Class: Numerix::Structure Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/numerix/structure.rb

Overview

This class is abstract.

Abstract class providing common functionality to the base classes.

This class cannot be instantiated, it of only for providing a common base class for all Numerix types and provide common functionality.

Direct Known Subclasses

MatrixBase, Plane, Quaternion, VectorBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sizeInteger

Returns the size, in bytes, the structure contains in memory.

Returns:

  • (Integer)

    the size, in bytes, the structure contains in memory.



103
104
# File 'lib/numerix/structure.rb', line 103

def size
end

.unpack(binary) ⇒ Object Also known as: _load

Unpacks a binary string of data into a structure.

This is the equivalent of calling binary.unpack('f*') on the string and using the values to create a new structure, but much faster as it bypasses the parser and is done in C directly with a pointer in memory.

Parameters:

  • binary (String)

    Binary string of data.

Returns:

  • (Object)

    the unpacked structure.

See Also:



118
119
# File 'lib/numerix/structure.rb', line 118

def unpack(binary)
end

Instance Method Details

#[](index) ⇒ Float?

Retrieves the component of the structure at the specified position.

Parameters:

  • index (Integer)

    The position of the component to retrieve.

Returns:

  • (Float, nil)

    the value at the given position, or +nil+ if index is out of range.

See Also:



52
53
# File 'lib/numerix/structure.rb', line 52

def [](index)
end

#[]=(index, value) ⇒ Float

Sets the component of the structure at the specified position.

If index is out of range, the method does nothing.

Parameters:

  • index (Integer)

    The position of the component to set.

  • value (Float)

    The value to set.

Returns:

  • (Float)

    the value

See Also:



66
67
# File 'lib/numerix/structure.rb', line 66

def []=(index, value)
end

#addressInteger

Returns the address of the internal C-struct in memory.

Returns:

  • (Integer)

    the address of the internal C-struct in memory.



20
21
# File 'lib/numerix/structure.rb', line 20

def address
end

#dupObject

Returns an exact duplicate of the object.

Returns:

  • (Object)

    an exact duplicate of the object.



15
16
# File 'lib/numerix/structure.rb', line 15

def dup
end

#each {|component| ... } ⇒ self #eachEnumerator

Enumerates over the components of the structure.

Overloads:

  • #each {|component| ... } ⇒ self

    When called with a block, enumerates through each component of the structure, yielding each before returning self;

    Yields:

    • (component)

      Yields a component to the block.

    Yield Parameters:

    • component (Float)

      The current component.

    Returns:

    • (self)
  • #eachEnumerator

    When called without a block, returned an Enumerator for the structure.

    Returns:

    • (Enumerator)

      the enumerator for the structure.



40
41
# File 'lib/numerix/structure.rb', line 40

def each
end

#packString Also known as: _dump

Packs the structures memory into a binary string.

This is the equivalent of taking its values into an array and calling array.pack('f*') on it, though considerably faster as the parser is bypassed and done directly in C by accessing the memory directly.

Returns:

  • (String)

    the packed binary string.

See Also:



79
80
# File 'lib/numerix/structure.rb', line 79

def pack
end

#ptrFiddle::Pointer

Note:

This method only exists in Ruby 2.0 and higher, and will not be present in lower versions.

Returns a sized pointer to the structure in memory.

Returns:

  • (Fiddle::Pointer)

    a sized pointer to the structure in memory.

See Also:



95
96
# File 'lib/numerix/structure.rb', line 95

def ptr
end