class GLib::Array

Overrides for GArray, GLib’s automatically growing array. It should not be necessary to create objects of this class from Ruby directly.

Attributes

element_type[R]

Public Class Methods

from(elmtype, it) click to toggle source
# File lib/ffi-glib/array.rb, line 53
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) click to toggle source
# 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) click to toggle source
# File lib/ffi-glib/array.rb, line 46
def self.wrap elmttype, ptr
  super(ptr).tap do |it|
    break if it.nil?
    it.element_type = elmttype
  end
end

Public Instance Methods

append_vals(data) click to toggle source
# 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() { |index(idx)| ... } click to toggle source
# File lib/ffi-glib/array.rb, line 36
def each
  @struct[:len].times.each do |idx|
    yield index(idx)
  end
end
element_type=(val) click to toggle source
# File lib/ffi-glib/array.rb, line 10
def element_type= val
  @element_type = val
  check_element_size_match
end
get_element_size() click to toggle source
# File lib/ffi-glib/array.rb, line 42
def get_element_size
  GLib.array_get_element_size self
end
index(idx) click to toggle source

Re-implementation of the g_array_index macro

# 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