class Babeltrace2::BTFieldClass::Variant

Public Class Methods

from_h(trace_class, h, stream_class_h = nil) click to toggle source
# File lib/babeltrace2/trace-ir/field-class.rb, line 1718
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
new(handle = nil, retain: true, auto_release: true, trace_class: nil, selector_field_class: nil) click to toggle source
Calls superclass method
# File lib/babeltrace2/trace-ir/field-class.rb, line 1646
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

Public Instance Methods

[](option)
Alias for: get_option
get_option(option) click to toggle source
# File lib/babeltrace2/trace-ir/field-class.rb, line 1698
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
Also aliased as: []
get_option_by_index(index) click to toggle source
# File lib/babeltrace2/trace-ir/field-class.rb, line 1683
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) click to toggle source
# File lib/babeltrace2/trace-ir/field-class.rb, line 1691
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() click to toggle source
# File lib/babeltrace2/trace-ir/field-class.rb, line 1678
def get_option_count
  Babeltrace2.bt_field_class_variant_get_option_count(@handle)
end
Also aliased as: option_count
option_count()
Alias for: get_option_count
to_h() click to toggle source
Calls superclass method Babeltrace2::BTFieldClass#to_h
# File lib/babeltrace2/trace-ir/field-class.rb, line 1710
def to_h
  res = super
  res[:options] = option_count.times.collect { |i|
    get_option_by_index(i).to_h
  }
  res
end