#include <babeltrace2/babeltrace.h>
+#include "borrowed-object-iterator.hpp"
#include "borrowed-object.hpp"
-#include "common-iter.hpp"
#include "exc.hpp"
#include "integer-range.hpp"
#include "internal/utils.hpp"
+#include "shared-object.hpp"
namespace bt2 {
-
namespace internal {
template <typename LibObjT>
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);
}
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);
}
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));
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));
} /* 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 = 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 :
+ explicit CommonIntegerRangeSet(const LibObjPtr libObjPtr) noexcept :
_ThisBorrowedObject {libObjPtr}
{
}
}
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
{
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);
}
}
- 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
Iterator end() const noexcept
{
- return Iterator {*this, this->size()};
+ return Iterator {*this, this->length()};
}
Shared shared() const noexcept