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

Constructor Details

#initialize(type) ⇒ PtrArray

Returns a new instance of PtrArray.



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

def initialize(type)
  @element_type = type
  store_pointer Lib.g_ptr_array_new
end

Instance Attribute Details

#element_typeObject (readonly)

Returns the value of attribute element_type.



16
17
18
# File 'lib/ffi-glib/ptr_array.rb', line 16

def element_type
  @element_type
end

Class Method Details

.add(array, data) ⇒ Object



34
35
36
# File 'lib/ffi-glib/ptr_array.rb', line 34

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

.from_enumerable(type, arr) ⇒ Object



30
31
32
# File 'lib/ffi-glib/ptr_array.rb', line 30

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

Instance Method Details

#==(other) ⇒ Object



70
71
72
# File 'lib/ffi-glib/ptr_array.rb', line 70

def ==(other)
  to_a == other.to_a
end

#add(data) ⇒ Object



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

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

#add_array(ary) ⇒ Object



48
49
50
# File 'lib/ffi-glib/ptr_array.rb', line 48

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

#data_ptrObject



52
53
54
# File 'lib/ffi-glib/ptr_array.rb', line 52

def data_ptr
  @struct[:pdata]
end

#eachObject



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

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

#element_sizeObject



56
57
58
# File 'lib/ffi-glib/ptr_array.rb', line 56

def element_size
  POINTER_SIZE
end

#lengthObject



66
67
68
# File 'lib/ffi-glib/ptr_array.rb', line 66

def length
  @struct[:len]
end

#reset_typespec(typespec) ⇒ Object



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

def reset_typespec(typespec)
  @element_type = typespec
  self
end