Class: FMOD::Core::Guid

Inherits:
Structure
  • Object
show all
Defined in:
lib/fmod/core/guid.rb

Overview

Structure describing a globally unique identifier.

Instance Method Summary collapse

Methods inherited from Structure

#inspect, #names, #values

Constructor Details

#initialize(address = nil) ⇒ Guid

Returns a new instance of Guid.

Parameters:

  • address (Pointer, Integer, String, nil) (defaults to: nil)

    The address in memory where the structure will be created from. If no address is given, new memory will be allocated.



14
15
16
17
18
# File 'lib/fmod/core/guid.rb', line 14

def initialize(address = nil)
  types = [TYPE_INT, TYPE_SHORT, TYPE_SHORT, [TYPE_CHAR, 8]]
  members = [:data1, :data2, :data3, :data4]
  super(address, types, members)
end

Instance Method Details

#==(obj) ⇒ Boolean

Returns true if objects are equal, otherwise false.

Parameters:

  • obj (Object)

    The object to compare.

Returns:

  • (Boolean)

    true if objects are equal, otherwise false.



64
65
66
# File 'lib/fmod/core/guid.rb', line 64

def ==(obj)
  eql?(obj)
end

#data1Integer

Returns the first 8 hexadecimal digits of the GUID.

Returns:

  • (Integer)

    the first 8 hexadecimal digits of the GUID.



22
23
24
# File 'lib/fmod/core/guid.rb', line 22

def data1
  [self[:data1]].pack('l').unpack1('L')
end

#data2Integer

Returns the first group of 4 hexadecimal digits.

Returns:

  • (Integer)

    the first group of 4 hexadecimal digits.



28
29
30
# File 'lib/fmod/core/guid.rb', line 28

def data2
  [self[:data2]].pack('s').unpack1('S')
end

#data3Integer

Returns the second group of 4 hexadecimal digits.

Returns:

  • (Integer)

    the second group of 4 hexadecimal digits.



34
35
36
# File 'lib/fmod/core/guid.rb', line 34

def data3
  [self[:data3]].pack('s').unpack1('S')
end

#data4Array<Integer>

Array of 8 bytes. The first 2 bytes contain the third group of 4 hexadecimal digits. The remaining 6 bytes contain the final 12.

hexadecimal digits.

Returns:

  • (Array<Integer>)

    the last part if the GUID.



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

def data4
  self[:data4].pack('c*').unpack('C*')
end

#eql?(obj) ⇒ Boolean

Returns true if objects are equal, otherwise false.

Parameters:

  • obj (Object)

    The object to compare.

Returns:

  • (Boolean)

    true if objects are equal, otherwise false.



51
52
53
54
55
56
57
58
59
# File 'lib/fmod/core/guid.rb', line 51

def eql?(obj)
  if obj.is_a?(Guid)
    return false unless data1 == obj.data1
    return false unless data2 == obj.data2
    return false unless data3 == obj.data3
    return data4 == obj.data4
  end
  to_s.tr('-', '').casecmp(obj.to_s.tr('-', '')).zero?
end

#to_sString

Returns the string representation of the GUID.

Returns:

  • (String)

    the string representation of the GUID.



70
71
72
73
74
# File 'lib/fmod/core/guid.rb', line 70

def to_s
  d4 = data4
  last = d4[2, 6].map { |byte| "%02X" % byte }.join
  "%08X-%04X-%04X-%02X%02X-#{last}" % [data1, data2, data3, d4[0], d4[1]]
end