From facfc96a839627fc82fccd1d5cdf5c998669dd41 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 31 May 2024 09:54:21 -0400 Subject: [PATCH] cpp-common/bt2: add plugin accessors to `bt2::ConstPluginSet` Add the functionality to index and iterate a plugin set to get plugins. Change-Id: Ibfece01a234813a7571f26fd6b00cc4e319689a5 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12827 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/cpp-common/bt2/plugin-set.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/cpp-common/bt2/plugin-set.hpp b/src/cpp-common/bt2/plugin-set.hpp index 57ce92e5..8291d6f3 100644 --- a/src/cpp-common/bt2/plugin-set.hpp +++ b/src/cpp-common/bt2/plugin-set.hpp @@ -11,6 +11,9 @@ #include +#include "cpp-common/bt2/borrowed-object-iterator.hpp" +#include "cpp-common/bt2/plugin.hpp" + #include "borrowed-object.hpp" #include "shared-object.hpp" @@ -35,6 +38,7 @@ struct PluginSetRefFuncs class ConstPluginSet final : public BorrowedObject { public: + using Iterator = BorrowedObjectIterator; using Shared = SharedObject; explicit ConstPluginSet(const bt_plugin_set * const plugin_set) : @@ -46,6 +50,21 @@ public: { return bt_plugin_set_get_plugin_count(this->libObjPtr()); } + + Iterator begin() const noexcept + { + return Iterator {*this, 0}; + } + + Iterator end() const noexcept + { + return Iterator {*this, this->length()}; + } + + OptionalBorrowedObject operator[](const std::uint64_t index) const noexcept + { + return bt_plugin_set_borrow_plugin_by_index_const(this->libObjPtr(), index); + } }; } /* namespace bt2 */ -- 2.34.1