cpp-common/bt2: add plugin accessors to `bt2::ConstPluginSet`
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 31 May 2024 13:54:21 +0000 (09:54 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Add the functionality to index and iterate a plugin set to get
plugins.

Change-Id: Ibfece01a234813a7571f26fd6b00cc4e319689a5
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12827
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2/plugin-set.hpp

index 57ce92e51c7e4100f97ab4a81f0cf7ac145fa005..8291d6f3269eba7b7632765c451d6c30cdb2a0b0 100644 (file)
@@ -11,6 +11,9 @@
 
 #include <babeltrace2/babeltrace.h>
 
+#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<const bt_plugin_set>
 {
 public:
+    using Iterator = BorrowedObjectIterator<ConstPluginSet>;
     using Shared = SharedObject<ConstPluginSet, const bt_plugin_set, internal::PluginSetRefFuncs>;
 
     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<ConstPlugin> operator[](const std::uint64_t index) const noexcept
+    {
+        return bt_plugin_set_borrow_plugin_by_index_const(this->libObjPtr(), index);
+    }
 };
 
 } /* namespace bt2 */
This page took 0.024884 seconds and 4 git commands to generate.