Skip to content

Commit

Permalink
Refactor CameraList and remove obsolete Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Dec 25, 2023
1 parent a440c7c commit 347ed0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
20 changes: 19 additions & 1 deletion src/gphoto2/camera_list.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module GPhoto2
class CameraList
include GPhoto2::Struct(LibGPhoto2::CameraList)

record Entry,
name : String,
value : String

# NOTE: allocates memory.
def initialize
new
Expand All @@ -21,7 +25,21 @@ module GPhoto2

# Returns an array of entries in the list.
def to_a : Array(Entry)
Array(Entry).new(size) { |i| Entry.new(self, i) }
Array(Entry).new(size) do |i|
Entry.new get_name(i), get_value(i)
end
end

private def get_name(idx)
GPhoto2.check! \
LibGPhoto2.gp_list_get_name(self, idx, out ptr)
ptr ? String.new(ptr) : ""
end

private def get_value(idx)
GPhoto2.check! \
LibGPhoto2.gp_list_get_value(self, idx, out ptr)
ptr ? String.new(ptr) : ""
end

private def new
Expand Down
28 changes: 0 additions & 28 deletions src/gphoto2/entry.cr

This file was deleted.

0 comments on commit 347ed0c

Please sign in to comment.