Class: Babeltrace2::BTValue

Inherits:
BTSharedObject show all
Defined in:
lib/babeltrace2/value.rb,
lib/babeltrace2/value.rb,
lib/babeltrace2/value.rb,
lib/babeltrace2/value.rb,
lib/babeltrace2/value.rb,
lib/babeltrace2/value.rb

Direct Known Subclasses

Array, Bool, Integer, Map, Null, Real, String

Defined Under Namespace

Classes: Array, Bool, Integer, Map, Null, Real, String

Constant Summary collapse

TYPE_MAP =
{}
IntegerUnsigned =
BTValue::Integer::Unsigned
IntegerSigned =
BTValue::Integer::Signed
StringSetStatus =
BTValueStringSetStatus
ArrayAppendElementStatus =
BTValueArrayAppendElementStatus
ArraySetElementByIndexStatus =
BTValueArraySetElementByIndexStatus
MapForeachEntryFuncStatus =
BTValueMapForeachEntryFuncStatus
MapForeachEntryStatus =
BTValueMapForeachEntryStatus
MapForeachEntryConstFuncStatus =
BTValueMapForeachEntryConstFuncStatus
MapForeachEntryConstStatus =
BTValueMapForeachEntryConstStatus
MapExtendStatus =
BTValueMapExtendStatus

Instance Attribute Summary

Attributes inherited from BTObject

#handle

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BTSharedObject

inherited, #initialize

Methods inherited from BTObject

#initialize, #to_ptr

Constructor Details

This class inherits a constructor from Babeltrace2::BTSharedObject

Class Method Details

.from_handle(handle, retain: true, auto_release: true) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/babeltrace2/value.rb', line 62

def self.from_handle(handle, retain: true, auto_release: true)
  type = Babeltrace2.bt_value_get_type(handle)
  if type == :BT_VALUE_TYPE_NULL
    return BTValueNull.instance
  else
    clss = TYPE_MAP[type]
    raise "unsupported value type" unless clss
    handle = clss[0].new(handle)
    clss[1].new(handle, retain: retain, auto_release: auto_release)
  end
end

.from_value(value) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/babeltrace2/value.rb', line 74

def self.from_value(value)
  case value
  when BTValue
    value
  when nil
    return BTValueNull.instance
  when false
    Bool.new(value: false)
  when true
    Bool.new(value: true)
  when ::Integer
    if value > (1<<63) - 1
      BTValueIntegerUnsigned.new(value: value)
    else
      BTValueIntegerSigned.new(value: value)
    end
  when ::Float
    BTValueReal.new(value: value)
  when ::String
    BTValueString.new(value: value)
  when ::Array
    arr = BTValueArray.new
    value.each { |v|
      arr.push(v)
    }
    arr
  when ::Hash
    map = BTValueMap.new
    value.each { |k, v|
      map.insert_entry(k, v)
    }
    map
  else
    raise TypeError, "unsupported value type"
  end
end

Instance Method Details

#copyObject



115
116
117
118
119
120
# File 'lib/babeltrace2/value.rb', line 115

def copy
  ptr = FFI::MemoryPointer.new(:pointer)
  res = Babeltrace2.bt_value_copy(@handle, ptr)
  raise Babeltrace2.process_error(res) if res != :BT_VALUE_COPY_STATUS_OK
  BTValue.from_handle(BTValueHandle.new(ptr.read_pointer), retain: false)
end

#get_typeObject Also known as: type



57
58
59
# File 'lib/babeltrace2/value.rb', line 57

def get_type
  Babeltrace2.bt_value_get_type(@handle)
end

#is_equal(other) ⇒ Object Also known as: ==



122
123
124
125
# File 'lib/babeltrace2/value.rb', line 122

def is_equal(other)
  other = BTValue.from_value(other)
  Babeltrace2.bt_value_is_equal(@handle, other) != BT_FALSE
end

#to_sObject



111
112
113
# File 'lib/babeltrace2/value.rb', line 111

def to_s
  value.to_s
end