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.



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

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.



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

def element_type
  @element_type
end

Class Method Details

.from(type, arg) ⇒ Object



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

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

.wrap(type, arg) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



37
38
39
# File 'lib/gir_ffi/zero_terminated.rb', line 37

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

#eachObject



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

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



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

def to_ptr
  @ptr
end