class GLib::PtrArray

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

Constants

POINTER_SIZE

Attributes

element_type[RW]

Public Class Methods

add(array, data) click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 36
def self.add array, data
  array.add data
end
from(type, it) click to toggle source
# 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
new(type) click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 19
def self.new type
  wrap(type, Lib.g_ptr_array_new)
end
wrap(type, ptr) click to toggle source
Calls superclass method
# File lib/ffi-glib/ptr_array.rb, line 23
def self.wrap type, ptr
  super(ptr).tap {|it|
    it.element_type = type}
end

Public Instance Methods

==(other) click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 68
def ==(other)
  self.to_a == other.to_a
end
add(data) click to toggle source
# 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
add_array(ary) click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 45
def add_array ary
  ary.each {|item| add item}
end
each() { |index(idx)| ... } click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 58
def each
  length.times 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 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
length() click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 64
def length
  @struct[:len]
end