Add bt2::CommonEnumerationFieldClass::addMapping() methods
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 9 May 2022 19:34:33 +0000 (15:34 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
They make it possible to add mappings to an enumeration field class.

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

index 8513c7952346f7a8e29b17541a0fcd1bbe39e8c6..4dbdee6057120b05d40d90d9b349799f7186ff6c 100644 (file)
@@ -677,6 +677,13 @@ struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping
     {
         return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label);
     }
+
+    static bt_field_class_enumeration_add_mapping_status
+    addMapping(bt_field_class * const libObjPtr, const char * const label,
+               const bt_integer_range_set_unsigned * const libRanges) noexcept
+    {
+        return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges);
+    }
 };
 
 /* Functions specific to signed enumeration field classes */
@@ -694,6 +701,13 @@ struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping>
     {
         return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label);
     }
+
+    static bt_field_class_enumeration_add_mapping_status
+    addMapping(bt_field_class * const libObjPtr, const char * const label,
+               const bt_integer_range_set_signed * const libRanges) noexcept
+    {
+        return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges);
+    }
 };
 
 } /* namespace internal */
@@ -799,6 +813,21 @@ public:
         return (*this)[label.data()];
     }
 
+    void addMapping(const char * const label, const typename Mapping::RangeSet ranges)
+    {
+        const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
+            this->libObjPtr(), label, ranges.libObjPtr());
+
+        if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
+            throw LibMemoryError {};
+        }
+    }
+
+    void addMapping(const std::string& label, const typename Mapping::RangeSet ranges)
+    {
+        this->addMapping(label.data(), ranges);
+    }
+
     Shared shared() const noexcept
     {
         return Shared {*this};
This page took 0.037203 seconds and 4 git commands to generate.