Add C++ interface for the libbabeltrace2 `bt_value` API
This patch adds C++ wrappers for Babeltrace 2 value objects.
The class hierarchy is:
Value
NullValue
BoolValue
UnsignedIntegerValue
SignedIntegerValue
RealValue
StringValue
ArrayValue
MapValue
ConstValue
ConstNullValue
ConstBoolValue
ConstUnsignedIntegerValue
ConstSignedIntegerValue
ConstRealValue
ConstStringValue
ConstArrayValue
ConstMapValue
Implicitly convert from a mutable value to a constant value with
converting constructors and assignment operators.
All classes have the `Shared` type alias which is what the shared()
method returns. You can also implicitly convert from a shared mutable
value to a shared constant value.
Create a shared value with the static create() methods, for example:
auto myRealVal = bt2::RealValue::create(17.42);
You can also use one of the overloaded bt2::createValue() functions:
auto myStrVal = bt2::createValue("salut");
Those methods and functions can throw a `LibMemoryError` instance.
`NullValue` has no create() static function as there's nothing to be
created. If you want to wrap the null value singleton, use:
bt2::NullValue {}
or
bt2::ConstNullValue {}
If you want a shared null value for any reason, use:
bt2::NullValue {}.shared()
Downcast a `Value` or `ConstValue` object to a specific value object
with one of its as*() methods, for example:
auto myBoolVal = myVal.asBool();
Each as*() method checks that the conversion is legal with
BT_ASSERT_DBG().
MapValue::forEach() and ConstMapValue::forEach() accept a function which
receives the key and value of the entry, for example:
myMapVal.forEach([&](const bpstd::string_view& key,
const Value val) {
// Do something
});
If you throw anything from such a function, then
bt_value_map_foreach_entry() or bt_value_map_foreach_entry_const()
receives `BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR` or
`BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR`, which in turn makes the
forEach() method throw a `LibError` instance. As of this patch, there's
no way for the user function to gracefully interrupt the iterating
operation (`BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPT` and
`BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_INTERRUPT` status code
equivalents).
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I7c278aa660e9716a69e7d540763dc31623e45fec
Reviewed-on: https://review.lttng.org/c/babeltrace/+/4537
This page took 0.025001 seconds and 5 git commands to generate.