cpp-common/bt2: make `bt2::BorrowedObject::LibObj` public
[babeltrace.git] / src / cpp-common / bt2 / integer-range-set.hpp
index ad2baa1e7923a79eef33938986ff50d630ccf71e..403b7fe7ee87248148507a2a26d9e2eab8f3272c 100644 (file)
@@ -9,16 +9,17 @@
 
 #include <cstdint>
 #include <type_traits>
+
 #include <babeltrace2/babeltrace.h>
 
-#include "common-iter.hpp"
-#include "internal/borrowed-obj.hpp"
-#include "internal/utils.hpp"
-#include "integer-range.hpp"
+#include "borrowed-object-iterator.hpp"
+#include "borrowed-object.hpp"
 #include "exc.hpp"
+#include "integer-range.hpp"
+#include "internal/utils.hpp"
+#include "shared-object.hpp"
 
 namespace bt2 {
-
 namespace internal {
 
 template <typename LibObjT>
@@ -27,12 +28,12 @@ struct IntegerRangeSetRefFuncs;
 template <>
 struct IntegerRangeSetRefFuncs<const bt_integer_range_set_unsigned> final
 {
-    static void get(const bt_integer_range_set_unsigned * const libObjPtr)
+    static void get(const bt_integer_range_set_unsigned * const libObjPtr) noexcept
     {
         bt_integer_range_set_unsigned_get_ref(libObjPtr);
     }
 
-    static void put(const bt_integer_range_set_unsigned * const libObjPtr)
+    static void put(const bt_integer_range_set_unsigned * const libObjPtr) noexcept
     {
         bt_integer_range_set_unsigned_put_ref(libObjPtr);
     }
@@ -41,12 +42,12 @@ struct IntegerRangeSetRefFuncs<const bt_integer_range_set_unsigned> final
 template <>
 struct IntegerRangeSetRefFuncs<const bt_integer_range_set_signed> final
 {
-    static void get(const bt_integer_range_set_signed * const libObjPtr)
+    static void get(const bt_integer_range_set_signed * const libObjPtr) noexcept
     {
         bt_integer_range_set_signed_get_ref(libObjPtr);
     }
 
-    static void put(const bt_integer_range_set_signed * const libObjPtr)
+    static void put(const bt_integer_range_set_signed * const libObjPtr) noexcept
     {
         bt_integer_range_set_signed_put_ref(libObjPtr);
     }
@@ -59,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));
@@ -96,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 +132,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 internal::BorrowedObj<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 internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
     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 = internal::SharedObj<_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 :
-        _ThisBorrowedObj {libObjPtr}
+    explicit CommonIntegerRangeSet(const LibObjPtr libObjPtr) noexcept :
+        _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -195,18 +167,22 @@ public:
 
     template <typename OtherLibObjT>
     CommonIntegerRangeSet(const CommonIntegerRangeSet<OtherLibObjT> rangeSet) noexcept :
-        _ThisBorrowedObj {rangeSet}
+        _ThisBorrowedObject {rangeSet}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonIntegerRangeSet&
-    operator=(const CommonIntegerRangeSet<OtherLibObjT> rangeSet) noexcept
+    CommonIntegerRangeSet operator=(const CommonIntegerRangeSet<OtherLibObjT> rangeSet) noexcept
     {
-        _ThisBorrowedObj::operator=(rangeSet);
+        _ThisBorrowedObject::operator=(rangeSet);
         return *this;
     }
 
+    _ConstLibObjT asConst() const noexcept
+    {
+        return _ConstLibObjT {*this};
+    }
+
     template <typename OtherLibObjT>
     bool operator==(const CommonIntegerRangeSet<OtherLibObjT> other) const noexcept
     {
@@ -219,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);
 
@@ -230,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
@@ -247,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.027579 seconds and 4 git commands to generate.