#include "lib-error.hpp"
namespace bt2 {
-
namespace internal {
struct ValueRefFuncs final
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>
{
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>
{
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>
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>
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>
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>
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>
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>
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
private:
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()`.
*
const auto libObjPtr = bt_value_map_create();
internal::validateCreatedObjPtr(libObjPtr);
- return Shared {CommonMapValue<LibObjT> {libObjPtr}};
+ return CommonMapValue::Shared::createWithoutRef(libObjPtr);
}
template <typename OtherLibObjT>
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
private:
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
{