cpp-common/bt2: field.hpp: Add assignment operator for Enum field
[babeltrace.git] / src / cpp-common / bt2 / field.hpp
index 126f8aa87aabd1eb5a8482c083bcf7f7f51871e2..4b3853826b2871478eb9f634d9cc39dfd73d8b76 100644 (file)
@@ -108,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;
@@ -265,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;
@@ -335,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;
@@ -402,7 +402,7 @@ 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;
@@ -424,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;
@@ -491,7 +491,7 @@ struct TypeDescr<ConstUnsignedIntegerField> : public UnsignedIntegerFieldTypeDes
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonSignedIntegerField final : public CommonField<LibObjT>
+class CommonSignedIntegerField : public CommonField<LibObjT>
 {
 private:
     using typename CommonField<LibObjT>::_ThisCommonField;
@@ -501,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;
@@ -513,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;
@@ -629,7 +629,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonUnsignedEnumerationField(const CommonUnsignedEnumerationField<OtherLibObjT>& val) noexcept
+    CommonUnsignedEnumerationField(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept
         :
         _ThisCommonUnsignedIntegerField {val}
     {
@@ -637,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;
@@ -649,6 +649,8 @@ public:
             internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
     }
 
+    using CommonUnsignedIntegerField<LibObjT>::operator=;
+
     Class cls() noexcept
     {
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
@@ -711,19 +713,21 @@ 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 {
@@ -790,7 +794,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonSinglePrecisionRealField(const CommonSinglePrecisionRealField<OtherLibObjT>& val) noexcept
+    CommonSinglePrecisionRealField(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
         :
         _ThisCommonField {val}
     {
@@ -798,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;
@@ -863,7 +867,7 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonDoublePrecisionRealField(const CommonDoublePrecisionRealField<OtherLibObjT>& val) noexcept
+    CommonDoublePrecisionRealField(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
         :
         _ThisCommonField {val}
     {
@@ -871,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;
@@ -881,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
@@ -933,18 +937,18 @@ 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`.");
 
@@ -957,11 +961,27 @@ public:
         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`.");
@@ -1053,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;
@@ -1196,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;
@@ -1273,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;
@@ -1367,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;
@@ -1489,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;
This page took 0.028568 seconds and 4 git commands to generate.