Class: Idl::EnumerationType
Instance Attribute Summary collapse
-
#element_names ⇒ Array<String>
readonly
The names of the enumeration elements, in the same order as element_values.
-
#element_values ⇒ Array<Integer>
readonly
The values of the enumeration elements, in the same order as element_names.
-
#ref_type ⇒ Type
readonly
The type of an reference to this Enumeration class.
-
#width ⇒ Integer
readonly
The bit width of the enumeration elements.
Instance Method Summary collapse
- #clone ⇒ Object
- #element_name(element_value) ⇒ Object
-
#initialize(type_name, element_names, element_values) ⇒ EnumerationType
constructor
A new instance of EnumerationType.
- #value(element_name) ⇒ Object
Constructor Details
#initialize(type_name, element_names, element_values) ⇒ EnumerationType
Returns a new instance of EnumerationType.
543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/idl/type.rb', line 543 def initialize(type_name, element_names, element_values) width = element_values.max.bit_length width = 1 if width.zero? # can happen if only enum member has value 0 super(:enum, width:) @name = type_name @element_names = element_names @element_values = element_values raise "unexpected" unless element_names.is_a?(Array) @ref_type = Type.new(:enum_ref, enum_class: self) end |
Instance Attribute Details
#element_names ⇒ Array<String> (readonly)
Returns The names of the enumeration elements, in the same order as element_values.
532 533 534 |
# File 'lib/idl/type.rb', line 532 def element_names @element_names end |
#element_values ⇒ Array<Integer> (readonly)
Returns The values of the enumeration elements, in the same order as element_names.
535 536 537 |
# File 'lib/idl/type.rb', line 535 def element_values @element_values end |
#ref_type ⇒ Type (readonly)
Returns The type of an reference to this Enumeration class.
538 539 540 |
# File 'lib/idl/type.rb', line 538 def ref_type @ref_type end |
#width ⇒ Integer (readonly)
Returns The bit width of the enumeration elements.
529 530 531 |
# File 'lib/idl/type.rb', line 529 def width @width end |
Instance Method Details
#clone ⇒ Object
556 557 558 |
# File 'lib/idl/type.rb', line 556 def clone EnumerationType.new(@name, @element_names, @element_values) end |
#element_name(element_value) ⇒ Object
567 568 569 570 571 572 573 |
# File 'lib/idl/type.rb', line 567 def element_name(element_value) i = @element_values.index(element_value) raise "? #{element_value}" if i.nil? return nil if i.nil? @element_names[i] end |
#value(element_name) ⇒ Object
560 561 562 563 564 565 |
# File 'lib/idl/type.rb', line 560 def value(element_name) i = @element_names.index(element_name) return nil if i.nil? @element_values[i] end |