Class: Babeltrace2::BTValue::Map
- Inherits:
-
Babeltrace2::BTValue
- Object
- Babeltrace2::BTObject
- Babeltrace2::BTSharedObject
- Babeltrace2::BTValue
- Babeltrace2::BTValue::Map
- Defined in:
- lib/babeltrace2/value.rb
Constant Summary collapse
- ForeachEntryFuncStatus =
BTValueMapForeachEntryFuncStatus- ForeachEntryStatus =
BTValueMapForeachEntryStatus- ForeachEntryConstFuncStatus =
BTValueMapForeachEntryConstFuncStatus- ForeachEntryConstStatus =
BTValueMapForeachEntryConstStatus- ExtendStatus =
BTValueMapExtendStatus
Constants inherited from Babeltrace2::BTValue
ArrayAppendElementStatus, ArraySetElementByIndexStatus, IntegerSigned, IntegerUnsigned, MapExtendStatus, MapForeachEntryConstFuncStatus, MapForeachEntryConstStatus, MapForeachEntryFuncStatus, MapForeachEntryStatus, StringSetStatus, TYPE_MAP
Instance Attribute Summary
Attributes inherited from Babeltrace2::BTObject
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #extend(other) ⇒ Object
- #extend!(other) ⇒ Object
- #get_entry_value(key) ⇒ Object (also: #[])
- #get_size ⇒ Object (also: #size)
- #has_entry(key) ⇒ Object (also: #include?)
-
#initialize(handle = nil, retain: true, auto_release: true) ⇒ Map
constructor
A new instance of Map.
- #insert_entry(key, value) ⇒ Object
- #value ⇒ Object (also: #to_h)
Methods inherited from Babeltrace2::BTValue
#copy, from_handle, from_value, #get_type, #is_equal, #to_s
Methods inherited from Babeltrace2::BTSharedObject
Methods inherited from Babeltrace2::BTObject
Constructor Details
#initialize(handle = nil, retain: true, auto_release: true) ⇒ Map
743 744 745 746 747 748 749 750 751 |
# File 'lib/babeltrace2/value.rb', line 743 def initialize(handle = nil, retain: true, auto_release: true) if handle super(handle, retain: retain, auto_release: auto_release) else handle = Babeltrace2.bt_value_map_create() raise Babeltrace2.process_error if handle.null? super(handle) end end |
Instance Method Details
#[]=(key, value) ⇒ Object
797 798 799 800 |
# File 'lib/babeltrace2/value.rb', line 797 def []=(key, value) insert_entry(key, value) value end |
#each(&block) ⇒ Object
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/babeltrace2/value.rb', line 825 def each(&block) if block_given? block_wrapper = lambda { |key, handle, ptr| begin val = BTValue.from_handle(handle) key = key[1..-1].to_sym if key[0] == ':' block.call(key, val) :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK rescue Exception => e Babeltrace2.stack_ruby_error(e, source: nil) :BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR end } Babeltrace2.bt_value_map_foreach_entry(@handle, block_wrapper, nil) else to_enum(:each) end end |
#empty? ⇒ Boolean
807 808 809 |
# File 'lib/babeltrace2/value.rb', line 807 def empty? size == 0 end |
#extend(other) ⇒ Object
857 858 859 860 861 |
# File 'lib/babeltrace2/value.rb', line 857 def extend(other) hsh = self.class.new hsh.extend!(self) hsh.extend!(other) end |
#extend!(other) ⇒ Object
851 852 853 854 855 |
# File 'lib/babeltrace2/value.rb', line 851 def extend!(other) res = Babeltrace2.bt_value_map_extend(@handle, other) raise Babeltrace2.process_error(res) if res != :BT_VALUE_COPY_STATUS_OK self end |
#get_entry_value(key) ⇒ Object Also known as: []
817 818 819 820 821 822 |
# File 'lib/babeltrace2/value.rb', line 817 def get_entry_value(key) key = key.inspect if key.kind_of?(Symbol) handle = Babeltrace2.bt_value_map_borrow_entry_value(@handle, key) return nil if handle.null? BTValue.from_handle(handle) end |
#get_size ⇒ Object Also known as: size
802 803 804 |
# File 'lib/babeltrace2/value.rb', line 802 def get_size Babeltrace2.bt_value_map_get_size(@handle) end |
#has_entry(key) ⇒ Object Also known as: include?
811 812 813 814 |
# File 'lib/babeltrace2/value.rb', line 811 def has_entry(key) key = key.inspect if key.kind_of?(Symbol) Babeltrace2.bt_value_map_has_entry(@handle, key) != BT_FALSE end |
#insert_entry(key, value) ⇒ Object
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/babeltrace2/value.rb', line 753 def insert_entry(key, value) key = key.inspect if key.kind_of?(Symbol) res = case value when BTValue Babeltrace2.bt_value_map_insert_entry(@handle, key, value) when nil Babeltrace2.bt_value_map_insert_entry(@handle, key, Babeltrace2.bt_value_null) when true Babeltrace2.bt_value_map_insert_bool_entry(@handle, key, BT_TRUE) when false Babeltrace2.bt_value_map_insert_bool_entry(@handle, key, BT_FALSE) when ::Integer if value > (1<<63) - 1 Babeltrace2.bt_value_map_insert_unsigned_integer_entry(@handle, key, value) else Babeltrace2.bt_value_map_insert_signed_integer_entry(@handle, key, value) end when ::Float Babeltrace2.bt_value_map_insert_real_entry(@handle, key, value) when ::String Babeltrace2.bt_value_map_insert_string_entry(@handle, key, value) when ::Array ptr = FFI::MemoryPointer.new(:pointer) res = Babeltrace2.bt_value_map_insert_empty_array_entry(@handle, key, ptr) raise Babeltrace2.process_error(res) if res != :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK arr = BTValueArray.new(BTValueArrayHandle.new(ptr.read_pointer), retain: false, auto_release: false) value.each { |v| arr.append_element(v) } :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK when ::Hash ptr = FFI::MemoryPointer.new(:pointer) res = Babeltrace2.bt_value_map_insert_empty_map_entry(@handle, key, ptr) raise Babeltrace2.process_error(res) if res != :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK map = BTValueMap.new(BTValueMapHandle.new(ptr.read_pointer), retain: false, auto_release: false) value.each { |k, v| map.insert_entry(k, v) } :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK else raise TypeError, "unsupported value type" end raise Babeltrace2.process_error(res) if res != :BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK self end |
#value ⇒ Object Also known as: to_h
844 845 846 847 848 |
# File 'lib/babeltrace2/value.rb', line 844 def value val = {} each { |k, v| val[k] = v.value } val end |