Overrides for GArray, GLib's automatically growing array. It should not be necessary to create objects of this class from Ruby directly.
# File lib/ffi-glib/array.rb, line 72 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
# 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
# File lib/ffi-glib/array.rb, line 66 def self.wrap elmttype, ptr super(ptr).tap do |array| array.element_type = elmttype if array end end
# File lib/ffi-glib/array.rb, line 82 def self.calculated_element_size type ffi_type = GirFFI::TypeMap.type_specification_to_ffitype(type) FFI.type_size(ffi_type) end
# File lib/ffi-glib/array.rb, line 62 def ==(other) self.to_a == other.to_a end
# File lib/ffi-glib/array.rb, line 23 def append_vals ary bytes = GirFFI::InPointer.from_array element_type, ary Lib.g_array_append_vals(self, bytes, ary.length) self end
@deprecated From 0.7.0, data will return the actual data as a string, as generated by GirFFI.
# File lib/ffi-glib/array.rb, line 48 def data_ptr @struct[:data] end
# File lib/ffi-glib/array.rb, line 38 def each length.times do |idx| yield index(idx) end end
# File lib/ffi-glib/array.rb, line 10 def element_type= val @element_type = val check_element_size_match end
# File lib/ffi-glib/array.rb, line 58 def get_element_size Lib.g_array_get_element_size self end
Re-implementation of the g_array_index macro
# File lib/ffi-glib/array.rb, line 30 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, data_ptr + idx * get_element_size ptr.to_ruby_value end
# File lib/ffi-glib/array.rb, line 44 def length @struct[:len] end
# File lib/ffi-glib/array.rb, line 87 def calculated_element_size self.class.calculated_element_size self.element_type end
# File lib/ffi-glib/array.rb, line 91 def check_element_size_match unless calculated_element_size == self.get_element_size warn "WARNING: Element sizes do not match" end end