Class: Babeltrace2::BTField::Variant

Inherits:
Babeltrace2::BTField show all
Defined in:
lib/babeltrace2/trace-ir/field.rb

Direct Known Subclasses

WithSelectorField, WithoutSelectorField

Defined Under Namespace

Classes: WithSelectorField, WithoutSelectorField

Constant Summary

Constants inherited from Babeltrace2::BTField

TYPE_MAP

Instance Attribute Summary

Attributes inherited from Babeltrace2::BTObject

#handle

Instance Method Summary collapse

Methods inherited from Babeltrace2::BTField

from_handle, #get_class, #get_class_type

Methods inherited from Babeltrace2::BTObject

#==, #initialize, #to_ptr

Constructor Details

This class inherits a constructor from Babeltrace2::BTObject

Instance Method Details

#get_option_countObject Also known as: option_count



798
799
800
# File 'lib/babeltrace2/trace-ir/field.rb', line 798

def get_option_count
  @option_count ||= get_class.get_option_count
end

#get_selected_option_classObject Also known as: selected_option_class



824
825
826
827
828
# File 'lib/babeltrace2/trace-ir/field.rb', line 824

def get_selected_option_class
  handle = Babeltrace2.bt_field_variant_borrow_selected_option_class_const(@handle)
  return nil if handle.null?
  BTFieldClassVariantOption.new(handle)
end

#get_selected_option_fieldObject Also known as: selected_option_field



812
813
814
815
816
# File 'lib/babeltrace2/trace-ir/field.rb', line 812

def get_selected_option_field
  handle = Babeltrace2.bt_field_variant_borrow_selected_option_field(@handle)
  return nil if handle.null?
  BTField.from_handle(handle)
end

#get_selected_option_indexObject Also known as: selected_option_index



819
820
821
# File 'lib/babeltrace2/trace-ir/field.rb', line 819

def get_selected_option_index
  Babeltrace2.bt_field_variant_get_selected_option_index(@handle)
end

#select_option_by_index(index) ⇒ Object



803
804
805
806
807
808
809
810
# File 'lib/babeltrace2/trace-ir/field.rb', line 803

def select_option_by_index(index)
  count = get_option_count
  index += count if index < 0
  raise "invalid index" if index >= count || index < 0
  res = Babeltrace2.bt_field_variant_select_option_by_index(@handle, index)
  raise Babeltrace2.process_error(res) if res != :BT_FIELD_VARIANT_SELECT_OPTION_STATUS_OK
  self
end

#to_sObject



837
838
839
840
841
842
843
844
845
846
# File 'lib/babeltrace2/trace-ir/field.rb', line 837

def to_s
  s = "{"
  opt = get_selected_option_field
  if opt
    name = selected_option_class.name
    name = name.inspect if name.kind_of?(Symbol)
    s << "#{name}: #{opt.to_s}"
  end
  s << "}"
end

#valueObject



831
832
833
834
835
# File 'lib/babeltrace2/trace-ir/field.rb', line 831

def value
  f = get_selected_option_field
  return nil unless f
  { selected_option_class.name => f.value }
end