Class: GLib::SizedArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ffi-glib/sized_array.rb

Overview

Class representing an array with a determined size

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_type, size, pointer) ⇒ SizedArray

Returns a new instance of SizedArray.



7
8
9
10
11
# File 'lib/ffi-glib/sized_array.rb', line 7

def initialize element_type, size, pointer
  @element_type = element_type
  @size = size
  @pointer = pointer
end

Instance Attribute Details

#element_typeObject (readonly)

Returns the value of attribute element_type.



5
6
7
# File 'lib/ffi-glib/sized_array.rb', line 5

def element_type
  @element_type
end

#sizeObject (readonly)

Returns the value of attribute size.



5
6
7
# File 'lib/ffi-glib/sized_array.rb', line 5

def size
  @size
end

Class Method Details

.from(element_type, size, item) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ffi-glib/sized_array.rb', line 37

def from element_type, size, item
  return unless item

  case item
  when FFI::Pointer
    wrap element_type, size, item
  when self
    from_sized_array size, item
  else
    from_enumerable element_type, size, item
  end
end

.wrap(element_type, size, pointer) ⇒ Object



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

def self.wrap element_type, size, pointer
  new element_type, size, pointer unless pointer.null?
end

Instance Method Details

#==(other) ⇒ Object



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

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

#each(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/ffi-glib/sized_array.rb', line 17

def each &block
  # TODO: Move implementation from GirFFI::ArgHelper to here.
  # While doing so, the implentation could also become a real iterator
  arr = GirFFI::ArgHelper.ptr_to_typed_array(@element_type, @pointer, @size)
  if block_given?
    arr.each(&block)
  else
    arr.each
  end
end

#to_ptrObject



13
14
15
# File 'lib/ffi-glib/sized_array.rb', line 13

def to_ptr
  @pointer
end