class GLib::PtrArray
Overrides for GPtrArray, GLib’s automatically growing array of pointers.
Constants
- POINTER_SIZE
Attributes
element_type[R]
Public Class Methods
add(array, data)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 33 def self.add(array, data) array.add data end
from_enumerable(type, arr)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 29 def self.from_enumerable(type, arr) new(type).tap { |it| it.add_array arr } end
new(type)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 24 def initialize(type) @element_type = type store_pointer Lib.g_ptr_array_new end
Public Instance Methods
==(other)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 68 def ==(other) to_a == other.to_a end
add(data)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 42 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 47 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_ptrarray_index macro
# File lib/ffi-glib/ptr_array.rb, line 52 def index(idx) item_ptr = item_pointer(idx) convertor = GirFFI::ArrayElementConvertor.new convert_element_type, item_ptr convertor.to_ruby_value end
length()
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 64 def length struct[:len] end
reset_typespec(typespec)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 37 def reset_typespec(typespec) @element_type = typespec self end
Private Instance Methods
check_bounds(idx)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 80 def check_bounds(idx) unless (0...length).cover? idx raise IndexError, "Index #{idx} outside of bounds 0..#{length - 1}" end end
convert_element_type()
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 86 def convert_element_type case element_type when :utf8 :utf8 when GirFFI::ObjectBase element_type else [:pointer, element_type] end end
data_ptr()
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 101 def data_ptr struct[:pdata] end
element_size()
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 97 def element_size POINTER_SIZE end
item_pointer(idx)
click to toggle source
# File lib/ffi-glib/ptr_array.rb, line 74 def item_pointer(idx) check_bounds(idx) data_ptr + idx * element_size end