Class: Babeltrace2::BTFieldClass::Variant
Defined Under Namespace
Modules: WithSelectorField, WithoutSelectorField
Classes: Option
Constant Summary
IntegerSigned, IntegerUnsigned, RealDoublePrecision, RealSinglePrecision, TYPE_MAP
Instance Attribute Summary
#handle
Class Method Summary
collapse
Instance Method Summary
collapse
#from_h, from_handle, #get_type, #get_user_attributes, #set_user_attributes, #type_is, #user_attributes=
inherited
#==, #to_ptr
Constructor Details
#initialize(handle = nil, retain: true, auto_release: true, trace_class: nil, selector_field_class: nil) ⇒ Variant
Returns a new instance of Variant.
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
|
# File 'lib/babeltrace2/trace-ir/field-class.rb', line 1648
def initialize(handle = nil, retain: true, auto_release: true,
trace_class: nil, selector_field_class: nil)
if handle
case Babeltrace2.bt_field_class_get_type(handle)
when :BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
self.extend(BTFieldClass::Variant::WithoutSelectorField)
when :BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
self.extend(BTFieldClass::Variant::WithSelectorField::IntegerUnsigned)
when :BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
self.extend(BTFieldClass::Variant::WithSelectorField::IntegerSigned)
else
raise "unsupported variant type"
end
super(handle, retain: retain, auto_release: auto_release)
else
handle =
Babeltrace2.bt_field_class_variant_create(trace_class, selector_field_class)
raise Babeltrace2.process_error if handle.null?
case Babeltrace2.bt_field_class_get_type(handle)
when :BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
self.extend(BTFieldClass::Variant::WithoutSelectorField)
when :BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
self.extend(BTFieldClass::Variant::WithSelectorField::IntegerUnsigned)
when :BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
self.extend(BTFieldClass::Variant::WithSelectorField::IntegerSigned)
else
raise "unsupported variant type"
end
super(handle, retain: false)
end
end
|
Class Method Details
.from_h(trace_class, h, stream_class_h = nil) ⇒ Object
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
|
# File 'lib/babeltrace2/trace-ir/field-class.rb', line 1720
def self.from_h(trace_class, h, stream_class_h = nil)
if (stream_class_h && h[:selector_field_path])
selector_field_class = BTStreamClass.locate_field_class(
BTFieldPath.path_from_s_to_h(h[:selector_field_path]), stream_class_h)
else
selector_field_class = nil
end
o = self.new(trace_class: trace_class,
selector_field_class: selector_field_class).from_h(h)
if selector_field_class
h[:options].each { |v|
o.append_option(v[:name],
BTFieldClass.from_h(trace_class, v[:field_class], stream_class_h),
v[:ranges]) }
else
h[:options].each { |v|
o.append_option(v[:name],
BTFieldClass.from_h(trace_class, v[:field_class], stream_class_h)) }
end
h[:bt_field_class] = o
o
end
|
Instance Method Details
#get_option(option) ⇒ Object
Also known as:
[]
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
|
# File 'lib/babeltrace2/trace-ir/field-class.rb', line 1700
def get_option(option)
case option
when ::String, Symbol
get_option_by_name(option)
when ::Integer
get_option_by_index(option)
else
raise TypeError, "wrong type for option query"
end
end
|
#get_option_by_index(index) ⇒ Object
1685
1686
1687
1688
1689
1690
1691
|
# File 'lib/babeltrace2/trace-ir/field-class.rb', line 1685
def get_option_by_index(index)
count = get_option_count
index += count if index < 0
return nil if index >= count || index < 0
BTFieldClassVariantOption.new(
Babeltrace2.bt_field_class_variant_borrow_option_by_index(@handle, index))
end
|
#get_option_by_name(name) ⇒ Object
1693
1694
1695
1696
1697
1698
|
# File 'lib/babeltrace2/trace-ir/field-class.rb', line 1693
def get_option_by_name(name)
name = name.inspect if name.kind_of?(Symbol)
handle = Babeltrace2.bt_field_class_variant_borrow_option_by_name(@handle, name)
return nil if handle.null?
BTFieldClassVariantOption.new(handle)
end
|
#get_option_count ⇒ Object
Also known as:
option_count
1680
1681
1682
|
# File 'lib/babeltrace2/trace-ir/field-class.rb', line 1680
def get_option_count
Babeltrace2.bt_field_class_variant_get_option_count(@handle)
end
|
#to_h ⇒ Object
1712
1713
1714
1715
1716
1717
1718
|
# File 'lib/babeltrace2/trace-ir/field-class.rb', line 1712
def to_h
res = super
res[:options] = option_count.times.collect { |i|
get_option_by_index(i).to_h
}
res
end
|