Class: GL::Registry::Enum

Inherits:
Token
  • Object
show all
Defined in:
lib/opengl/registry/enum.rb

Overview

Describes an OpenGL enumeration (constant) value.

Instance Attribute Summary collapse

Attributes inherited from Token

#comment

Instance Method Summary collapse

Methods inherited from Token

#to_s

Constructor Details

#initialize(node) ⇒ Enum

Creates a new instance of the GL::Registry::Enum class.

Parameters:

  • node (Ox::Element)

    The XML element defining the instance.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/opengl/registry/enum.rb', line 38

def initialize(node)
  super(node)

  # Required
  @name = node[Words::NAME]
  @value = node[Words::VALUE]

  # Optional
  @alias_name = node[Words::ALIAS]
  @api = node[Words::API]&.to_sym
  @groups = node[Words::GROUP]&.split(',') || []

  @type = case node[Words::TYPE]
  when Words::U_LONG then :GLuint
  when Words::U_LONG_LONG then :GLuint64
  else :GLenum
  end
end

Instance Attribute Details

#alias_nameString? (readonly)

Returns an alternative name for the value.

Returns:

  • (String?)

    an alternative name for the value.



20
21
22
# File 'lib/opengl/registry/enum.rb', line 20

def alias_name
  @alias_name
end

#apiSymbol? (readonly)

Returns an API associated with this enumeration value.

Returns:

  • (Symbol?)

    an API associated with this enumeration value.



28
29
30
# File 'lib/opengl/registry/enum.rb', line 28

def api
  @api
end

#groupsArray<String> (readonly)

Returns an array of names of the groups this enumeration is defined within.

Returns:

  • (Array<String>)

    an array of names of the groups this enumeration is defined within.



32
33
34
# File 'lib/opengl/registry/enum.rb', line 32

def groups
  @groups
end

#nameString (readonly)

Returns the name of the enumeration member.

Returns:

  • (String)

    the name of the enumeration member.



12
13
14
# File 'lib/opengl/registry/enum.rb', line 12

def name
  @name
end

#typeSymbol (readonly)

Returns a hint for the enumeration value type (i.e. GLenum, GLuint, GLuint64, etc).

Returns:

  • (Symbol)

    a hint for the enumeration value type (i.e. GLenum, GLuint, GLuint64, etc)



24
25
26
# File 'lib/opengl/registry/enum.rb', line 24

def type
  @type
end

#valueString (readonly)

Returns the value of the enumeration, always numerical, typically in hexadecimal format.

Returns:

  • (String)

    the value of the enumeration, always numerical, typically in hexadecimal format.



16
17
18
# File 'lib/opengl/registry/enum.rb', line 16

def value
  @value
end

Instance Method Details

#to_iInteger

Returns the enumeration's value, as an integer.

Returns:

  • (Integer)

    the enumeration's value, as an integer.



59
60
61
# File 'lib/opengl/registry/enum.rb', line 59

def to_i
  @value.start_with?('0x') ? @value.hex : @value.to_i
end