Class: GLib::Array
Overview
Overrides for GArray, GLib’s automatically growing array. It should not be necessary to create objects of this class from Ruby directly.
Instance Attribute Summary collapse
-
#element_type ⇒ Object
Returns the value of attribute element_type.
Class Method Summary collapse
Instance Method Summary collapse
- #append_vals(data) ⇒ Object
- #each ⇒ Object
- #get_element_size ⇒ Object
-
#index(idx) ⇒ Object
Re-implementation of the g_array_index macro.
Instance Attribute Details
#element_type ⇒ Object
Returns the value of attribute element_type.
9 10 11 |
# File 'lib/ffi-glib/array.rb', line 9 def element_type @element_type end |
Class Method Details
.from(elmtype, it) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/ffi-glib/array.rb', line 52 def self.from elmtype, it case it when self then it when FFI::Pointer then wrap elmtype, it else self.new(elmtype).tap {|arr| arr.append_vals it } end end |
.new(type) ⇒ Object
17 18 19 20 |
# File 'lib/ffi-glib/array.rb', line 17 def new type ptr = Lib.g_array_new(0, 0, calculated_element_size(type)) wrap type, ptr end |
.wrap(elmttype, ptr) ⇒ Object
46 47 48 49 50 |
# File 'lib/ffi-glib/array.rb', line 46 def self.wrap elmttype, ptr super(ptr).tap do |array| array.element_type = elmttype if array end end |
Instance Method Details
#append_vals(data) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/ffi-glib/array.rb', line 23 def append_vals data bytes = GirFFI::InPointer.from_array element_type, data len = data.length Lib.g_array_append_vals(self, bytes, len) self end |
#each ⇒ Object
36 37 38 39 40 |
# File 'lib/ffi-glib/array.rb', line 36 def each @struct[:len].times.each do |idx| yield index(idx) end end |
#get_element_size ⇒ Object
42 43 44 |
# File 'lib/ffi-glib/array.rb', line 42 def get_element_size Lib.g_array_get_element_size self end |
#index(idx) ⇒ Object
Re-implementation of the g_array_index macro
31 32 33 34 |
# File 'lib/ffi-glib/array.rb', line 31 def index idx ptr = @struct[:data].get_pointer(idx * get_element_size) GirFFI::ArgHelper.cast_from_pointer(element_type, ptr) end |