Class: GLib::PtrArray
- Inherits:
-
Object
- Object
- GLib::PtrArray
- Extended by:
- ContainerClassMethods
- Includes:
- Enumerable, ArrayMethods
- Defined in:
- lib/ffi-glib/ptr_array.rb
Overview
Overrides for GPtrArray, GLib’s automatically growing array of pointers.
Constant Summary collapse
- POINTER_SIZE =
FFI.type_size(:pointer)
Instance Attribute Summary collapse
-
#element_type ⇒ Object
readonly
Returns the value of attribute element_type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add(data) ⇒ Object
- #add_array(ary) ⇒ Object
- #data_ptr ⇒ Object
- #each ⇒ Object
- #element_size ⇒ Object
-
#initialize(type) ⇒ PtrArray
constructor
A new instance of PtrArray.
- #length ⇒ Object
- #reset_typespec(typespec) ⇒ Object
Methods included from ContainerClassMethods
Methods included from ArrayMethods
Constructor Details
Instance Attribute Details
#element_type ⇒ Object (readonly)
Returns the value of attribute element_type.
15 16 17 |
# File 'lib/ffi-glib/ptr_array.rb', line 15 def element_type @element_type end |
Class Method Details
.add(array, data) ⇒ Object
33 34 35 |
# File 'lib/ffi-glib/ptr_array.rb', line 33 def self.add(array, data) array.add data end |
.from_enumerable(type, it) ⇒ Object
29 30 31 |
# File 'lib/ffi-glib/ptr_array.rb', line 29 def self.from_enumerable(type, it) new(type).tap { |arr| arr.add_array it } end |
Instance Method Details
#==(other) ⇒ Object
69 70 71 |
# File 'lib/ffi-glib/ptr_array.rb', line 69 def ==(other) to_a == other.to_a end |
#add(data) ⇒ Object
42 43 44 45 |
# 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) ⇒ Object
47 48 49 |
# File 'lib/ffi-glib/ptr_array.rb', line 47 def add_array(ary) ary.each { |item| add item } end |
#data_ptr ⇒ Object
51 52 53 |
# File 'lib/ffi-glib/ptr_array.rb', line 51 def data_ptr @struct[:pdata] end |
#each ⇒ Object
59 60 61 62 63 |
# File 'lib/ffi-glib/ptr_array.rb', line 59 def each length.times do |idx| yield index(idx) end end |
#element_size ⇒ Object
55 56 57 |
# File 'lib/ffi-glib/ptr_array.rb', line 55 def element_size POINTER_SIZE end |
#length ⇒ Object
65 66 67 |
# File 'lib/ffi-glib/ptr_array.rb', line 65 def length @struct[:len] end |
#reset_typespec(typespec) ⇒ Object
37 38 39 40 |
# File 'lib/ffi-glib/ptr_array.rb', line 37 def reset_typespec(typespec) @element_type = typespec self end |