Class: Yadriggy::C::FFIArray Abstract
- Inherits:
-
Object
- Object
- Yadriggy::C::FFIArray
- 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
Class Method Summary collapse
-
.element_type ⇒ Object
Obtain the element type.
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#length ⇒ Integer
Obtain the size.
-
#memory_pointer ⇒ FFI::MemoryPointer
The object holding all data.
-
#set_values ⇒ Object
Initializes the element values.
-
#size ⇒ Integer
Obtains the size.
-
#to_a(*args, &proc) ⇒ Object
Converts all the elements into an array.
Class Method Details
.element_type ⇒ Object
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 |
#length ⇒ Integer
Obtain the size.
29 |
# File 'lib/yadriggy/c/ffi.rb', line 29 def length() size() end |
#memory_pointer ⇒ FFI::MemoryPointer
Returns the object holding all data.
13 14 15 |
# File 'lib/yadriggy/c/ffi.rb', line 13 def memory_pointer() @array end |
#set_values ⇒ Object
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 |
#size ⇒ Integer
Obtains the size.
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 |