Class: OklahomaMixer::ArrayList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/oklahoma_mixer/array_list.rb,
lib/oklahoma_mixer/array_list/c.rb

Overview

:nodoc:

Defined Under Namespace

Modules: C

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer_or_size) ⇒ ArrayList

Returns a new instance of ArrayList.


5
6
7
8
9
10
# File 'lib/oklahoma_mixer/array_list.rb', line 5

def initialize(pointer_or_size)
  @pointer = case pointer_or_size
             when FFI::Pointer then pointer_or_size
             else                   C.new2(pointer_or_size.to_i)
             end
end

Instance Attribute Details

#pointerObject (readonly)

Returns the value of attribute pointer


12
13
14
# File 'lib/oklahoma_mixer/array_list.rb', line 12

def pointer
  @pointer
end

Instance Method Details

#eachObject


16
17
18
19
20
# File 'lib/oklahoma_mixer/array_list.rb', line 16

def each
  (0...C.num(pointer)).each do |i|
    yield C.read_from_func(:val, :no_free, @pointer, i)
  end
end

#freeObject


28
29
30
# File 'lib/oklahoma_mixer/array_list.rb', line 28

def free
  C.del(@pointer)
end

#push(*values) ⇒ Object


22
23
24
25
26
# File 'lib/oklahoma_mixer/array_list.rb', line 22

def push(*values)
  values.each do |value|
    C.push(@pointer, *yield(value))
  end
end