Class: GirFFI::ZeroTerminated

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gir_ffi/zero_terminated.rb

Overview

Represents a null-terminated array.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elm_t, ptr) ⇒ ZeroTerminated

Returns a new instance of ZeroTerminated.



9
10
11
12
# File 'lib/gir_ffi/zero_terminated.rb', line 9

def initialize(elm_t, ptr)
  @element_type = elm_t
  @ptr = ptr
end

Instance Attribute Details

#element_typeObject (readonly)

Returns the value of attribute element_type.



7
8
9
# File 'lib/gir_ffi/zero_terminated.rb', line 7

def element_type
  @element_type
end

Class Method Details

.from(type, arg) ⇒ Object



18
19
20
# File 'lib/gir_ffi/zero_terminated.rb', line 18

def self.from(type, arg)
  new type, InPointer.from_array(type, arg)
end

.wrap(type, arg) ⇒ Object



22
23
24
# File 'lib/gir_ffi/zero_terminated.rb', line 22

def self.wrap(type, arg)
  new type, arg
end

Instance Method Details

#==(other) ⇒ Object



35
36
37
# File 'lib/gir_ffi/zero_terminated.rb', line 35

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

#eachObject



26
27
28
29
30
31
32
33
# File 'lib/gir_ffi/zero_terminated.rb', line 26

def each
  return if @ptr.null?
  offset = 0
  while (val = read_value(offset))
    offset += ffi_type_size
    yield wrap_value(val)
  end
end

#to_ptrObject



14
15
16
# File 'lib/gir_ffi/zero_terminated.rb', line 14

def to_ptr
  @ptr
end