From: Francis Deslauriers Date: Thu, 10 Feb 2022 22:06:27 +0000 (-0500) Subject: cpp-common: add `begin()` and `end()` to Variant and Struct FC X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=5046c776430ff9f1c0580bad8cd36511fae636f8 cpp-common: add `begin()` and `end()` to Variant and Struct FC Signed-off-by: Francis Deslauriers Change-Id: Ic78e9a06ec86b3a1749c1763698408964f34ec27 Reviewed-on: https://review.lttng.org/c/babeltrace/+/7323 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/7290 CI-Build: Philippe Proulx Tested-by: jenkins --- diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index 46f3a7cf..677f7fb4 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -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, LibObjT>; - using Member = typename std::conditional::value, ConstStructureFieldClassMember, StructureFieldClassMember>::type; + using Iterator = CommonIterator, 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::value, ConstVariantFieldClassOption, VariantFieldClassOption>::type; + using Iterator = CommonIterator, 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 {