cpp-common/bt2: field.hpp: Add assignment operator for Enum field
[babeltrace.git] / src / cpp-common / bt2 / field.hpp
index 54f3b38a1548e111775a24b3f2baffad0056ecb8..4b3853826b2871478eb9f634d9cc39dfd73d8b76 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "common/assert.h"
 #include "internal/borrowed-obj.hpp"
+#include "internal/utils.hpp"
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
 #include "field-class.hpp"
@@ -107,12 +108,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonField(const CommonField<OtherLibObjT>& val) noexcept : _ThisBorrowedObj {val}
+    CommonField(const CommonField<OtherLibObjT> val) noexcept : _ThisBorrowedObj {val}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonField& operator=(const CommonField<OtherLibObjT>& val) noexcept
+    _ThisCommonField& operator=(const CommonField<OtherLibObjT> val) noexcept
     {
         _ThisBorrowedObj::operator=(val);
         return *this;
@@ -120,17 +121,17 @@ public:
 
     FieldClassType classType() const noexcept
     {
-        return static_cast<FieldClassType>(bt_field_get_class_type(this->_libObjPtr()));
+        return static_cast<FieldClassType>(bt_field_get_class_type(this->libObjPtr()));
     }
 
     ConstFieldClass cls() const noexcept
     {
-        return ConstFieldClass {internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+        return ConstFieldClass {internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     bool isBool() const noexcept
@@ -203,6 +204,12 @@ public:
         return this->cls().isVariant();
     }
 
+    template <typename FieldT>
+    FieldT as() const noexcept
+    {
+        return FieldT {this->libObjPtr()};
+    }
+
     CommonBoolField<LibObjT> asBool() const noexcept;
     CommonBitArrayField<LibObjT> asBitArray() const noexcept;
     CommonUnsignedIntegerField<LibObjT> asUnsignedInteger() const noexcept;
@@ -222,6 +229,26 @@ public:
 using Field = CommonField<bt_field>;
 using ConstField = CommonField<const bt_field>;
 
+namespace internal {
+
+struct FieldTypeDescr
+{
+    using Const = ConstField;
+    using NonConst = Field;
+};
+
+template <>
+struct TypeDescr<Field> : public FieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstField> : public FieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 class CommonBoolField final : public CommonField<LibObjT>
 {
@@ -238,12 +265,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBoolField(const CommonBoolField<OtherLibObjT>& val) noexcept : _ThisCommonField {val}
+    CommonBoolField(const CommonBoolField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonBoolField<LibObjT>& operator=(const CommonBoolField<OtherLibObjT>& val) noexcept
+    CommonBoolField<LibObjT>& operator=(const CommonBoolField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -253,13 +280,13 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_bool_set_value(this->_libObjPtr(), static_cast<bt_bool>(val));
+        bt_field_bool_set_value(this->libObjPtr(), static_cast<bt_bool>(val));
         return *this;
     }
 
     Value value() const noexcept
     {
-        return static_cast<Value>(bt_field_bool_get_value(this->_libObjPtr()));
+        return static_cast<Value>(bt_field_bool_get_value(this->libObjPtr()));
     }
 
     operator Value() const noexcept
@@ -271,6 +298,26 @@ public:
 using BoolField = CommonBoolField<bt_field>;
 using ConstBoolField = CommonBoolField<const bt_field>;
 
+namespace internal {
+
+struct BoolFieldTypeDescr
+{
+    using Const = ConstBoolField;
+    using NonConst = BoolField;
+};
+
+template <>
+struct TypeDescr<BoolField> : public BoolFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstBoolField> : public BoolFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 class CommonBitArrayField final : public CommonField<LibObjT>
 {
@@ -288,13 +335,13 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBitArrayField(const CommonBitArrayField<OtherLibObjT>& val) noexcept :
+    CommonBitArrayField(const CommonBitArrayField<OtherLibObjT> val) noexcept :
         _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonBitArrayField<LibObjT>& operator=(const CommonBitArrayField<OtherLibObjT>& val) noexcept
+    CommonBitArrayField<LibObjT>& operator=(const CommonBitArrayField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -303,25 +350,25 @@ public:
     ConstBitArrayFieldClass cls() const noexcept
     {
         return ConstBitArrayFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     CommonBitArrayField<LibObjT>& operator=(const std::uint64_t bits) noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_bit_array_set_value_as_integer(this->_libObjPtr(), bits);
+        bt_field_bit_array_set_value_as_integer(this->libObjPtr(), bits);
         return *this;
     }
 
     std::uint64_t valueAsInteger() const noexcept
     {
-        return bt_field_bit_array_get_value_as_integer(this->_libObjPtr());
+        return bt_field_bit_array_get_value_as_integer(this->libObjPtr());
     }
 
     bool bitValue(const std::uint64_t index) const noexcept
@@ -334,8 +381,28 @@ public:
 using BitArrayField = CommonBitArrayField<bt_field>;
 using ConstBitArrayField = CommonBitArrayField<const bt_field>;
 
+namespace internal {
+
+struct BitArrayFieldTypeDescr
+{
+    using Const = ConstBitArrayField;
+    using NonConst = BitArrayField;
+};
+
+template <>
+struct TypeDescr<BitArrayField> : public BitArrayFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstBitArrayField> : public BitArrayFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
-class CommonUnsignedIntegerField final : public CommonField<LibObjT>
+class CommonUnsignedIntegerField : public CommonField<LibObjT>
 {
 private:
     using typename CommonField<LibObjT>::_ThisCommonField;
@@ -357,14 +424,14 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonUnsignedIntegerField(const CommonUnsignedIntegerField<OtherLibObjT>& val) noexcept :
+    CommonUnsignedIntegerField(const CommonUnsignedIntegerField<OtherLibObjT> val) noexcept :
         _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonUnsignedIntegerField&
-    operator=(const CommonUnsignedIntegerField<OtherLibObjT>& val) noexcept
+    operator=(const CommonUnsignedIntegerField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -373,25 +440,25 @@ public:
     ConstIntegerFieldClass cls() const noexcept
     {
         return ConstIntegerFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     CommonUnsignedIntegerField<LibObjT>& operator=(const Value val) noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_integer_unsigned_set_value(this->_libObjPtr(), val);
+        bt_field_integer_unsigned_set_value(this->libObjPtr(), val);
         return *this;
     }
 
     Value value() const noexcept
     {
-        return bt_field_integer_unsigned_get_value(this->_libObjPtr());
+        return bt_field_integer_unsigned_get_value(this->libObjPtr());
     }
 
     operator Value() const noexcept
@@ -403,8 +470,28 @@ public:
 using UnsignedIntegerField = CommonUnsignedIntegerField<bt_field>;
 using ConstUnsignedIntegerField = CommonUnsignedIntegerField<const bt_field>;
 
+namespace internal {
+
+struct UnsignedIntegerFieldTypeDescr
+{
+    using Const = ConstUnsignedIntegerField;
+    using NonConst = UnsignedIntegerField;
+};
+
+template <>
+struct TypeDescr<UnsignedIntegerField> : public UnsignedIntegerFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstUnsignedIntegerField> : public UnsignedIntegerFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
-class CommonSignedIntegerField final : public CommonField<LibObjT>
+class CommonSignedIntegerField : public CommonField<LibObjT>
 {
 private:
     using typename CommonField<LibObjT>::_ThisCommonField;
@@ -414,7 +501,7 @@ protected:
     using _ThisCommonSignedIntegerField = CommonSignedIntegerField<LibObjT>;
 
 public:
-    using Value = std::uint64_t;
+    using Value = std::int64_t;
 
     using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstIntegerFieldClass,
                                             IntegerFieldClass>::type;
@@ -426,14 +513,14 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonSignedIntegerField(const CommonSignedIntegerField<OtherLibObjT>& val) noexcept :
+    CommonSignedIntegerField(const CommonSignedIntegerField<OtherLibObjT> val) noexcept :
         _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonSignedIntegerField&
-    operator=(const CommonSignedIntegerField<OtherLibObjT>& val) noexcept
+    operator=(const CommonSignedIntegerField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -442,25 +529,25 @@ public:
     ConstIntegerFieldClass cls() const noexcept
     {
         return ConstIntegerFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     CommonSignedIntegerField<LibObjT>& operator=(const Value val) noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_integer_signed_set_value(this->_libObjPtr(), val);
+        bt_field_integer_signed_set_value(this->libObjPtr(), val);
         return *this;
     }
 
     Value value() const noexcept
     {
-        return bt_field_integer_signed_get_value(this->_libObjPtr());
+        return bt_field_integer_signed_get_value(this->libObjPtr());
     }
 
     operator Value() const noexcept
@@ -472,6 +559,26 @@ public:
 using SignedIntegerField = CommonSignedIntegerField<bt_field>;
 using ConstSignedIntegerField = CommonSignedIntegerField<const bt_field>;
 
+namespace internal {
+
+struct SignedIntegerFieldTypeDescr
+{
+    using Const = ConstSignedIntegerField;
+    using NonConst = SignedIntegerField;
+};
+
+template <>
+struct TypeDescr<SignedIntegerField> : public SignedIntegerFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstSignedIntegerField> : public SignedIntegerFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 class EnumerationFieldClassMappingLabels
 {
 public:
@@ -522,7 +629,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonUnsignedEnumerationField(const CommonUnsignedEnumerationField<OtherLibObjT>& val) noexcept
+    CommonUnsignedEnumerationField(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept
         :
         _ThisCommonUnsignedIntegerField {val}
     {
@@ -530,7 +637,7 @@ public:
 
     template <typename OtherLibObjT>
     CommonUnsignedEnumerationField<LibObjT>&
-    operator=(const CommonUnsignedEnumerationField<OtherLibObjT>& val) noexcept
+    operator=(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept
     {
         _ThisCommonUnsignedIntegerField::operator=(val);
         return *this;
@@ -539,23 +646,25 @@ public:
     ConstUnsignedEnumerationFieldClass cls() const noexcept
     {
         return ConstUnsignedEnumerationFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
+    using CommonUnsignedIntegerField<LibObjT>::operator=;
+
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     EnumerationFieldClassMappingLabels labels() const
     {
         bt_field_class_enumeration_mapping_label_array labelArray;
         std::uint64_t count;
-        const auto status = bt_field_enumeration_unsigned_get_mapping_labels(this->_libObjPtr(),
+        const auto status = bt_field_enumeration_unsigned_get_mapping_labels(this->libObjPtr(),
                                                                              &labelArray, &count);
 
         if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
 
         return EnumerationFieldClassMappingLabels {labelArray, count};
@@ -565,6 +674,26 @@ public:
 using UnsignedEnumerationField = CommonUnsignedEnumerationField<bt_field>;
 using ConstUnsignedEnumerationField = CommonUnsignedEnumerationField<const bt_field>;
 
+namespace internal {
+
+struct UnsignedEnumerationFieldTypeDescr
+{
+    using Const = ConstUnsignedEnumerationField;
+    using NonConst = UnsignedEnumerationField;
+};
+
+template <>
+struct TypeDescr<UnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstUnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 class CommonSignedEnumerationField final : public CommonSignedIntegerField<LibObjT>
 {
@@ -584,28 +713,30 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonSignedEnumerationField(const CommonSignedEnumerationField<OtherLibObjT>& val) noexcept :
+    CommonSignedEnumerationField(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept :
         _ThisCommonSignedIntegerField {val}
     {
     }
 
     template <typename OtherLibObjT>
     CommonSignedEnumerationField<LibObjT>&
-    operator=(const CommonSignedEnumerationField<OtherLibObjT>& val) noexcept
+    operator=(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept
     {
         _ThisCommonSignedIntegerField::operator=(val);
         return *this;
     }
 
+    using CommonSignedIntegerField<LibObjT>::operator=;
+
     ConstSignedEnumerationFieldClass cls() const noexcept
     {
         return ConstSignedEnumerationFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     EnumerationFieldClassMappingLabels labels() const
@@ -613,10 +744,10 @@ public:
         bt_field_class_enumeration_mapping_label_array labelArray;
         std::uint64_t count;
         const auto status =
-            bt_field_enumeration_signed_get_mapping_labels(this->_libObjPtr(), &labelArray, &count);
+            bt_field_enumeration_signed_get_mapping_labels(this->libObjPtr(), &labelArray, &count);
 
         if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
 
         return EnumerationFieldClassMappingLabels {labelArray, count};
@@ -626,6 +757,26 @@ public:
 using SignedEnumerationField = CommonSignedEnumerationField<bt_field>;
 using ConstSignedEnumerationField = CommonSignedEnumerationField<const bt_field>;
 
+namespace internal {
+
+struct SignedEnumerationFieldTypeDescr
+{
+    using Const = ConstSignedEnumerationField;
+    using NonConst = SignedEnumerationField;
+};
+
+template <>
+struct TypeDescr<SignedEnumerationField> : public SignedEnumerationFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstSignedEnumerationField> : public SignedEnumerationFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 class CommonSinglePrecisionRealField final : public CommonField<LibObjT>
 {
@@ -643,7 +794,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonSinglePrecisionRealField(const CommonSinglePrecisionRealField<OtherLibObjT>& val) noexcept
+    CommonSinglePrecisionRealField(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
         :
         _ThisCommonField {val}
     {
@@ -651,7 +802,7 @@ public:
 
     template <typename OtherLibObjT>
     CommonSinglePrecisionRealField<LibObjT>&
-    operator=(const CommonSinglePrecisionRealField<OtherLibObjT>& val) noexcept
+    operator=(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -661,13 +812,13 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_real_single_precision_set_value(this->_libObjPtr(), val);
+        bt_field_real_single_precision_set_value(this->libObjPtr(), val);
         return *this;
     }
 
     Value value() const noexcept
     {
-        return bt_field_real_single_precision_get_value(this->_libObjPtr());
+        return bt_field_real_single_precision_get_value(this->libObjPtr());
     }
 
     operator Value() const noexcept
@@ -679,6 +830,26 @@ public:
 using SinglePrecisionRealField = CommonSinglePrecisionRealField<bt_field>;
 using ConstSinglePrecisionRealField = CommonSinglePrecisionRealField<const bt_field>;
 
+namespace internal {
+
+struct SinglePrecisionRealFieldTypeDescr
+{
+    using Const = ConstSinglePrecisionRealField;
+    using NonConst = SinglePrecisionRealField;
+};
+
+template <>
+struct TypeDescr<SinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstSinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 class CommonDoublePrecisionRealField final : public CommonField<LibObjT>
 {
@@ -696,7 +867,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonDoublePrecisionRealField(const CommonDoublePrecisionRealField<OtherLibObjT>& val) noexcept
+    CommonDoublePrecisionRealField(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
         :
         _ThisCommonField {val}
     {
@@ -704,7 +875,7 @@ public:
 
     template <typename OtherLibObjT>
     CommonDoublePrecisionRealField<LibObjT>&
-    operator=(const CommonDoublePrecisionRealField<OtherLibObjT>& val) noexcept
+    operator=(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -714,13 +885,13 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_real_single_precision_set_value(this->_libObjPtr(), val);
+        bt_field_real_double_precision_set_value(this->libObjPtr(), val);
         return *this;
     }
 
     Value value() const noexcept
     {
-        return bt_field_real_single_precision_get_value(this->_libObjPtr());
+        return bt_field_real_double_precision_get_value(this->libObjPtr());
     }
 
     operator Value() const noexcept
@@ -732,6 +903,26 @@ public:
 using DoublePrecisionRealField = CommonDoublePrecisionRealField<bt_field>;
 using ConstDoublePrecisionRealField = CommonDoublePrecisionRealField<const bt_field>;
 
+namespace internal {
+
+struct DoublePrecisionRealFieldTypeDescr
+{
+    using Const = ConstDoublePrecisionRealField;
+    using NonConst = DoublePrecisionRealField;
+};
+
+template <>
+struct TypeDescr<DoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstDoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 class CommonStringField final : public CommonField<LibObjT>
 {
@@ -746,45 +937,61 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStringField(const CommonStringField<OtherLibObjT>& val) noexcept : _ThisCommonField {val}
+    CommonStringField(const CommonStringField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonStringField<LibObjT>& operator=(const CommonStringField<OtherLibObjT>& val) noexcept
+    CommonStringField<LibObjT>& operator=(const CommonStringField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
-    CommonStringField<LibObjT>& operator=(const char * const val) noexcept
+    CommonStringField<LibObjT>& operator=(const char * const val)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_field_string_set_value(this->_libObjPtr(), val);
+        const auto status = bt_field_string_set_value(this->libObjPtr(), val);
 
         if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
 
         return *this;
     }
 
-    CommonStringField<LibObjT>& operator=(const std::string& val) noexcept
+    CommonStringField<LibObjT>& operator=(const std::string& val)
     {
         return *this = val.data();
     }
 
+    void append(const char * const begin, const std::uint64_t len)
+    {
+        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+
+        const auto status = bt_field_string_append_with_length(this->libObjPtr(), begin, len);
+
+        if (status == BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR) {
+            throw MemoryError {};
+        }
+    }
+
+    void append(const std::string& val)
+    {
+        this->append(val.data(), val.size());
+    }
+
     void clear() noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_string_clear(this->_libObjPtr());
+        bt_field_string_clear(this->libObjPtr());
     }
 
     bpstd::string_view value() const noexcept
     {
-        return bt_field_string_get_value(this->_libObjPtr());
+        return bt_field_string_get_value(this->libObjPtr());
     }
 };
 
@@ -793,6 +1000,22 @@ using ConstStringField = CommonStringField<const bt_field>;
 
 namespace internal {
 
+struct StringFieldTypeDescr
+{
+    using Const = ConstStringField;
+    using NonConst = StringField;
+};
+
+template <>
+struct TypeDescr<StringField> : public StringFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStringField> : public StringFieldTypeDescr
+{
+};
+
 template <typename LibObjT>
 struct CommonStructureFieldSpec;
 
@@ -850,13 +1073,13 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStructureField(const CommonStructureField<OtherLibObjT>& val) noexcept :
+    CommonStructureField(const CommonStructureField<OtherLibObjT> val) noexcept :
         _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonStructureField<LibObjT>& operator=(const CommonStructureField<OtherLibObjT>& val) noexcept
+    CommonStructureField<LibObjT>& operator=(const CommonStructureField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -865,12 +1088,12 @@ public:
     ConstStructureFieldClass cls() const noexcept
     {
         return ConstStructureFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     std::uint64_t size() const noexcept
@@ -881,19 +1104,19 @@ public:
     ConstField operator[](const std::uint64_t index) const noexcept
     {
         return ConstField {internal::CommonStructureFieldSpec<const bt_field>::memberFieldByIndex(
-            this->_libObjPtr(), index)};
+            this->libObjPtr(), index)};
     }
 
     CommonField<LibObjT> operator[](const std::uint64_t index) noexcept
     {
-        return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->_libObjPtr(), index)};
+        return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
     }
 
     nonstd::optional<ConstField> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr =
-            internal::CommonStructureFieldSpec<const bt_field>::memberFieldByName(
-                this->_libObjPtr(), name);
+            internal::CommonStructureFieldSpec<const bt_field>::memberFieldByName(this->libObjPtr(),
+                                                                                  name);
 
         if (libObjPtr) {
             return ConstField {libObjPtr};
@@ -909,7 +1132,7 @@ public:
 
     nonstd::optional<CommonField<LibObjT>> operator[](const char * const name) noexcept
     {
-        const auto libObjPtr = _Spec::memberFieldByName(this->_libObjPtr(), name);
+        const auto libObjPtr = _Spec::memberFieldByName(this->libObjPtr(), name);
 
         if (libObjPtr) {
             return CommonField<LibObjT> {libObjPtr};
@@ -929,6 +1152,22 @@ using ConstStructureField = CommonStructureField<const bt_field>;
 
 namespace internal {
 
+struct StructureFieldTypeDescr
+{
+    using Const = ConstStructureField;
+    using NonConst = StructureField;
+};
+
+template <>
+struct TypeDescr<StructureField> : public StructureFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStructureField> : public StructureFieldTypeDescr
+{
+};
+
 template <typename LibObjT>
 struct CommonArrayFieldSpec;
 
@@ -977,12 +1216,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonArrayField(const CommonArrayField<OtherLibObjT>& val) noexcept : _ThisCommonField {val}
+    CommonArrayField(const CommonArrayField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonArrayField& operator=(const CommonArrayField<OtherLibObjT>& val) noexcept
+    _ThisCommonArrayField& operator=(const CommonArrayField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -991,34 +1230,54 @@ public:
     ConstArrayFieldClass cls() const noexcept
     {
         return ConstArrayFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     std::uint64_t length() const noexcept
     {
-        return bt_field_array_get_length(this->_libObjPtr());
+        return bt_field_array_get_length(this->libObjPtr());
     }
 
     ConstField operator[](const std::uint64_t index) const noexcept
     {
         return ConstField {internal::CommonArrayFieldSpec<const bt_field>::elementFieldByIndex(
-            this->_libObjPtr(), index)};
+            this->libObjPtr(), index)};
     }
 
     CommonField<LibObjT> operator[](const std::uint64_t index) noexcept
     {
-        return CommonField<LibObjT> {_Spec::elementFieldByIndex(this->_libObjPtr(), index)};
+        return CommonField<LibObjT> {_Spec::elementFieldByIndex(this->libObjPtr(), index)};
     }
 };
 
 using ArrayField = CommonArrayField<bt_field>;
 using ConstArrayField = CommonArrayField<const bt_field>;
 
+namespace internal {
+
+struct ArrayFieldTypeDescr
+{
+    using Const = ConstArrayField;
+    using NonConst = ArrayField;
+};
+
+template <>
+struct TypeDescr<ArrayField> : public ArrayFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstArrayField> : public ArrayFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 class CommonDynamicArrayField : public CommonArrayField<LibObjT>
 {
@@ -1034,14 +1293,14 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonDynamicArrayField(const CommonDynamicArrayField<OtherLibObjT>& val) noexcept :
+    CommonDynamicArrayField(const CommonDynamicArrayField<OtherLibObjT> val) noexcept :
         _ThisCommonArrayField {val}
     {
     }
 
     template <typename OtherLibObjT>
     CommonDynamicArrayField<LibObjT>&
-    operator=(const CommonDynamicArrayField<OtherLibObjT>& val) noexcept
+    operator=(const CommonDynamicArrayField<OtherLibObjT> val) noexcept
     {
         _ThisCommonArrayField::operator=(val);
         return *this;
@@ -1056,10 +1315,10 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_field_array_dynamic_set_length(this->_libObjPtr(), length);
+        const auto status = bt_field_array_dynamic_set_length(this->libObjPtr(), length);
 
         if (status == BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 };
@@ -1069,6 +1328,22 @@ using ConstDynamicArrayField = CommonDynamicArrayField<const bt_field>;
 
 namespace internal {
 
+struct DynamicArrayFieldTypeDescr
+{
+    using Const = ConstDynamicArrayField;
+    using NonConst = DynamicArrayField;
+};
+
+template <>
+struct TypeDescr<DynamicArrayField> : public DynamicArrayFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstDynamicArrayField> : public DynamicArrayFieldTypeDescr
+{
+};
+
 template <typename LibObjT>
 struct CommonOptionFieldSpec;
 
@@ -1112,12 +1387,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionField(const CommonOptionField<OtherLibObjT>& val) noexcept : _ThisCommonField {val}
+    CommonOptionField(const CommonOptionField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonOptionField<LibObjT>& operator=(const CommonOptionField<OtherLibObjT>& val) noexcept
+    CommonOptionField<LibObjT>& operator=(const CommonOptionField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -1126,19 +1401,19 @@ public:
     ConstOptionFieldClass cls() const noexcept
     {
         return ConstOptionFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     void hasField(const bool hasField) noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_field_option_set_has_field(this->_libObjPtr(), static_cast<bt_bool>(hasField));
+        bt_field_option_set_has_field(this->libObjPtr(), static_cast<bt_bool>(hasField));
     }
 
     bool hasField() const noexcept
@@ -1149,7 +1424,7 @@ public:
     nonstd::optional<ConstField> field() const noexcept
     {
         const auto libObjPtr =
-            internal::CommonOptionFieldSpec<const bt_field>::field(this->_libObjPtr());
+            internal::CommonOptionFieldSpec<const bt_field>::field(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstField {libObjPtr};
@@ -1160,7 +1435,7 @@ public:
 
     nonstd::optional<CommonField<LibObjT>> field() noexcept
     {
-        const auto libObjPtr = _Spec::field(this->_libObjPtr());
+        const auto libObjPtr = _Spec::field(this->libObjPtr());
 
         if (libObjPtr) {
             return CommonField<LibObjT> {libObjPtr};
@@ -1175,6 +1450,22 @@ using ConstOptionField = CommonOptionField<const bt_field>;
 
 namespace internal {
 
+struct OptionFieldTypeDescr
+{
+    using Const = ConstOptionField;
+    using NonConst = OptionField;
+};
+
+template <>
+struct TypeDescr<OptionField> : public OptionFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstOptionField> : public OptionFieldTypeDescr
+{
+};
+
 template <typename LibObjT>
 struct CommonVariantFieldSpec;
 
@@ -1218,13 +1509,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantField(const CommonVariantField<OtherLibObjT>& val) noexcept :
-        _ThisCommonField {val}
+    CommonVariantField(const CommonVariantField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonVariantField<LibObjT>& operator=(const CommonVariantField<OtherLibObjT>& val) noexcept
+    CommonVariantField<LibObjT>& operator=(const CommonVariantField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
@@ -1233,137 +1523,157 @@ public:
     ConstVariantFieldClass cls() const noexcept
     {
         return ConstVariantFieldClass {
-            internal::CommonFieldSpec<const bt_field>::cls(this->_libObjPtr())};
+            internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
     Class cls() noexcept
     {
-        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->_libObjPtr())};
+        return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
     void selectOption(const std::uint64_t index) noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        static_cast<void>(bt_field_variant_select_option_by_index(this->_libObjPtr(), index));
+        static_cast<void>(bt_field_variant_select_option_by_index(this->libObjPtr(), index));
     }
 
     ConstField selectedOptionField() const noexcept
     {
         return ConstField {internal::CommonVariantFieldSpec<const bt_field>::selectedOptionField(
-            this->_libObjPtr())};
+            this->libObjPtr())};
     }
 
     CommonField<LibObjT> selectedOptionField() noexcept
     {
-        return CommonField<LibObjT> {_Spec::selectedOptionField(this->_libObjPtr())};
+        return CommonField<LibObjT> {_Spec::selectedOptionField(this->libObjPtr())};
     }
 
     std::uint64_t selectedOptionIndex() const noexcept
     {
-        return bt_field_variant_get_selected_option_index(this->_libObjPtr());
+        return bt_field_variant_get_selected_option_index(this->libObjPtr());
     }
 };
 
 using VariantField = CommonVariantField<bt_field>;
 using ConstVariantField = CommonVariantField<const bt_field>;
 
+namespace internal {
+
+struct VariantFieldTypeDescr
+{
+    using Const = ConstVariantField;
+    using NonConst = VariantField;
+};
+
+template <>
+struct TypeDescr<VariantField> : public VariantFieldTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstVariantField> : public VariantFieldTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 CommonBoolField<LibObjT> CommonField<LibObjT>::asBool() const noexcept
 {
     BT_ASSERT_DBG(this->isBool());
-    return CommonBoolField<LibObjT> {this->_libObjPtr()};
+    return CommonBoolField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonBitArrayField<LibObjT> CommonField<LibObjT>::asBitArray() const noexcept
 {
     BT_ASSERT_DBG(this->isBitArray());
-    return CommonBitArrayField<LibObjT> {this->_libObjPtr()};
+    return CommonBitArrayField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonUnsignedIntegerField<LibObjT> CommonField<LibObjT>::asUnsignedInteger() const noexcept
 {
     BT_ASSERT_DBG(this->isUnsignedInteger());
-    return CommonUnsignedIntegerField<LibObjT> {this->_libObjPtr()};
+    return CommonUnsignedIntegerField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSignedIntegerField<LibObjT> CommonField<LibObjT>::asSignedInteger() const noexcept
 {
     BT_ASSERT_DBG(this->isSignedInteger());
-    return CommonSignedIntegerField<LibObjT> {this->_libObjPtr()};
+    return CommonSignedIntegerField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonUnsignedEnumerationField<LibObjT> CommonField<LibObjT>::asUnsignedEnumeration() const noexcept
 {
     BT_ASSERT_DBG(this->isUnsignedEnumeration());
-    return CommonUnsignedEnumerationField<LibObjT> {this->_libObjPtr()};
+    return CommonUnsignedEnumerationField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSignedEnumerationField<LibObjT> CommonField<LibObjT>::asSignedEnumeration() const noexcept
 {
     BT_ASSERT_DBG(this->isSignedEnumeration());
-    return CommonSignedEnumerationField<LibObjT> {this->_libObjPtr()};
+    return CommonSignedEnumerationField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSinglePrecisionRealField<LibObjT> CommonField<LibObjT>::asSinglePrecisionReal() const noexcept
 {
     BT_ASSERT_DBG(this->isSinglePrecisionReal());
-    return CommonSinglePrecisionRealField<LibObjT> {this->_libObjPtr()};
+    return CommonSinglePrecisionRealField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDoublePrecisionRealField<LibObjT> CommonField<LibObjT>::asDoublePrecisionReal() const noexcept
 {
     BT_ASSERT_DBG(this->isDoublePrecisionReal());
-    return CommonDoublePrecisionRealField<LibObjT> {this->_libObjPtr()};
+    return CommonDoublePrecisionRealField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStringField<LibObjT> CommonField<LibObjT>::asString() const noexcept
 {
     BT_ASSERT_DBG(this->isString());
-    return CommonStringField<LibObjT> {this->_libObjPtr()};
+    return CommonStringField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStructureField<LibObjT> CommonField<LibObjT>::asStructure() const noexcept
 {
     BT_ASSERT_DBG(this->isStructure());
-    return CommonStructureField<LibObjT> {this->_libObjPtr()};
+    return CommonStructureField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonArrayField<LibObjT> CommonField<LibObjT>::asArray() const noexcept
 {
     BT_ASSERT_DBG(this->isArray());
-    return CommonArrayField<LibObjT> {this->_libObjPtr()};
+    return CommonArrayField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDynamicArrayField<LibObjT> CommonField<LibObjT>::asDynamicArray() const noexcept
 {
     BT_ASSERT_DBG(this->isDynamicArray());
-    return CommonDynamicArrayField<LibObjT> {this->_libObjPtr()};
+    return CommonDynamicArrayField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonOptionField<LibObjT> CommonField<LibObjT>::asOption() const noexcept
 {
     BT_ASSERT_DBG(this->isOption());
-    return CommonOptionField<LibObjT> {this->_libObjPtr()};
+    return CommonOptionField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonVariantField<LibObjT> CommonField<LibObjT>::asVariant() const noexcept
 {
     BT_ASSERT_DBG(this->isVariant());
-    return CommonVariantField<LibObjT> {this->_libObjPtr()};
+    return CommonVariantField<LibObjT> {this->libObjPtr()};
 }
 
 } /* namespace bt2 */
This page took 0.047901 seconds and 4 git commands to generate.