Class: Glyr::Results
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Class Method Summary collapse
-
.finalizer(pointer) ⇒ Object
:nodoc:.
-
.wrap(pointer, length = nil) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(pointer, length = nil) ⇒ Results
constructor
A new instance of Results.
- #to_native ⇒ Object
Constructor Details
#initialize(pointer, length = nil) ⇒ Results
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/glyr/results.rb', line 30 def initialize (pointer, length = nil) @internal = pointer.is_a?(FFI::Pointer) ? C::MemCache.new(pointer) : pointer @length = if length length else length = 0 current = @internal until current.null? length += 1 current = C::MemCache.new(current[:next]) end length end end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
28 29 30 |
# File 'lib/glyr/results.rb', line 28 def length @length end |
Class Method Details
.finalizer(pointer) ⇒ Object
:nodoc:
20 21 22 23 24 |
# File 'lib/glyr/results.rb', line 20 def self.finalizer (pointer) # :nodoc: proc { C.glyr_free_list(pointer) } end |
.wrap(pointer, length = nil) ⇒ Object
:nodoc:
14 15 16 17 18 |
# File 'lib/glyr/results.rb', line 14 def self.wrap (pointer, length = nil) # :nodoc: new(pointer, length).tap {|x| ObjectSpace.define_finalizer x, finalizer(pointer) } end |
Instance Method Details
#each(&block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/glyr/results.rb', line 47 def each (&block) current = @internal until current.null? block.call(Result.wrap(current, self)) current = C::MemCache.new(current[:next]) end self end |
#to_native ⇒ Object
59 60 61 |
# File 'lib/glyr/results.rb', line 59 def to_native @internal end |