Class: GLib::PtrArray

Inherits:
Object
  • Object
show all
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

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/ptr_array.rb', line 14

def element_type
  @element_type
end

Class Method Details

.add(array, data) ⇒ Object



32
33
34
# File 'lib/ffi-glib/ptr_array.rb', line 32

def self.add array, data
  array.add data
end

.from_enumerable(type, it) ⇒ Object



28
29
30
# File 'lib/ffi-glib/ptr_array.rb', line 28

def self.from_enumerable type, it
  new(type).tap {|arr| arr.add_array it}
end

.new(type) ⇒ Object



24
25
26
# File 'lib/ffi-glib/ptr_array.rb', line 24

def self.new type
  wrap(type, Lib.g_ptr_array_new)
end

Instance Method Details

#==(other) ⇒ Object



68
69
70
# File 'lib/ffi-glib/ptr_array.rb', line 68

def == other
  to_a == other.to_a
end

#add(data) ⇒ Object



41
42
43
44
# File 'lib/ffi-glib/ptr_array.rb', line 41

def add data
  ptr = GirFFI::InPointer.from element_type, data
  Lib.g_ptr_array_add self, ptr
end

#add_array(ary) ⇒ Object



46
47
48
# File 'lib/ffi-glib/ptr_array.rb', line 46

def add_array ary
  ary.each {|item| add item}
end

#data_ptrObject



50
51
52
# File 'lib/ffi-glib/ptr_array.rb', line 50

def data_ptr
  @struct[:pdata]
end

#eachObject



58
59
60
61
62
# File 'lib/ffi-glib/ptr_array.rb', line 58

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

#element_sizeObject



54
55
56
# File 'lib/ffi-glib/ptr_array.rb', line 54

def element_size
  POINTER_SIZE
end

#lengthObject



64
65
66
# File 'lib/ffi-glib/ptr_array.rb', line 64

def length
  @struct[:len]
end

#reset_typespec(typespec) ⇒ Object



36
37
38
39
# File 'lib/ffi-glib/ptr_array.rb', line 36

def reset_typespec typespec
  @element_type = typespec
  self
end