Class: GLib::Array

Inherits:
Object
  • Object
show all
Extended by:
ContainerClassMethods
Includes:
Enumerable, ArrayMethods
Defined in:
lib/ffi-glib/array.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContainerClassMethods

from, wrap

Methods included from ArrayMethods

#index

Instance Attribute Details

#element_typeObject (readonly)

Returns the value of attribute element_type.



14
15
16
# File 'lib/ffi-glib/array.rb', line 14

def element_type
  @element_type
end

Class Method Details

.from_enumerable(elmtype, it) ⇒ Object



63
64
65
# File 'lib/ffi-glib/array.rb', line 63

def self.from_enumerable elmtype, it
  new(elmtype).tap { |arr| arr.append_vals it }
end

.new(type) ⇒ Object



18
19
20
21
# File 'lib/ffi-glib/array.rb', line 18

def self.new type
  ptr = Lib.g_array_new(0, 0, calculated_element_size(type))
  wrap type, ptr
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
# File 'lib/ffi-glib/array.rb', line 49

def == other
  to_a == other.to_a
end

#append_vals(ary) ⇒ Object



23
24
25
26
27
# 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

#data_ptrObject



39
40
41
# File 'lib/ffi-glib/array.rb', line 39

def data_ptr
  @struct[:data]
end

#eachObject



29
30
31
32
33
# File 'lib/ffi-glib/array.rb', line 29

def each
  length.times do |idx|
    yield index(idx)
  end
end

#get_element_sizeObject Also known as: element_size



43
44
45
# File 'lib/ffi-glib/array.rb', line 43

def get_element_size
  Lib.g_array_get_element_size self
end

#lengthObject



35
36
37
# File 'lib/ffi-glib/array.rb', line 35

def length
  @struct[:len]
end

#reset_typespec(typespec = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/ffi-glib/array.rb', line 53

def reset_typespec typespec = nil
  if typespec
    @element_type = typespec
    check_element_size_match
  else
    @element_type = guess_element_type
  end
  self
end