Class: GirFFI::ZeroTerminated
- Inherits:
-
Object
- Object
- GirFFI::ZeroTerminated
- Includes:
- Enumerable
- Defined in:
- lib/gir_ffi/zero_terminated.rb
Overview
Represents a null-terminated array.
Instance Attribute Summary collapse
-
#element_type ⇒ Object
readonly
Returns the value of attribute element_type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each ⇒ Object
-
#initialize(elm_t, ptr) ⇒ ZeroTerminated
constructor
A new instance of ZeroTerminated.
- #to_ptr ⇒ Object
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_type ⇒ Object (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
#==(other) ⇒ Object
34 35 36 |
# File 'lib/gir_ffi/zero_terminated.rb', line 34 def ==(other) self.to_a == other.to_a end |
#each ⇒ Object
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(ffi_type) yield wrap_value(val) end end |
#to_ptr ⇒ Object
13 14 15 |
# File 'lib/gir_ffi/zero_terminated.rb', line 13 def to_ptr @ptr end |