Sort includes in C++ files
[babeltrace.git] / src / cpp-common / bt2 / integer-range-set.hpp
index 52fc540dcbb10c5b2f26bf8f4c29c4e2603dd638..a86bcaf9dc872b307bd79803619587bcbfe038ec 100644 (file)
@@ -9,12 +9,14 @@
 
 #include <cstdint>
 #include <type_traits>
+
 #include <babeltrace2/babeltrace.h>
 
+#include "common-iter.hpp"
+#include "exc.hpp"
+#include "integer-range.hpp"
 #include "internal/borrowed-obj.hpp"
 #include "internal/utils.hpp"
-#include "integer-range.hpp"
-#include "lib-error.hpp"
 
 namespace bt2 {
 
@@ -33,7 +35,7 @@ struct IntegerRangeSetRefFuncs<const bt_integer_range_set_unsigned> final
 
     static void put(const bt_integer_range_set_unsigned * const libObjPtr)
     {
-        bt_integer_range_set_unsigned_get_ref(libObjPtr);
+        bt_integer_range_set_unsigned_put_ref(libObjPtr);
     }
 };
 
@@ -47,14 +49,14 @@ struct IntegerRangeSetRefFuncs<const bt_integer_range_set_signed> final
 
     static void put(const bt_integer_range_set_signed * const libObjPtr)
     {
-        bt_integer_range_set_signed_get_ref(libObjPtr);
+        bt_integer_range_set_signed_put_ref(libObjPtr);
     }
 };
 
 template <typename LibObjT>
 struct CommonIntegerRangeSetSpec;
 
-// Functions specific to unsigned integer range sets
+/* Functions specific to unsigned integer range sets */
 template <>
 struct CommonIntegerRangeSetSpec<const bt_integer_range_set_unsigned> final
 {
@@ -91,7 +93,7 @@ struct CommonIntegerRangeSetSpec<const bt_integer_range_set_unsigned> final
     }
 };
 
-// Functions specific to signed integer range sets
+/* Functions specific to signed integer range sets */
 template <>
 struct CommonIntegerRangeSetSpec<const bt_integer_range_set_signed> final
 {
@@ -127,17 +129,40 @@ struct CommonIntegerRangeSetSpec<const bt_integer_range_set_signed> final
     }
 };
 
-} // namespace internal
+} /* 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>
 {
-    // Allow operator==() to call `other._libObjPtr()`
+    /* 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;
@@ -154,6 +179,7 @@ public:
         ConstUnsignedIntegerRange, ConstSignedIntegerRange>::type;
 
     using Value = typename Range::Value;
+    using Iterator = CommonIterator<CommonIntegerRangeSet, Range>;
 
     explicit CommonIntegerRangeSet(const _LibObjPtr libObjPtr) noexcept :
         _ThisBorrowedObj {libObjPtr}
@@ -165,31 +191,31 @@ public:
         const auto libObjPtr = _Spec::create();
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return Shared {_ThisCommonIntegerRangeSet {libObjPtr}};
+        return CommonIntegerRangeSet::Shared::createWithoutRef(libObjPtr);
     }
 
     template <typename OtherLibObjT>
-    CommonIntegerRangeSet(const CommonIntegerRangeSet<OtherLibObjT>& rangeSet) noexcept :
+    CommonIntegerRangeSet(const CommonIntegerRangeSet<OtherLibObjT> rangeSet) noexcept :
         _ThisBorrowedObj {rangeSet}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonIntegerRangeSet&
-    operator=(const CommonIntegerRangeSet<OtherLibObjT>& rangeSet) noexcept
+    operator=(const CommonIntegerRangeSet<OtherLibObjT> rangeSet) noexcept
     {
         _ThisBorrowedObj::operator=(rangeSet);
         return *this;
     }
 
     template <typename OtherLibObjT>
-    bool operator==(const CommonIntegerRangeSet<OtherLibObjT>& other) const noexcept
+    bool operator==(const CommonIntegerRangeSet<OtherLibObjT> other) const noexcept
     {
-        return _Spec::isEqual(this->_libObjPtr(), other._libObjPtr());
+        return _Spec::isEqual(this->libObjPtr(), other.libObjPtr());
     }
 
     template <typename OtherLibObjT>
-    bool operator!=(const CommonIntegerRangeSet<OtherLibObjT>& other) const noexcept
+    bool operator!=(const CommonIntegerRangeSet<OtherLibObjT> other) const noexcept
     {
         return !(*this == other);
     }
@@ -198,26 +224,36 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = _Spec::addRange(this->_libObjPtr(), lower, upper);
+        const auto status = _Spec::addRange(this->libObjPtr(), lower, upper);
 
         if (status == BT_INTEGER_RANGE_SET_ADD_RANGE_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
     std::uint64_t size() const noexcept
     {
-        return _Spec::size(this->_libObjPtr());
+        return _Spec::size(this->libObjPtr());
     }
 
     Range operator[](const std::uint64_t index) const noexcept
     {
-        return Range {_Spec::rangeByIndex(this->_libObjPtr(), index)};
+        return Range {_Spec::rangeByIndex(this->libObjPtr(), index)};
+    }
+
+    Iterator begin() const noexcept
+    {
+        return Iterator {*this, 0};
+    }
+
+    Iterator end() const noexcept
+    {
+        return Iterator {*this, this->size()};
     }
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 };
 
@@ -226,6 +262,41 @@ using ConstUnsignedIntegerRangeSet = CommonIntegerRangeSet<const bt_integer_rang
 using SignedIntegerRangeSet = CommonIntegerRangeSet<bt_integer_range_set_signed>;
 using ConstSignedIntegerRangeSet = CommonIntegerRangeSet<const bt_integer_range_set_signed>;
 
-} // namespace bt2
+namespace internal {
+
+struct UnsignedIntegerRangeSetTypeDescr
+{
+    using Const = ConstUnsignedIntegerRangeSet;
+    using NonConst = UnsignedIntegerRangeSet;
+};
+
+template <>
+struct TypeDescr<UnsignedIntegerRangeSet> : public UnsignedIntegerRangeSetTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstUnsignedIntegerRangeSet> : public UnsignedIntegerRangeSetTypeDescr
+{
+};
+
+struct SignedIntegerRangeSetTypeDescr
+{
+    using Const = ConstSignedIntegerRangeSet;
+    using NonConst = SignedIntegerRangeSet;
+};
+
+template <>
+struct TypeDescr<SignedIntegerRangeSet> : public SignedIntegerRangeSetTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstSignedIntegerRangeSet> : public SignedIntegerRangeSetTypeDescr
+{
+};
+
+} /* namespace internal */
+} /* namespace bt2 */
 
-#endif // BABELTRACE_CPP_COMMON_BT2_INTEGER_RANGE_SET_HPP
+#endif /* BABELTRACE_CPP_COMMON_BT2_INTEGER_RANGE_SET_HPP */
This page took 0.026404 seconds and 4 git commands to generate.