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
  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
  new type, arg
end

Instance Method Details

#==(other) ⇒ Object



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

def == other
  to_a == other.to_a
end

#eachObject



25
26
27
28
29
30
31
32
# 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
    yield wrap_value(val)
  end
end

#to_ptrObject



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

def to_ptr
  @ptr
end