field-class.hpp: add missing support for user attributes
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 20 May 2022 13:11:40 +0000 (09:11 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
This patch adds the missing
bt2::CommonStructureFieldClassMember::userAttributes() and
bt2::CommonVariantFieldClassOption::userAttributes() methods to set and
borrow user attributes of structure field member classes and variant
field class options.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I023e835531753eb928ea5db41b5f429750139af7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8100
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10804
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/field-class.hpp

index b630224f929fda5b0a851065bebd0c5981b26103..6460000ffe11c0dcda83fb0086777a63ee9edda8 100644 (file)
@@ -971,6 +971,11 @@ struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> fina
     {
         return bt_field_class_structure_member_borrow_field_class(libObjPtr);
     }
+
+    static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept
+    {
+        return bt_field_class_structure_member_borrow_user_attributes(libObjPtr);
+    }
 };
 
 /* Functions specific to constant structure field class members */
@@ -982,6 +987,12 @@ struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member
     {
         return bt_field_class_structure_member_borrow_field_class_const(libObjPtr);
     }
+
+    static const bt_value *
+    userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept
+    {
+        return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr);
+    }
 };
 
 } /* namespace internal */
@@ -997,6 +1008,9 @@ private:
         typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
 
 public:
+    using UserAttributes =
+        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
+
     explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObj {libObjPtr}
     {
@@ -1033,6 +1047,28 @@ public:
         return _FieldClass {
             internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())};
     }
+
+    template <typename LibValT>
+    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    {
+        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+
+        bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
+                                                            userAttrs.libObjPtr());
+    }
+
+    ConstMapValue userAttributes() const noexcept
+    {
+        return ConstMapValue {internal::CommonStructureFieldClassMemberSpec<
+            const bt_field_class_structure_member>::userAttributes(this->libObjPtr())};
+    }
+
+    UserAttributes userAttributes() noexcept
+    {
+        return UserAttributes {
+            internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes(
+                this->libObjPtr())};
+    }
 };
 
 using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>;
@@ -1860,6 +1896,11 @@ struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final
     {
         return bt_field_class_variant_option_borrow_field_class(libObjPtr);
     }
+
+    static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept
+    {
+        return bt_field_class_variant_option_borrow_user_attributes(libObjPtr);
+    }
 };
 
 /* Functions specific to constant variant field class options */
@@ -1871,6 +1912,12 @@ struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> fi
     {
         return bt_field_class_variant_option_borrow_field_class_const(libObjPtr);
     }
+
+    static const bt_value *
+    userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept
+    {
+        return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr);
+    }
 };
 
 } /* namespace internal */
@@ -1886,6 +1933,9 @@ private:
         typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
 
 public:
+    using UserAttributes =
+        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
+
     explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObj {libObjPtr}
     {
@@ -1927,6 +1977,26 @@ public:
         return _FieldClass {
             internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())};
     }
+
+    template <typename LibValT>
+    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    {
+        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+
+        bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+    }
+
+    ConstMapValue userAttributes() const noexcept
+    {
+        return ConstMapValue {internal::CommonVariantFieldClassOptionSpec<
+            const bt_field_class_variant_option>::userAttributes(this->libObjPtr())};
+    }
+
+    UserAttributes userAttributes() noexcept
+    {
+        return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes(
+            this->libObjPtr())};
+    }
 };
 
 using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>;
This page took 0.026749 seconds and 4 git commands to generate.