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.



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

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.



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

def element_type
  @element_type
end

Class Method Details

.from(type, arg) ⇒ Object



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

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

.wrap(type, arg) ⇒ Object



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

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

Instance Method Details

#eachObject



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

def each
  return if @ptr.null?
  offset = 0
  while val = read_value(offset)
    offset += FFI.type_size(ffi_type)
    if complex_element_type?
      val = element_class.wrap val
    end
    yield val
  end
end

#to_ptrObject



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

def to_ptr
  @ptr
end