Overrides for GPtrArray, GLib's automatically growing array of pointers.
# File lib/ffi-glib/ptr_array.rb, line 36 def self.add array, data array.add data end
# File lib/ffi-glib/ptr_array.rb, line 28 def self.from type, it case it when self then it when FFI::Pointer then wrap type, it else self.new(type).tap {|arr| arr.add_array it} end end
# File lib/ffi-glib/ptr_array.rb, line 19 def self.new type wrap(type, Lib.g_ptr_array_new) end
# File lib/ffi-glib/ptr_array.rb, line 23 def self.wrap type, ptr super(ptr).tap {|it| it.element_type = type} end
# File lib/ffi-glib/ptr_array.rb, line 68 def ==(other) self.to_a == other.to_a end
# File lib/ffi-glib/ptr_array.rb, line 40 def add data ptr = GirFFI::InPointer.from element_type, data Lib.g_ptr_array_add self, ptr end
# File lib/ffi-glib/ptr_array.rb, line 45 def add_array ary ary.each {|item| add item} end
# File lib/ffi-glib/ptr_array.rb, line 58 def each length.times do |idx| yield index(idx) end end
Re-implementation of the g_ptr_array_index macro
# File lib/ffi-glib/ptr_array.rb, line 50 def index idx if idx >= length or idx < 0 raise IndexError, "Index #{idx} outside of bounds 0..#{length - 1}" end ptr = GirFFI::InOutPointer.new element_type, @struct[:pdata] + idx * POINTER_SIZE ptr.to_ruby_value end
# File lib/ffi-glib/ptr_array.rb, line 64 def length @struct[:len] end