class GLib::PtrArray

Overrides for GPtrArray, GLib’s automatically growing array of pointers.

Attributes

element_type[RW]

Public Class Methods

add(array, data) click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 22
def self.add array, data
  array.add data
end
new(type) click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 17
def self.new type
  wrap(Lib.g_ptr_array_new).tap {|it|
    it.element_type = type}
end

Public Instance Methods

add(data) click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 26
def add data
  ptr = GirFFI::InPointer.from element_type, data
  Lib.g_ptr_array_add self, ptr
end
each() { |index(idx)| ... } click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 38
def each
  @struct[:len].times.each do |idx|
    yield index(idx)
  end
end
index(idx) click to toggle source

Re-implementation of the g_ptr_array_index macro

# File lib/ffi-glib/ptr_array.rb, line 32
def index idx
  sz = FFI.type_size :pointer
  ptr = @struct[:pdata].get_pointer(idx * sz)
  GirFFI::ArgHelper.cast_from_pointer(element_type, ptr)
end