Class: FMOD::Core::Structure Abstract

Inherits:
Fiddle::CStructEntity
  • Object
show all
Includes:
FMOD::Core, Fiddle
Defined in:
lib/fmod/core/structure.rb

Overview

This class is abstract.

Expands upon a the built-in Fiddle::CStructEntity to provide some additional common functionality for FMOD structures.

Instance Method Summary collapse

Constructor Details

#initialize(address, types, members) ⇒ Structure

Returns a new instance of Structure.

Parameters:

  • address (Integer, String)

    The memory address of the structure as an integer or packed binary string.

  • types (Array<Integer>)

    Array of primitive C-type flags for the data type used by each field.

  • members (Array<Symbol>)

    Array of names as symbols to use for the fields.



21
22
23
24
25
26
# File 'lib/fmod/core/structure.rb', line 21

def initialize(address, types, members)
  address = Pointer[address] if address.is_a?(String)
  address ||= Fiddle.malloc(self.class.size(types)).to_i
  super(address, types)
  assign_names members
end

Instance Method Details

#inspectString

Returns the structure as a string.

Returns:

  • (String)

    the structure as a string.



44
45
46
47
# File 'lib/fmod/core/structure.rb', line 44

def inspect
  values = @members.map { |sym| "#{sym}=#{self[sym]}"}.join(', ')
  super.sub(/free=0x(.)*/, values << '>')
end

#namesArray<Symbol>

Returns the names of the structure’s fields as symbols.

Returns:

  • (Array<Symbol>)

    the names of the structure’s fields as symbols.

Since:

  • 0.9.1



31
32
33
# File 'lib/fmod/core/structure.rb', line 31

def names
  @members
end

#valuesArray<Object>

Returns the values of the structure’s fields.

Returns:

  • (Array<Object>)

    the values of the structure’s fields.

Since:

  • 0.9.1



38
39
40
# File 'lib/fmod/core/structure.rb', line 38

def values
  @members.map { |sym| self[sym] }
end