#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 {
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);
}
};
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
{
}
};
-// Functions specific to signed integer range sets
+/* Functions specific to signed integer range sets */
template <>
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()`
+ /* Allow appendOption() to call `ranges.libObjPtr()` */
friend class CommonVariantWithIntegerSelectorFieldClass<
bt_field_class,
ConstVariantWithIntegerSelectorFieldClassOption<
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;
ConstUnsignedIntegerRange, ConstSignedIntegerRange>::type;
using Value = typename Range::Value;
+ using Iterator = CommonIterator<CommonIntegerRangeSet, Range>;
explicit CommonIntegerRangeSet(const _LibObjPtr libObjPtr) noexcept :
_ThisBorrowedObj {libObjPtr}
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);
}
{
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);
}
};
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 */