#include "internal/utils.hpp"
#include "cpp-common/optional.hpp"
#include "cpp-common/string_view.hpp"
-#include "lib-error.hpp"
+#include "exc.hpp"
namespace bt2 {
-
namespace internal {
struct ValueRefFuncs final
}
template <typename OtherLibObjT>
- CommonValue(const CommonValue<OtherLibObjT>& val) noexcept : _ThisBorrowedObj {val}
+ CommonValue(const CommonValue<OtherLibObjT> val) noexcept : _ThisBorrowedObj {val}
{
}
template <typename OtherLibObjT>
- _ThisCommonValue& operator=(const CommonValue<OtherLibObjT>& val) noexcept
+ _ThisCommonValue& operator=(const CommonValue<OtherLibObjT> val) noexcept
{
_ThisBorrowedObj::operator=(val);
return *this;
}
template <typename OtherLibObjT>
- bool operator==(const CommonValue<OtherLibObjT>& other) const noexcept
+ bool operator==(const CommonValue<OtherLibObjT> other) const noexcept
{
return static_cast<bool>(bt_value_is_equal(this->libObjPtr(), other.libObjPtr()));
}
template <typename OtherLibObjT>
- bool operator!=(const CommonValue<OtherLibObjT>& other) const noexcept
+ bool operator!=(const CommonValue<OtherLibObjT> other) const noexcept
{
return !(*this == other);
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
+ }
+
+ template <typename ValueT>
+ ValueT as() const noexcept
+ {
+ return ValueT {this->libObjPtr()};
}
CommonNullValue<LibObjT> asNull() const noexcept;
using Value = CommonValue<bt_value>;
using ConstValue = CommonValue<const bt_value>;
+namespace internal {
+
+struct ValueTypeDescr
+{
+ using Const = ConstValue;
+ using NonConst = Value;
+};
+
+template <>
+struct TypeDescr<Value> : public ValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstValue> : public ValueTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonNullValue final : public CommonValue<LibObjT>
{
}
template <typename OtherLibObjT>
- CommonNullValue(const CommonNullValue<OtherLibObjT>& val) noexcept : _ThisCommonValue {val}
+ CommonNullValue(const CommonNullValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
{
}
template <typename OtherLibObjT>
- CommonNullValue<LibObjT>& operator=(const CommonNullValue<OtherLibObjT>& val) noexcept
+ CommonNullValue<LibObjT>& operator=(const CommonNullValue<OtherLibObjT> val) noexcept
{
_ThisCommonValue::operator=(val);
return *this;
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using NullValue = CommonNullValue<bt_value>;
using ConstNullValue = CommonNullValue<const bt_value>;
+namespace internal {
+
+struct NullValueTypeDescr
+{
+ using Const = ConstNullValue;
+ using NonConst = NullValue;
+};
+
+template <>
+struct TypeDescr<NullValue> : public NullValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstNullValue> : public NullValueTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonBoolValue final : public CommonValue<LibObjT>
{
}
template <typename OtherLibObjT>
- CommonBoolValue(const CommonBoolValue<OtherLibObjT>& val) noexcept : _ThisCommonValue {val}
+ CommonBoolValue(const CommonBoolValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
{
}
const auto libObjPtr = bt_value_bool_create_init(static_cast<bt_bool>(rawVal));
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonBoolValue<LibObjT> {libObjPtr}};
+ return CommonBoolValue::Shared::createWithoutRef(libObjPtr);
}
template <typename OtherLibObjT>
- CommonBoolValue<LibObjT>& operator=(const CommonBoolValue<OtherLibObjT>& val) noexcept
+ CommonBoolValue<LibObjT>& operator=(const CommonBoolValue<OtherLibObjT> val) noexcept
{
_ThisCommonValue::operator=(val);
return *this;
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using BoolValue = CommonBoolValue<bt_value>;
using ConstBoolValue = CommonBoolValue<const bt_value>;
+namespace internal {
+
+struct BoolValueTypeDescr
+{
+ using Const = ConstBoolValue;
+ using NonConst = BoolValue;
+};
+
+template <>
+struct TypeDescr<BoolValue> : public BoolValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstBoolValue> : public BoolValueTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonUnsignedIntegerValue final : public CommonValue<LibObjT>
{
const auto libObjPtr = bt_value_integer_unsigned_create_init(rawVal);
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonUnsignedIntegerValue<LibObjT> {libObjPtr}};
+ return CommonUnsignedIntegerValue::Shared::createWithoutRef(libObjPtr);
}
template <typename OtherLibObjT>
- CommonUnsignedIntegerValue(const CommonUnsignedIntegerValue<OtherLibObjT>& val) noexcept :
+ CommonUnsignedIntegerValue(const CommonUnsignedIntegerValue<OtherLibObjT> val) noexcept :
_ThisCommonValue {val}
{
}
template <typename OtherLibObjT>
CommonUnsignedIntegerValue<LibObjT>&
- operator=(const CommonUnsignedIntegerValue<OtherLibObjT>& val) noexcept
+ operator=(const CommonUnsignedIntegerValue<OtherLibObjT> val) noexcept
{
static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using UnsignedIntegerValue = CommonUnsignedIntegerValue<bt_value>;
using ConstUnsignedIntegerValue = CommonUnsignedIntegerValue<const bt_value>;
+namespace internal {
+
+struct UnsignedIntegerValueTypeDescr
+{
+ using Const = ConstUnsignedIntegerValue;
+ using NonConst = UnsignedIntegerValue;
+};
+
+template <>
+struct TypeDescr<UnsignedIntegerValue> : public UnsignedIntegerValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstUnsignedIntegerValue> : public UnsignedIntegerValueTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonSignedIntegerValue final : public CommonValue<LibObjT>
{
const auto libObjPtr = bt_value_integer_signed_create_init(rawVal);
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonSignedIntegerValue<LibObjT> {libObjPtr}};
+ return CommonSignedIntegerValue::Shared::createWithoutRef(libObjPtr);
}
template <typename OtherLibObjT>
- CommonSignedIntegerValue(const CommonSignedIntegerValue<OtherLibObjT>& val) noexcept :
+ CommonSignedIntegerValue(const CommonSignedIntegerValue<OtherLibObjT> val) noexcept :
_ThisCommonValue {val}
{
}
template <typename OtherLibObjT>
CommonSignedIntegerValue<LibObjT>&
- operator=(const CommonSignedIntegerValue<OtherLibObjT>& val) noexcept
+ operator=(const CommonSignedIntegerValue<OtherLibObjT> val) noexcept
{
_ThisCommonValue::operator=(val);
return *this;
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using SignedIntegerValue = CommonSignedIntegerValue<bt_value>;
using ConstSignedIntegerValue = CommonSignedIntegerValue<const bt_value>;
+namespace internal {
+
+struct SignedIntegerValueTypeDescr
+{
+ using Const = ConstSignedIntegerValue;
+ using NonConst = SignedIntegerValue;
+};
+
+template <>
+struct TypeDescr<SignedIntegerValue> : public SignedIntegerValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstSignedIntegerValue> : public SignedIntegerValueTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonRealValue final : public CommonValue<LibObjT>
{
const auto libObjPtr = bt_value_real_create_init(rawVal);
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonRealValue<LibObjT> {libObjPtr}};
+ return CommonRealValue::Shared::createWithoutRef(libObjPtr);
}
template <typename OtherLibObjT>
- CommonRealValue(const CommonRealValue<OtherLibObjT>& val) noexcept : _ThisCommonValue {val}
+ CommonRealValue(const CommonRealValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
{
}
template <typename OtherLibObjT>
- CommonRealValue<LibObjT>& operator=(const CommonRealValue<OtherLibObjT>& val) noexcept
+ CommonRealValue<LibObjT>& operator=(const CommonRealValue<OtherLibObjT> val) noexcept
{
_ThisCommonValue::operator=(val);
return *this;
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using RealValue = CommonRealValue<bt_value>;
using ConstRealValue = CommonRealValue<const bt_value>;
+namespace internal {
+
+struct RealValueTypeDescr
+{
+ using Const = ConstRealValue;
+ using NonConst = RealValue;
+};
+
+template <>
+struct TypeDescr<RealValue> : public RealValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstRealValue> : public RealValueTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonStringValue final : public CommonValue<LibObjT>
{
const auto libObjPtr = bt_value_string_create_init(rawVal);
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonStringValue<LibObjT> {libObjPtr}};
+ return CommonStringValue::Shared::createWithoutRef(libObjPtr);
}
static Shared create(const std::string& rawVal)
{
- return CommonStringValue<LibObjT>::create(rawVal.data());
+ return CommonStringValue::create(rawVal.data());
}
template <typename OtherLibObjT>
- CommonStringValue(const CommonStringValue<OtherLibObjT>& val) noexcept : _ThisCommonValue {val}
+ CommonStringValue(const CommonStringValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
{
}
template <typename OtherLibObjT>
- CommonStringValue<LibObjT>& operator=(const CommonStringValue<OtherLibObjT>& val) noexcept
+ CommonStringValue<LibObjT>& operator=(const CommonStringValue<OtherLibObjT> val) noexcept
{
_ThisCommonValue::operator=(val);
return *this;
const auto status = bt_value_string_set(this->libObjPtr(), rawVal);
if (status == BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR) {
- throw LibMemoryError {};
+ throw MemoryError {};
}
return *this;
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
namespace internal {
+struct StringValueTypeDescr
+{
+ using Const = ConstStringValue;
+ using NonConst = StringValue;
+};
+
+template <>
+struct TypeDescr<StringValue> : public StringValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStringValue> : public StringValueTypeDescr
+{
+};
+
template <typename LibObjT>
struct CommonArrayValueSpec;
const auto libObjPtr = bt_value_array_create();
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonArrayValue<LibObjT> {libObjPtr}};
+ return CommonArrayValue::Shared::createWithoutRef(libObjPtr);
}
template <typename OtherLibObjT>
- CommonArrayValue(const CommonArrayValue<OtherLibObjT>& val) noexcept : _ThisCommonValue {val}
+ CommonArrayValue(const CommonArrayValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
{
}
template <typename OtherLibObjT>
- CommonArrayValue<LibObjT>& operator=(const CommonArrayValue<OtherLibObjT>& val) noexcept
+ CommonArrayValue<LibObjT>& operator=(const CommonArrayValue<OtherLibObjT> val) noexcept
{
_ThisCommonValue::operator=(val);
return *this;
internal::CommonArrayValueSpec<LibObjT>::elementByIndex(this->libObjPtr(), index)};
}
- void append(const Value& val)
+ void append(const Value val)
{
static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
CommonArrayValue<bt_value> appendEmptyArray();
CommonMapValue<bt_value> appendEmptyMap();
- void operator+=(const Value& val)
+ void operator+=(const Value val)
{
this->append(val);
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
private:
void _handleAppendLibStatus(const bt_value_array_append_element_status status) const
{
if (status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR) {
- throw LibMemoryError {};
+ throw MemoryError {};
}
}
};
namespace internal {
+struct ArrayValueTypeDescr
+{
+ using Const = ConstArrayValue;
+ using NonConst = ArrayValue;
+};
+
+template <>
+struct TypeDescr<ArrayValue> : public ArrayValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstArrayValue> : public ArrayValueTypeDescr
+{
+};
+
/*
* Type of a user function passed to `CommonMapValue<ObjT>::forEach()`.
*
return;
case BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR:
case BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR:
- throw LibError {};
+ throw Error {};
default:
bt_common_abort();
}
return;
case BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_USER_ERROR:
case BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR:
- throw LibError {};
+ throw Error {};
default:
bt_common_abort();
}
const auto libObjPtr = bt_value_map_create();
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonMapValue<LibObjT> {libObjPtr}};
+ return CommonMapValue::Shared::createWithoutRef(libObjPtr);
}
template <typename OtherLibObjT>
- CommonMapValue(const CommonMapValue<OtherLibObjT>& val) noexcept : _ThisCommonValue {val}
+ CommonMapValue(const CommonMapValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
{
}
template <typename OtherLibObjT>
- CommonMapValue<LibObjT>& operator=(const CommonMapValue<OtherLibObjT>& val) noexcept
+ CommonMapValue<LibObjT>& operator=(const CommonMapValue<OtherLibObjT> val) noexcept
{
_ThisCommonValue::operator=(val);
return *this;
return this->hasEntry(key.data());
}
- void insert(const char * const key, const Value& val)
+ void insert(const char * const key, const Value val)
{
static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
this->_handleInsertLibStatus(status);
}
- void insert(const std::string& key, const Value& val)
+ void insert(const std::string& key, const Value val)
{
this->insert(key.data(), val);
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
private:
void _handleInsertLibStatus(const bt_value_map_insert_entry_status status) const
{
if (status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR) {
- throw LibMemoryError {};
+ throw MemoryError {};
}
}
};
using MapValue = CommonMapValue<bt_value>;
using ConstMapValue = CommonMapValue<const bt_value>;
+namespace internal {
+
+struct MapValueTypeDescr
+{
+ using Const = ConstMapValue;
+ using NonConst = MapValue;
+};
+
+template <>
+struct TypeDescr<MapValue> : public MapValueTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstMapValue> : public MapValueTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
CommonNullValue<LibObjT> CommonValue<LibObjT>::asNull() const noexcept
{