Class: Babeltrace2::BTFieldPath
- Inherits:
-
BTSharedObject
- Object
- BTObject
- BTSharedObject
- Babeltrace2::BTFieldPath
- Defined in:
- lib/babeltrace2/trace-ir/field-path.rb
Defined Under Namespace
Classes: Item
Constant Summary collapse
- Scope =
BTFieldPathScope
Instance Attribute Summary
Attributes inherited from BTObject
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
- #get_item_by_index(index) ⇒ Object (also: #[])
- #get_item_count ⇒ Object (also: #item_count, #size)
- #get_root_scope ⇒ Object (also: #root_scope)
-
#initialize(handle, retain: true, auto_release: true) ⇒ BTFieldPath
constructor
A new instance of BTFieldPath.
- #to_s ⇒ Object
Methods inherited from BTSharedObject
Methods inherited from BTObject
Constructor Details
#initialize(handle, retain: true, auto_release: true) ⇒ BTFieldPath
Returns a new instance of BTFieldPath.
40 41 42 |
# File 'lib/babeltrace2/trace-ir/field-path.rb', line 40 def initialize(handle, retain: true, auto_release: true) super(handle, retain: retain, auto_release: auto_release) end |
Class Method Details
.path_from_s_to_h(str) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/babeltrace2/trace-ir/field-path.rb', line 89 def self.path_from_s_to_h(str) str_orig = str m = str.match(/\A(PACKET_CONTEXT|EVENT_COMMON_CONTEXT|EVENT_SPECIFIC_CONTEXT|EVENT_PAYLOAD)/) raise "invalid path #{str}" if !m path = [(m[1].downcase << "_field_class").to_sym] str = str.sub(m[1], "") while !str.empty? case str when /\A\[(\d+)\]/ path.push :members, $1.to_i, :field_class str = str.sub("[#{$1}]", "") when /\A->/ path.push :element_field_class str = str.sub("->", "") when /\A=>/ path.push :field_class str = str.sub("=>", "") else raise "invalid path #{str_orig}" end end path end |
Instance Method Details
#each ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/babeltrace2/trace-ir/field-path.rb', line 63 def each if block_given? get_item_count.times { |i| yield get_item_by_index(i) } else to_enum(:each) end end |
#get_item_by_index(index) ⇒ Object Also known as: []
55 56 57 58 59 60 |
# File 'lib/babeltrace2/trace-ir/field-path.rb', line 55 def get_item_by_index(index) index = get_item_count + index if index < 0 return nil if index >= get_item_count || index < 0 BTFieldPathItem.new( Babeltrace2.bt_field_path_borrow_item_by_index_const(@handle, index)) end |
#get_item_count ⇒ Object Also known as: item_count, size
49 50 51 |
# File 'lib/babeltrace2/trace-ir/field-path.rb', line 49 def get_item_count @item_count ||= Babeltrace2.bt_field_path_get_item_count(@handle) end |
#get_root_scope ⇒ Object Also known as: root_scope
44 45 46 |
# File 'lib/babeltrace2/trace-ir/field-path.rb', line 44 def get_root_scope Babeltrace2.bt_field_path_get_root_scope(@handle) end |
#to_s ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/babeltrace2/trace-ir/field-path.rb', line 73 def to_s path = "" path << root_scope.to_s.sub("BT_FIELD_PATH_SCOPE_","") each { |e| case e.type when :BT_FIELD_PATH_ITEM_TYPE_INDEX path << "[#{e.index}]" when :BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT path << "->" when :BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT path << "=>" end } path end |