Remove some unused includes in C++ files
[babeltrace.git] / src / cpp-common / bt2 / value.hpp
index 816a5454d0ee52567f77f6f8d629a4c7a09a55e2..0dfe9dc614d42b8598b80365089700a3958d2ddf 100644 (file)
@@ -7,22 +7,24 @@
 #ifndef BABELTRACE_CPP_COMMON_BT2_VALUE_HPP
 #define BABELTRACE_CPP_COMMON_BT2_VALUE_HPP
 
-#include <type_traits>
 #include <cstdint>
 #include <functional>
+#include <type_traits>
+
 #include <babeltrace2/babeltrace.h>
 
 #include "common/assert.h"
 #include "common/common.h"
+#include "cpp-common/optional.hpp"
+#include "cpp-common/string_view.hpp"
+
+#include "common-iter.hpp"
+#include "exc.hpp"
 #include "internal/borrowed-obj.hpp"
 #include "internal/shared-obj.hpp"
 #include "internal/utils.hpp"
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
-#include "lib-error.hpp"
 
 namespace bt2 {
-
 namespace internal {
 
 struct ValueRefFuncs final
@@ -41,7 +43,7 @@ struct ValueRefFuncs final
 template <typename ObjT, typename LibObjT>
 using SharedValue = internal::SharedObj<ObjT, LibObjT, internal::ValueRefFuncs>;
 
-} // namespace internal
+} /* namespace internal */
 
 template <typename LibObjT>
 class CommonNullValue;
@@ -85,20 +87,36 @@ class CommonClockClass;
 template <typename LibObjT>
 class CommonFieldClass;
 
+template <typename LibObjT>
+class CommonTraceClass;
+
+template <typename LibObjT>
+class CommonStreamClass;
+
+template <typename LibObjT>
+class CommonEventClass;
+
+template <typename LibObjT>
+class CommonStream;
+
 template <typename LibObjT>
 class CommonValue : public internal::BorrowedObj<LibObjT>
 {
-    // Allow append() to call `val._libObjPtr()`
+    /* Allow append() to call `val.libObjPtr()` */
     friend class CommonArrayValue<bt_value>;
 
-    // Allow insert() to call `val._libObjPtr()`
+    /* Allow insert() to call `val.libObjPtr()` */
     friend class CommonMapValue<bt_value>;
 
-    // Allow userAttributes() to call `val._libObjPtr()`
+    /* Allow userAttributes() to call `val.libObjPtr()` */
     friend class CommonClockClass<bt_clock_class>;
     friend class CommonFieldClass<bt_field_class>;
+    friend class CommonTraceClass<bt_trace_class>;
+    friend class CommonStreamClass<bt_stream_class>;
+    friend class CommonEventClass<bt_event_class>;
+    friend class CommonStream<bt_stream>;
 
-    // Allow operator==() to call `other._libObjPtr()`
+    /* Allow operator==() to call `other.libObjPtr()` */
     friend class CommonValue<bt_value>;
     friend class CommonValue<const bt_value>;
 
@@ -117,12 +135,12 @@ public:
     }
 
     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;
@@ -130,7 +148,7 @@ public:
 
     ValueType type() const noexcept
     {
-        return static_cast<ValueType>(bt_value_get_type(this->_libObjPtr()));
+        return static_cast<ValueType>(bt_value_get_type(this->libObjPtr()));
     }
 
     bool isNull() const noexcept
@@ -179,20 +197,26 @@ public:
     }
 
     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()));
+        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;
@@ -207,13 +231,33 @@ public:
 protected:
     bool _libTypeIs(const bt_value_type type) const noexcept
     {
-        return bt_value_type_is(bt_value_get_type(this->_libObjPtr()), type);
+        return bt_value_type_is(bt_value_get_type(this->libObjPtr()), type);
     }
 };
 
 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>
 {
@@ -228,12 +272,12 @@ public:
     }
 
     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;
@@ -241,13 +285,33 @@ public:
 
     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>
 {
@@ -265,7 +329,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBoolValue(const CommonBoolValue<OtherLibObjT>& val) noexcept : _ThisCommonValue {val}
+    CommonBoolValue(const CommonBoolValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
     {
     }
 
@@ -274,11 +338,11 @@ public:
         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;
@@ -288,13 +352,13 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_value_bool_set(this->_libObjPtr(), static_cast<bt_bool>(rawVal));
+        bt_value_bool_set(this->libObjPtr(), static_cast<bt_bool>(rawVal));
         return *this;
     }
 
     Value value() const noexcept
     {
-        return static_cast<Value>(bt_value_bool_get(this->_libObjPtr()));
+        return static_cast<Value>(bt_value_bool_get(this->libObjPtr()));
     }
 
     operator Value() const noexcept
@@ -304,13 +368,33 @@ public:
 
     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>
 {
@@ -333,18 +417,18 @@ public:
         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`.");
 
@@ -354,13 +438,13 @@ public:
 
     CommonUnsignedIntegerValue<LibObjT>& operator=(const Value rawVal) noexcept
     {
-        bt_value_integer_unsigned_set(this->_libObjPtr(), rawVal);
+        bt_value_integer_unsigned_set(this->libObjPtr(), rawVal);
         return *this;
     }
 
     Value value() const noexcept
     {
-        return bt_value_integer_unsigned_get(this->_libObjPtr());
+        return bt_value_integer_unsigned_get(this->libObjPtr());
     }
 
     operator Value() const noexcept
@@ -370,13 +454,33 @@ public:
 
     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>
 {
@@ -399,18 +503,18 @@ public:
         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;
@@ -420,13 +524,13 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_value_integer_signed_set(this->_libObjPtr(), rawVal);
+        bt_value_integer_signed_set(this->libObjPtr(), rawVal);
         return *this;
     }
 
     Value value() const noexcept
     {
-        return bt_value_integer_signed_get(this->_libObjPtr());
+        return bt_value_integer_signed_get(this->libObjPtr());
     }
 
     operator Value() const noexcept
@@ -436,13 +540,33 @@ public:
 
     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>
 {
@@ -464,16 +588,16 @@ public:
         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;
@@ -483,13 +607,13 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_value_real_set(this->_libObjPtr(), rawVal);
+        bt_value_real_set(this->libObjPtr(), rawVal);
         return *this;
     }
 
     Value value() const noexcept
     {
-        return bt_value_real_get(this->_libObjPtr());
+        return bt_value_real_get(this->libObjPtr());
     }
 
     operator Value() const noexcept
@@ -499,13 +623,33 @@ public:
 
     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>
 {
@@ -526,21 +670,21 @@ public:
         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;
@@ -550,10 +694,10 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_value_string_set(this->_libObjPtr(), rawVal);
+        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;
@@ -566,12 +710,12 @@ public:
 
     bpstd::string_view value() const noexcept
     {
-        return bt_value_string_get(this->_libObjPtr());
+        return bt_value_string_get(this->libObjPtr());
     }
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 };
 
@@ -580,10 +724,26 @@ using ConstStringValue = CommonStringValue<const bt_value>;
 
 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;
 
-// Functions specific to mutable array values
+/* Functions specific to mutable array values */
 template <>
 struct CommonArrayValueSpec<bt_value> final
 {
@@ -593,7 +753,7 @@ struct CommonArrayValueSpec<bt_value> final
     }
 };
 
-// Functions specific to constant array values
+/* Functions specific to constant array values */
 template <>
 struct CommonArrayValueSpec<const bt_value> final
 {
@@ -604,7 +764,7 @@ struct CommonArrayValueSpec<const bt_value> final
     }
 };
 
-} // namespace internal
+} /* namespace internal */
 
 template <typename LibObjT>
 class CommonArrayValue final : public CommonValue<LibObjT>
@@ -615,6 +775,7 @@ private:
 
 public:
     using Shared = internal::SharedValue<CommonArrayValue<LibObjT>, LibObjT>;
+    using Iterator = CommonIterator<CommonArrayValue<LibObjT>, CommonValue<LibObjT>>;
 
     explicit CommonArrayValue(const _LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
     {
@@ -626,16 +787,16 @@ public:
         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;
@@ -643,7 +804,23 @@ public:
 
     std::uint64_t length() const noexcept
     {
-        return bt_value_array_get_length(this->_libObjPtr());
+        return bt_value_array_get_length(this->libObjPtr());
+    }
+
+    /* Required by the `CommonIterator` template class */
+    std::uint64_t size() const noexcept
+    {
+        return this->length();
+    }
+
+    Iterator begin() const noexcept
+    {
+        return Iterator {*this, 0};
+    }
+
+    Iterator end() const noexcept
+    {
+        return Iterator {*this, this->length()};
     }
 
     bool isEmpty() const noexcept
@@ -654,20 +831,20 @@ public:
     ConstValue operator[](const std::uint64_t index) const noexcept
     {
         return ConstValue {internal::CommonArrayValueSpec<const bt_value>::elementByIndex(
-            this->_libObjPtr(), index)};
+            this->libObjPtr(), index)};
     }
 
     CommonValue<LibObjT> operator[](const std::uint64_t index) noexcept
     {
         return CommonValue<LibObjT> {
-            internal::CommonArrayValueSpec<LibObjT>::elementByIndex(this->_libObjPtr(), index)};
+            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`.");
 
-        const auto status = bt_value_array_append_element(this->_libObjPtr(), val._libObjPtr());
+        const auto status = bt_value_array_append_element(this->libObjPtr(), val.libObjPtr());
 
         this->_handleAppendLibStatus(status);
     }
@@ -677,7 +854,7 @@ public:
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_value_array_append_bool_element(this->_libObjPtr(), static_cast<bt_bool>(rawVal));
+            bt_value_array_append_bool_element(this->libObjPtr(), static_cast<bt_bool>(rawVal));
 
         this->_handleAppendLibStatus(status);
     }
@@ -687,7 +864,7 @@ public:
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_value_array_append_unsigned_integer_element(this->_libObjPtr(), rawVal);
+            bt_value_array_append_unsigned_integer_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
     }
@@ -696,8 +873,7 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status =
-            bt_value_array_append_signed_integer_element(this->_libObjPtr(), rawVal);
+        const auto status = bt_value_array_append_signed_integer_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
     }
@@ -706,7 +882,7 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_value_array_append_real_element(this->_libObjPtr(), rawVal);
+        const auto status = bt_value_array_append_real_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
     }
@@ -715,7 +891,7 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_value_array_append_string_element(this->_libObjPtr(), rawVal);
+        const auto status = bt_value_array_append_string_element(this->libObjPtr(), rawVal);
 
         this->_handleAppendLibStatus(status);
     }
@@ -728,7 +904,7 @@ public:
     CommonArrayValue<bt_value> appendEmptyArray();
     CommonMapValue<bt_value> appendEmptyMap();
 
-    void operator+=(const Value& val)
+    void operator+=(const Value val)
     {
         this->append(val);
     }
@@ -765,14 +941,14 @@ public:
 
     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 {};
         }
     }
 };
@@ -782,6 +958,22 @@ using ConstArrayValue = CommonArrayValue<const bt_value>;
 
 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()`.
  *
@@ -819,7 +1011,7 @@ LibStatusT mapValueForEachLibFunc(const char * const key, LibObjT * const libObj
 template <typename LibObjT>
 struct CommonMapValueSpec;
 
-// Functions specific to mutable map values
+/* Functions specific to mutable map values */
 template <>
 struct CommonMapValueSpec<bt_value> final
 {
@@ -843,14 +1035,14 @@ struct CommonMapValueSpec<bt_value> final
             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();
         }
     }
 };
 
-// Functions specific to constant map values
+/* Functions specific to constant map values */
 template <>
 struct CommonMapValueSpec<const bt_value> final
 {
@@ -876,14 +1068,14 @@ struct CommonMapValueSpec<const bt_value> final
             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();
         }
     }
 };
 
-} // namespace internal
+} /* namespace internal */
 
 template <typename LibObjT>
 class CommonMapValue final : public CommonValue<LibObjT>
@@ -905,16 +1097,16 @@ public:
         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;
@@ -922,7 +1114,7 @@ public:
 
     std::uint64_t size() const noexcept
     {
-        return bt_value_map_get_size(this->_libObjPtr());
+        return bt_value_map_get_size(this->libObjPtr());
     }
 
     bool isEmpty() const noexcept
@@ -933,7 +1125,7 @@ public:
     nonstd::optional<ConstValue> operator[](const char * const key) const noexcept
     {
         const auto libObjPtr =
-            internal::CommonMapValueSpec<const bt_value>::entryByKey(this->_libObjPtr(), key);
+            internal::CommonMapValueSpec<const bt_value>::entryByKey(this->libObjPtr(), key);
 
         if (!libObjPtr) {
             return nonstd::nullopt;
@@ -950,7 +1142,7 @@ public:
     nonstd::optional<CommonValue<LibObjT>> operator[](const char * const key) noexcept
     {
         const auto libObjPtr =
-            internal::CommonMapValueSpec<LibObjT>::entryByKey(this->_libObjPtr(), key);
+            internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
 
         if (!libObjPtr) {
             return nonstd::nullopt;
@@ -966,7 +1158,7 @@ public:
 
     bool hasEntry(const char * const key) const noexcept
     {
-        return static_cast<bool>(bt_value_map_has_entry(this->_libObjPtr(), key));
+        return static_cast<bool>(bt_value_map_has_entry(this->libObjPtr(), key));
     }
 
     bool hasEntry(const std::string& key) const noexcept
@@ -974,16 +1166,16 @@ public:
         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`.");
 
-        const auto status = bt_value_map_insert_entry(this->_libObjPtr(), key, val._libObjPtr());
+        const auto status = bt_value_map_insert_entry(this->libObjPtr(), key, val.libObjPtr());
 
         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);
     }
@@ -993,7 +1185,7 @@ public:
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_value_map_insert_bool_entry(this->_libObjPtr(), key, static_cast<bt_bool>(rawVal));
+            bt_value_map_insert_bool_entry(this->libObjPtr(), key, static_cast<bt_bool>(rawVal));
 
         this->_handleInsertLibStatus(status);
     }
@@ -1008,7 +1200,7 @@ public:
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_value_map_insert_unsigned_integer_entry(this->_libObjPtr(), key, rawVal);
+            bt_value_map_insert_unsigned_integer_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
     }
@@ -1023,7 +1215,7 @@ public:
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_value_map_insert_signed_integer_entry(this->_libObjPtr(), key, rawVal);
+            bt_value_map_insert_signed_integer_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
     }
@@ -1037,7 +1229,7 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_value_map_insert_real_entry(this->_libObjPtr(), key, rawVal);
+        const auto status = bt_value_map_insert_real_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
     }
@@ -1051,7 +1243,7 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_value_map_insert_string_entry(this->_libObjPtr(), key, rawVal);
+        const auto status = bt_value_map_insert_string_entry(this->libObjPtr(), key, rawVal);
 
         this->_handleInsertLibStatus(status);
     }
@@ -1078,24 +1270,24 @@ public:
 
     void forEach(const internal::CommonMapValueForEachUserFunc<ConstValue>& func) const
     {
-        internal::CommonMapValueSpec<const bt_value>::forEach(this->_libObjPtr(), func);
+        internal::CommonMapValueSpec<const bt_value>::forEach(this->libObjPtr(), func);
     }
 
     void forEach(const internal::CommonMapValueForEachUserFunc<CommonValue<LibObjT>>& func)
     {
-        internal::CommonMapValueSpec<LibObjT>::forEach(this->_libObjPtr(), func);
+        internal::CommonMapValueSpec<LibObjT>::forEach(this->libObjPtr(), func);
     }
 
     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 {};
         }
     }
 };
@@ -1103,60 +1295,80 @@ 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
 {
     BT_ASSERT_DBG(this->isNull());
-    return CommonNullValue<LibObjT> {this->_libObjPtr()};
+    return CommonNullValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonBoolValue<LibObjT> CommonValue<LibObjT>::asBool() const noexcept
 {
     BT_ASSERT_DBG(this->isBool());
-    return CommonBoolValue<LibObjT> {this->_libObjPtr()};
+    return CommonBoolValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSignedIntegerValue<LibObjT> CommonValue<LibObjT>::asSignedInteger() const noexcept
 {
     BT_ASSERT_DBG(this->isSignedInteger());
-    return CommonSignedIntegerValue<LibObjT> {this->_libObjPtr()};
+    return CommonSignedIntegerValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonUnsignedIntegerValue<LibObjT> CommonValue<LibObjT>::asUnsignedInteger() const noexcept
 {
     BT_ASSERT_DBG(this->isUnsignedInteger());
-    return CommonUnsignedIntegerValue<LibObjT> {this->_libObjPtr()};
+    return CommonUnsignedIntegerValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonRealValue<LibObjT> CommonValue<LibObjT>::asReal() const noexcept
 {
     BT_ASSERT_DBG(this->isReal());
-    return CommonRealValue<LibObjT> {this->_libObjPtr()};
+    return CommonRealValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStringValue<LibObjT> CommonValue<LibObjT>::asString() const noexcept
 {
     BT_ASSERT_DBG(this->isString());
-    return CommonStringValue<LibObjT> {this->_libObjPtr()};
+    return CommonStringValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonArrayValue<LibObjT> CommonValue<LibObjT>::asArray() const noexcept
 {
     BT_ASSERT_DBG(this->isArray());
-    return CommonArrayValue<LibObjT> {this->_libObjPtr()};
+    return CommonArrayValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonMapValue<LibObjT> CommonValue<LibObjT>::asMap() const noexcept
 {
     BT_ASSERT_DBG(this->isMap());
-    return CommonMapValue<LibObjT> {this->_libObjPtr()};
+    return CommonMapValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
@@ -1165,7 +1377,7 @@ ArrayValue CommonArrayValue<LibObjT>::appendEmptyArray()
     static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
     bt_value *libElemPtr;
-    const auto status = bt_value_array_append_empty_array_element(this->_libObjPtr(), &libElemPtr);
+    const auto status = bt_value_array_append_empty_array_element(this->libObjPtr(), &libElemPtr);
 
     this->_handleAppendLibStatus(status);
     return ArrayValue {libElemPtr};
@@ -1177,7 +1389,7 @@ MapValue CommonArrayValue<LibObjT>::appendEmptyMap()
     static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
     bt_value *libElemPtr;
-    const auto status = bt_value_array_append_empty_map_element(this->_libObjPtr(), &libElemPtr);
+    const auto status = bt_value_array_append_empty_map_element(this->libObjPtr(), &libElemPtr);
 
     this->_handleAppendLibStatus(status);
     return MapValue {libElemPtr};
@@ -1189,8 +1401,7 @@ ArrayValue CommonMapValue<LibObjT>::insertEmptyArray(const char * const key)
     static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
     bt_value *libEntryPtr;
-    const auto status =
-        bt_value_map_insert_empty_array_entry(this->_libObjPtr(), key, &libEntryPtr);
+    const auto status = bt_value_map_insert_empty_array_entry(this->libObjPtr(), key, &libEntryPtr);
 
     this->_handleInsertLibStatus(status);
     return ArrayValue {libEntryPtr};
@@ -1208,7 +1419,7 @@ MapValue CommonMapValue<LibObjT>::insertEmptyMap(const char * const key)
     static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
     bt_value *libEntryPtr;
-    const auto status = bt_value_map_insert_empty_map_entry(this->_libObjPtr(), key, &libEntryPtr);
+    const auto status = bt_value_map_insert_empty_map_entry(this->libObjPtr(), key, &libEntryPtr);
 
     this->_handleInsertLibStatus(status);
     return MapValue {libEntryPtr};
@@ -1250,6 +1461,6 @@ inline StringValue::Shared createValue(const std::string& rawVal)
     return StringValue::create(rawVal);
 }
 
-} // namespace bt2
+} /* namespace bt2 */
 
-#endif // BABELTRACE_CPP_COMMON_BT2_VALUE_HPP
+#endif /* BABELTRACE_CPP_COMMON_BT2_VALUE_HPP */
This page took 0.058795 seconds and 4 git commands to generate.