cpp-common/bt2: `User*Component`: pass query method data to user `_query` methods
[babeltrace.git] / src / cpp-common / bt2 / integer-range-set.hpp
index f542c6a5e83593da11c8820dfe00270df9b28995..403b7fe7ee87248148507a2a26d9e2eab8f3272c 100644 (file)
@@ -12,8 +12,8 @@
 
 #include <babeltrace2/babeltrace.h>
 
+#include "borrowed-object-iterator.hpp"
 #include "borrowed-object.hpp"
-#include "common-iterator.hpp"
 #include "exc.hpp"
 #include "integer-range.hpp"
 #include "internal/utils.hpp"
@@ -60,7 +60,7 @@ struct CommonIntegerRangeSetSpec;
 template <>
 struct CommonIntegerRangeSetSpec<const bt_integer_range_set_unsigned> final
 {
-    static std::uint64_t size(const bt_integer_range_set_unsigned * const libRangePtr) noexcept
+    static std::uint64_t length(const bt_integer_range_set_unsigned * const libRangePtr) noexcept
     {
         return bt_integer_range_set_get_range_count(
             bt_integer_range_set_unsigned_as_range_set_const(libRangePtr));
@@ -97,7 +97,7 @@ struct CommonIntegerRangeSetSpec<const bt_integer_range_set_unsigned> final
 template <>
 struct CommonIntegerRangeSetSpec<const bt_integer_range_set_signed> final
 {
-    static std::uint64_t size(const bt_integer_range_set_signed * const libRangePtr) noexcept
+    static std::uint64_t length(const bt_integer_range_set_signed * const libRangePtr) noexcept
     {
         return bt_integer_range_set_get_range_count(
             bt_integer_range_set_signed_as_range_set_const(libRangePtr));
@@ -131,57 +131,28 @@ struct CommonIntegerRangeSetSpec<const bt_integer_range_set_signed> final
 
 } /* namespace internal */
 
-template <typename LibObjT>
-class ConstVariantWithIntegerSelectorFieldClassOption;
-
-template <typename LibObjT, typename RangeSetT>
-class CommonVariantWithIntegerSelectorFieldClass;
-
-template <typename LibObjT>
-class CommonTraceClass;
-
 template <typename LibObjT>
 class CommonIntegerRangeSet final : public BorrowedObject<LibObjT>
 {
-    /* Allow operator==() to call `other.libObjPtr()` */
-    friend class CommonIntegerRangeSet<bt_integer_range_set_unsigned>;
-    friend class CommonIntegerRangeSet<const bt_integer_range_set_unsigned>;
-    friend class CommonIntegerRangeSet<bt_integer_range_set_signed>;
-    friend class CommonIntegerRangeSet<const bt_integer_range_set_signed>;
-
-    /* Allow appendOption() to call `ranges.libObjPtr()` */
-    friend class CommonVariantWithIntegerSelectorFieldClass<
-        bt_field_class,
-        ConstVariantWithIntegerSelectorFieldClassOption<
-            const bt_field_class_variant_with_selector_field_integer_unsigned_option>>;
-
-    friend class CommonVariantWithIntegerSelectorFieldClass<
-        bt_field_class,
-        ConstVariantWithIntegerSelectorFieldClassOption<
-            const bt_field_class_variant_with_selector_field_integer_signed_option>>;
-
-    /* Allow create*FieldClass() to call `ranges.libObjPtr()` */
-    friend class CommonTraceClass<bt_trace_class>;
-
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstLibObjT = typename std::add_const<LibObjT>::type;
-    using _RefFuncs = internal::IntegerRangeSetRefFuncs<_ConstLibObjT>;
     using _Spec = internal::CommonIntegerRangeSetSpec<_ConstLibObjT>;
-    using _ThisCommonIntegerRangeSet = CommonIntegerRangeSet<LibObjT>;
 
 public:
-    using Shared = SharedObject<_ThisCommonIntegerRangeSet, LibObjT, _RefFuncs>;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+
+    using Shared = SharedObject<CommonIntegerRangeSet, LibObjT,
+                                internal::IntegerRangeSetRefFuncs<_ConstLibObjT>>;
 
     using Range = typename std::conditional<
         std::is_same<_ConstLibObjT, const bt_integer_range_set_unsigned>::value,
         ConstUnsignedIntegerRange, ConstSignedIntegerRange>::type;
 
     using Value = typename Range::Value;
-    using Iterator = CommonIterator<CommonIntegerRangeSet, Range>;
+    using Iterator = BorrowedObjectIterator<CommonIntegerRangeSet>;
 
-    explicit CommonIntegerRangeSet(const _LibObjPtr libObjPtr) noexcept :
+    explicit CommonIntegerRangeSet(const LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObject {libObjPtr}
     {
     }
@@ -201,13 +172,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonIntegerRangeSet&
-    operator=(const CommonIntegerRangeSet<OtherLibObjT> rangeSet) noexcept
+    CommonIntegerRangeSet operator=(const CommonIntegerRangeSet<OtherLibObjT> rangeSet) noexcept
     {
         _ThisBorrowedObject::operator=(rangeSet);
         return *this;
     }
 
+    _ConstLibObjT asConst() const noexcept
+    {
+        return _ConstLibObjT {*this};
+    }
+
     template <typename OtherLibObjT>
     bool operator==(const CommonIntegerRangeSet<OtherLibObjT> other) const noexcept
     {
@@ -220,9 +195,11 @@ public:
         return !(*this == other);
     }
 
-    void addRange(const Value lower, const Value upper)
+    void addRange(const Value lower, const Value upper) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(
+            !std::is_const<LibObjT>::value,
+            "Not available with `bt2::ConstUnsignedIntegerRangeSet` or `bt2::ConstSignedIntegerRangeSet`.");
 
         const auto status = _Spec::addRange(this->libObjPtr(), lower, upper);
 
@@ -231,9 +208,9 @@ public:
         }
     }
 
-    std::uint64_t size() const noexcept
+    std::uint64_t length() const noexcept
     {
-        return _Spec::size(this->libObjPtr());
+        return _Spec::length(this->libObjPtr());
     }
 
     Range operator[](const std::uint64_t index) const noexcept
@@ -248,7 +225,7 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
     Shared shared() const noexcept
This page took 0.024755 seconds and 4 git commands to generate.