cpp-common: add `begin()` and `end()` to Variant and Struct FC
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 10 Feb 2022 22:06:27 +0000 (17:06 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ic78e9a06ec86b3a1749c1763698408964f34ec27
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7323
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7290
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/field-class.hpp

index 46f3a7cf627f0d975b78bdefc5665ba378f0c995..677f7fb466ab8209a947519a68ccfd894070ed69 100644 (file)
@@ -16,6 +16,7 @@
 #include "internal/shared-obj.hpp"
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
+#include "common-iter.hpp"
 #include "lib-error.hpp"
 #include "integer-range-set.hpp"
 #include "field-path.hpp"
@@ -904,11 +905,12 @@ private:
 
 public:
     using Shared = internal::SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
-
     using Member =
         typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember,
                                   StructureFieldClassMember>::type;
 
+    using Iterator = CommonIterator<CommonStructureFieldClass<LibObjT>, Member>;
+
     explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
@@ -951,6 +953,16 @@ public:
         return bt_field_class_structure_get_member_count(this->_libObjPtr());
     }
 
+    Iterator begin() const noexcept
+    {
+        return Iterator {*this, 0};
+    }
+
+    Iterator end() const noexcept
+    {
+        return Iterator {*this, this->size()};
+    }
+
     ConstStructureFieldClassMember operator[](const std::uint64_t index) const noexcept
     {
         return ConstStructureFieldClassMember {
@@ -1723,6 +1735,8 @@ public:
         typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption,
                                   VariantFieldClassOption>::type;
 
+    using Iterator = CommonIterator<CommonVariantFieldClass<LibObjT>, Option>;
+
     explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
     {
@@ -1748,6 +1762,16 @@ public:
         return bt_field_class_variant_get_option_count(this->_libObjPtr());
     }
 
+    Iterator begin() const noexcept
+    {
+        return Iterator {*this, 0};
+    }
+
+    Iterator end() const noexcept
+    {
+        return Iterator {*this, this->size()};
+    }
+
     ConstVariantFieldClassOption operator[](const std::uint64_t index) const noexcept
     {
         return ConstVariantFieldClassOption {
This page took 0.027375 seconds and 4 git commands to generate.