Class: Yadriggy::C::FFIArray Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/yadriggy/c/ffi.rb

Overview

This class is abstract.

A wrapper of memory object accessible from Ruby and C code.

Direct Known Subclasses

Float32Array, FloatArray, IntArray

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.element_typeObject

Obtain the element type. All the subclasses have to override this method.



44
45
46
# File 'lib/yadriggy/c/ffi.rb', line 44

def self.element_type()
  Undef
end

Instance Method Details

#==(obj) ⇒ Object



17
18
19
# File 'lib/yadriggy/c/ffi.rb', line 17

def ==(obj)
  obj.is_a?(FFIArray) && @array == obj.memory_pointer
end

#lengthInteger

Obtain the size.

Returns:

  • (Integer)

    the number of elements.



29
# File 'lib/yadriggy/c/ffi.rb', line 29

def length() size() end

#memory_pointerFFI::MemoryPointer

Returns the object holding all data.

Returns:

  • (FFI::MemoryPointer)

    the object holding all data.



13
14
15
# File 'lib/yadriggy/c/ffi.rb', line 13

def memory_pointer()
  @array
end

#set_valuesObject

Initializes the element values.



32
33
34
# File 'lib/yadriggy/c/ffi.rb', line 32

def set_values
  size.times {|i| self[i] = yield i }
end

#sizeInteger

Obtains the size.

Returns:

  • (Integer)

    the number of elements.



23
24
25
# File 'lib/yadriggy/c/ffi.rb', line 23

def size
  @array.size / @array.type_size
end

#to_a(*args, &proc) ⇒ Object

Converts all the elements into an array. This method is available only within Ruby.



38
39
40
# File 'lib/yadriggy/c/ffi.rb', line 38

def to_a(*args, &proc)
  Array.new(size) {|i| self[i] }
end