#ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
#define BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
-#include <type_traits>
#include <cstdint>
+#include <type_traits>
+
#include <babeltrace2/babeltrace.h>
#include "common/assert.h"
-#include "internal/borrowed-obj.hpp"
-#include "internal/shared-obj.hpp"
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
-#include "lib-error.hpp"
-#include "integer-range-set.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
+
+#include "borrowed-object-iterator.hpp"
+#include "borrowed-object.hpp"
+#include "exc.hpp"
#include "field-path.hpp"
+#include "integer-range-set.hpp"
+#include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
+#include "shared-object.hpp"
+#include "value.hpp"
namespace bt2 {
-
namespace internal {
struct FieldClassRefFuncs final
{
- static void get(const bt_field_class * const libObjPtr)
+ static void get(const bt_field_class * const libObjPtr) noexcept
{
bt_field_class_get_ref(libObjPtr);
}
- static void put(const bt_field_class * const libObjPtr)
+ static void put(const bt_field_class * const libObjPtr) noexcept
{
bt_field_class_put_ref(libObjPtr);
}
};
-template <typename ObjT, typename LibObjT>
-using SharedFieldClass = internal::SharedObj<ObjT, LibObjT, internal::FieldClassRefFuncs>;
-
template <typename LibObjT>
struct CommonFieldClassSpec;
} /* namespace internal */
+template <typename ObjT, typename LibObjT>
+using SharedFieldClass = SharedObject<ObjT, LibObjT, internal::FieldClassRefFuncs>;
+
template <typename LibObjT>
class CommonBitArrayFieldClass;
template <typename LibObjT>
class ConstEnumerationFieldClassMapping;
+template <typename LibObjT>
+class CommonBaseEnumerationFieldClass;
+
template <typename LibObjT, typename MappingT>
class CommonEnumerationFieldClass;
template <typename LibObjT>
class CommonVariantWithoutSelectorFieldClass;
+template <typename LibObjT>
+class CommonVariantWithSelectorFieldClass;
+
template <typename LibObjT>
class ConstVariantWithIntegerSelectorFieldClassOption;
enum class FieldClassType
{
- BOOL = BT_FIELD_CLASS_TYPE_BOOL,
- BIT_ARRAY = BT_FIELD_CLASS_TYPE_BIT_ARRAY,
- UNSIGNED_INTEGER = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER,
- SIGNED_INTEGER = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER,
- UNSIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION,
- SIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION,
- SINGLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL,
- DOUBLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL,
- STRING = BT_FIELD_CLASS_TYPE_STRING,
- STRUCTURE = BT_FIELD_CLASS_TYPE_STRUCTURE,
- STATIC_ARRAY = BT_FIELD_CLASS_TYPE_STATIC_ARRAY,
- DYNAMIC_ARRAY_WITHOUT_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD,
- DYNAMIC_ARRAY_WITH_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD,
- OPTION_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD,
- OPTION_WITH_BOOL_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD,
- OPTION_WITH_UNSIGNED_INTEGER_SELECTOR =
+ Bool = BT_FIELD_CLASS_TYPE_BOOL,
+ BitArray = BT_FIELD_CLASS_TYPE_BIT_ARRAY,
+ UnsignedInteger = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER,
+ SignedInteger = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER,
+ UnsignedEnumeration = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION,
+ SignedEnumeration = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION,
+ SinglePrecisionReal = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL,
+ DoublePrecisionReal = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL,
+ String = BT_FIELD_CLASS_TYPE_STRING,
+ Structure = BT_FIELD_CLASS_TYPE_STRUCTURE,
+ StaticArray = BT_FIELD_CLASS_TYPE_STATIC_ARRAY,
+ DynamicArrayWithoutLength = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD,
+ DynamicArrayWithLength = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD,
+ OptionWithoutSelector = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD,
+ OptionWithBoolSelector = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD,
+ OptionWithUnsignedIntegerSelector =
BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
- OPTION_WITH_SIGNED_INTEGER_SELECTOR =
- BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
- VARIANT_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD,
- VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR =
+ OptionWithSignedIntegerSelector = BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
+ VariantWithoutSelector = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD,
+ VariantWithUnsignedIntegerSelector =
BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
- VARIANT_WITH_SIGNED_INTEGER_SELECTOR =
+ VariantWithSignedIntegerSelector =
BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
};
template <typename LibObjT>
-class CommonFieldClass : public internal::BorrowedObj<LibObjT>
+class CommonFieldClass : public BorrowedObject<LibObjT>
{
- /* Allow appendMember() to call `fc._libObjPtr()` */
- friend class CommonStructureFieldClass<bt_field_class>;
-
- /* Allow appendOption() to call `fc._libObjPtr()` */
- friend class CommonVariantWithoutSelectorFieldClass<bt_field_class>;
-
- 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 *FieldClass() to call `fc._libObjPtr()` */
- friend class CommonEventClass<bt_event_class>;
- friend class CommonStreamClass<bt_stream_class>;
-
- /* Allow create*FieldClass() to call `fc._libObjPtr()` */
- friend class CommonTraceClass<bt_trace_class>;
-
private:
- using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
+ using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
protected:
- using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
-
- using UserAttributes =
- typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
+ using UserAttributes = internal::DepUserAttrs<LibObjT>;
- explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+ explicit CommonFieldClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
{
}
template <typename OtherLibObjT>
- CommonFieldClass(const CommonFieldClass<OtherLibObjT>& fc) noexcept : _ThisBorrowedObj {fc}
+ CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObject {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonFieldClass& operator=(const CommonFieldClass<OtherLibObjT>& fc) noexcept
+ CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
{
- _ThisBorrowedObj::operator=(fc);
+ _ThisBorrowedObject::operator=(fc);
return *this;
}
+ CommonFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonFieldClass<const bt_field_class> {*this};
+ }
+
FieldClassType type() const noexcept
{
- return static_cast<FieldClassType>(bt_field_class_get_type(this->_libObjPtr()));
+ return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr()));
}
bool isBool() const noexcept
return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
}
+ bool isReal() const noexcept
+ {
+ return this->_libTypeIs(BT_FIELD_CLASS_TYPE_REAL);
+ }
+
bool isSinglePrecisionReal() const noexcept
{
return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
}
+ template <typename FieldClassT>
+ FieldClassT as() const noexcept
+ {
+ return FieldClassT {this->libObjPtr()};
+ }
+
CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept;
CommonIntegerFieldClass<LibObjT> asInteger() const noexcept;
-
+ CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept;
CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping<
const bt_field_class_enumeration_unsigned_mapping>>
asUnsignedEnumeration() const noexcept;
CommonVariantFieldClass<LibObjT> asVariant() const noexcept;
CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept;
+ CommonVariantWithSelectorFieldClass<LibObjT> asVariantWithSelector() const noexcept;
CommonVariantWithIntegerSelectorFieldClass<
LibObjT, ConstVariantWithIntegerSelectorFieldClassOption<
asVariantWithSignedIntegerSelector() const noexcept;
template <typename LibValT>
- void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+ CommonFieldClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
{
- static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+ static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstFieldClass`.");
- bt_field_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
- }
-
- ConstMapValue userAttributes() const noexcept
- {
- return ConstMapValue {internal::CommonFieldClassSpec<const bt_field_class>::userAttributes(
- this->_libObjPtr())};
+ bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+ return *this;
}
- UserAttributes userAttributes() noexcept
+ UserAttributes userAttributes() const noexcept
{
return UserAttributes {
- internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->_libObjPtr())};
+ internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
protected:
bool _libTypeIs(const bt_field_class_type type) const noexcept
{
- return bt_field_class_type_is(bt_field_class_get_type(this->_libObjPtr()), type);
+ return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type);
}
};
using FieldClass = CommonFieldClass<bt_field_class>;
using ConstFieldClass = CommonFieldClass<const bt_field_class>;
+namespace internal {
+
+struct FieldClassTypeDescr
+{
+ using Const = ConstFieldClass;
+ using NonConst = FieldClass;
+};
+
+template <>
+struct TypeDescr<FieldClass> : public FieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT>
{
private:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
public:
- using Shared = internal::SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
- explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonBitArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isBitArray());
}
template <typename OtherLibObjT>
- CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT>& fc) noexcept :
+ CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonFieldClass {fc}
{
}
template <typename OtherLibObjT>
- CommonBitArrayFieldClass<LibObjT>&
- operator=(const CommonBitArrayFieldClass<OtherLibObjT>& fc) noexcept
+ CommonBitArrayFieldClass<LibObjT>
+ operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonFieldClass::operator=(fc);
return *this;
}
+ CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonBitArrayFieldClass<const bt_field_class> {*this};
+ }
+
std::uint64_t length() const noexcept
{
- return bt_field_class_bit_array_get_length(this->_libObjPtr());
+ return bt_field_class_bit_array_get_length(this->libObjPtr());
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>;
using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>;
+namespace internal {
+
+struct BitArrayFieldClassTypeDescr
+{
+ using Const = ConstBitArrayFieldClass;
+ using NonConst = BitArrayFieldClass;
+};
+
+template <>
+struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
enum class DisplayBase
{
- BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY,
- OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL,
- DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
- HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL,
+ Binary = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY,
+ Octal = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL,
+ Decimal = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
+ Hexadecimal = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL,
};
template <typename LibObjT>
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
protected:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
- explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonIntegerFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isInteger());
}
template <typename OtherLibObjT>
- CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT>& fc) noexcept :
+ CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonIntegerFieldClass&
- operator=(const CommonIntegerFieldClass<OtherLibObjT>& fc) noexcept
+ CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonFieldClass::operator=(fc);
return *this;
}
- void fieldValueRange(const std::uint64_t n) noexcept
+ CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonIntegerFieldClass<const bt_field_class> {*this};
+ }
+
+ CommonIntegerFieldClass fieldValueRange(const std::uint64_t n) const noexcept
{
- static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+ static_assert(!std::is_const<LibObjT>::value,
+ "Not available with `bt2::ConstIntegerFieldClass`.");
- bt_field_class_integer_get_field_value_range(this->_libObjPtr(), n);
+ bt_field_class_integer_set_field_value_range(this->libObjPtr(), n);
+ return *this;
}
std::uint64_t fieldValueRange() const noexcept
{
- return bt_field_class_integer_get_field_value_range(this->_libObjPtr());
+ return bt_field_class_integer_get_field_value_range(this->libObjPtr());
}
- void preferredDisplayBase(const DisplayBase base) noexcept
+ CommonIntegerFieldClass preferredDisplayBase(const DisplayBase base) const noexcept
{
- static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+ static_assert(!std::is_const<LibObjT>::value,
+ "Not available with `bt2::ConstIntegerFieldClass`.");
bt_field_class_integer_set_preferred_display_base(
- this->_libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
+ this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
+ return *this;
}
DisplayBase preferredDisplayBase() const noexcept
{
return static_cast<DisplayBase>(
- bt_field_class_integer_get_preferred_display_base(this->_libObjPtr()));
+ bt_field_class_integer_get_preferred_display_base(this->libObjPtr()));
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
namespace internal {
+struct IntegerFieldClassTypeDescr
+{
+ using Const = ConstIntegerFieldClass;
+ using NonConst = IntegerFieldClass;
+};
+
+template <>
+struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
+{
+};
+
template <typename LibObjT>
struct ConstEnumerationFieldClassMappingSpec;
} /* namespace internal */
template <typename LibObjT>
-class ConstEnumerationFieldClassMapping final : public internal::BorrowedObj<LibObjT>
+class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT>
{
private:
- using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
- using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
- using _ThisConstEnumerationFieldClassMapping = ConstEnumerationFieldClassMapping<LibObjT>;
+ using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
public:
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
+
using RangeSet = typename std::conditional<
std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value,
ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
- explicit ConstEnumerationFieldClassMapping(const _LibObjPtr libObjPtr) noexcept :
- _ThisBorrowedObj {libObjPtr}
+ explicit ConstEnumerationFieldClassMapping(const LibObjPtr libObjPtr) noexcept :
+ _ThisBorrowedObject {libObjPtr}
{
}
- ConstEnumerationFieldClassMapping(
- const _ThisConstEnumerationFieldClassMapping& mapping) noexcept :
- _ThisBorrowedObj {mapping}
+ ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept :
+ _ThisBorrowedObject {mapping}
{
}
- _ThisConstEnumerationFieldClassMapping&
- operator=(const _ThisConstEnumerationFieldClassMapping& mapping) noexcept
+ ConstEnumerationFieldClassMapping
+ operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept
{
- _ThisBorrowedObj::operator=(mapping);
+ _ThisBorrowedObject::operator=(mapping);
return *this;
}
RangeSet ranges() const noexcept
{
return RangeSet {
- internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->_libObjPtr())};
+ internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
}
- bpstd::string_view label() const noexcept
+ bt2c::CStringView label() const noexcept
{
- return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->_libObjPtr());
+ return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
}
};
{
return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label);
}
+
+ static bt_field_class_enumeration_add_mapping_status
+ addMapping(bt_field_class * const libObjPtr, const char * const label,
+ const bt_integer_range_set_unsigned * const libRanges) noexcept
+ {
+ return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges);
+ }
};
/* Functions specific to signed enumeration field classes */
{
return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label);
}
+
+ static bt_field_class_enumeration_add_mapping_status
+ addMapping(bt_field_class * const libObjPtr, const char * const label,
+ const bt_integer_range_set_signed * const libRanges) noexcept
+ {
+ return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges);
+ }
};
} /* namespace internal */
-template <typename LibObjT, typename MappingT>
-class CommonEnumerationFieldClass final : public CommonIntegerFieldClass<LibObjT>
+template <typename LibObjT>
+class CommonBaseEnumerationFieldClass : public CommonIntegerFieldClass<LibObjT>
{
private:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass;
- using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
+
+protected:
+ using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
- using Mapping = MappingT;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
- explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonBaseEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonIntegerFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isEnumeration());
}
template <typename OtherLibObjT>
- CommonEnumerationFieldClass(
- const CommonEnumerationFieldClass<OtherLibObjT, MappingT>& fc) noexcept :
+ CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
+ :
_ThisCommonIntegerFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonEnumerationFieldClass&
- operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT>& fc) noexcept
+ CommonBaseEnumerationFieldClass
+ operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonIntegerFieldClass::operator=(fc);
return *this;
}
- std::uint64_t size() const noexcept
+ CommonBaseEnumerationFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonBaseEnumerationFieldClass<const bt_field_class> {*this};
+ }
+
+ std::uint64_t length() const noexcept
+ {
+ return bt_field_class_enumeration_get_mapping_count(this->libObjPtr());
+ }
+
+ Shared shared() const noexcept
{
- return bt_field_class_enumeration_get_mapping_count(this->_libObjPtr());
+ return Shared::createWithRef(*this);
+ }
+};
+
+template <typename LibObjT, typename MappingT>
+class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT>
+{
+private:
+ using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
+
+public:
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>;
+ using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>;
+ using Mapping = MappingT;
+
+ explicit CommonEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept :
+ _ThisCommonBaseEnumerationFieldClass {libObjPtr}
+ {
+ BT_ASSERT_DBG(this->isEnumeration());
+ }
+
+ template <typename OtherLibObjT>
+ CommonEnumerationFieldClass(
+ const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept :
+ CommonEnumerationFieldClass {fc}
+ {
+ }
+
+ template <typename OtherLibObjT>
+ CommonEnumerationFieldClass
+ operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept
+ {
+ CommonEnumerationFieldClass::operator=(fc);
+ return *this;
}
Mapping operator[](const std::uint64_t index) const noexcept
{
return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex(
- this->_libObjPtr(), index)};
+ this->libObjPtr(), index)};
+ }
+
+ OptionalBorrowedObject<Mapping> operator[](const bt2c::CStringView label) const noexcept
+ {
+ return internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
+ this->libObjPtr(), label);
}
- nonstd::optional<Mapping> operator[](const char * const label) const noexcept
+ CommonEnumerationFieldClass addMapping(const bt2c::CStringView label,
+ const typename Mapping::RangeSet ranges) const
{
- const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
- this->_libObjPtr(), label);
+ const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
+ this->libObjPtr(), label, ranges.libObjPtr());
- if (libObjPtr) {
- return Mapping {libObjPtr};
+ if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
+ throw MemoryError {};
}
- return nonstd::nullopt;
+ return *this;
+ }
+
+ Iterator begin() const noexcept
+ {
+ return Iterator {*this, 0};
}
- nonstd::optional<Mapping> operator[](const std::string& label) const noexcept
+ Iterator end() const noexcept
{
- return (*this)[label.data()];
+ return Iterator {*this, this->length()};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
+using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>;
+using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>;
+
using UnsignedEnumerationFieldClass =
CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
namespace internal {
+struct UnsignedEnumerationFieldClassTypeDescr
+{
+ using Const = ConstUnsignedEnumerationFieldClass;
+ using NonConst = UnsignedEnumerationFieldClass;
+};
+
+template <>
+struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
+{
+};
+
+struct SignedEnumerationFieldClassTypeDescr
+{
+ using Const = ConstSignedEnumerationFieldClass;
+ using NonConst = SignedEnumerationFieldClass;
+};
+
+template <>
+struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
+{
+};
+
template <typename LibObjT>
struct CommonStructureFieldClassMemberSpec;
{
return bt_field_class_structure_member_borrow_field_class(libObjPtr);
}
+
+ static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept
+ {
+ return bt_field_class_structure_member_borrow_user_attributes(libObjPtr);
+ }
};
/* Functions specific to constant structure field class members */
{
return bt_field_class_structure_member_borrow_field_class_const(libObjPtr);
}
+
+ static const bt_value *
+ userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept
+ {
+ return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr);
+ }
};
} /* namespace internal */
template <typename LibObjT>
-class CommonStructureFieldClassMember final : public internal::BorrowedObj<LibObjT>
+class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT>
{
private:
- using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
- using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-
- using _FieldClass =
- typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+ using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+ using _FieldClass = internal::DepFc<LibObjT>;
public:
- explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept :
- _ThisBorrowedObj {libObjPtr}
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
+ using UserAttributes = internal::DepUserAttrs<LibObjT>;
+
+ explicit CommonStructureFieldClassMember(const LibObjPtr libObjPtr) noexcept :
+ _ThisBorrowedObject {libObjPtr}
{
}
template <typename OtherLibObjT>
- CommonStructureFieldClassMember(
- const CommonStructureFieldClassMember<OtherLibObjT>& fc) noexcept :
- _ThisBorrowedObj {fc}
+ CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
+ :
+ _ThisBorrowedObject {fc}
{
}
template <typename OtherLibObjT>
- CommonStructureFieldClassMember<LibObjT>&
- operator=(const CommonStructureFieldClassMember<OtherLibObjT>& fc) noexcept
+ CommonStructureFieldClassMember<LibObjT>
+ operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
{
- _ThisBorrowedObj::operator=(fc);
+ _ThisBorrowedObject::operator=(fc);
return *this;
}
- bpstd::string_view name() const noexcept
+ CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept
{
- return bt_field_class_structure_member_get_name(this->_libObjPtr());
+ return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
}
- ConstFieldClass fieldClass() const noexcept
+ bt2c::CStringView name() const noexcept
{
- return ConstFieldClass {internal::CommonStructureFieldClassMemberSpec<
- const bt_field_class_structure_member>::fieldClass(this->_libObjPtr())};
+ return bt_field_class_structure_member_get_name(this->libObjPtr());
}
- _FieldClass fieldClass() noexcept
+ _FieldClass fieldClass() const noexcept
{
return _FieldClass {
- internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->_libObjPtr())};
+ internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())};
+ }
+
+ template <typename LibValT>
+ CommonStructureFieldClassMember
+ userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+ {
+ static_assert(!std::is_const<LibObjT>::value,
+ "Not available with `bt2::ConstStructureFieldClassMember`.");
+
+ bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
+ userAttrs.libObjPtr());
+ return *this;
+ }
+
+ UserAttributes userAttributes() const noexcept
+ {
+ return UserAttributes {
+ internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes(
+ this->libObjPtr())};
}
};
namespace internal {
+struct StructureFieldClassMemberTypeDescr
+{
+ using Const = ConstStructureFieldClassMember;
+ using NonConst = StructureFieldClassMember;
+};
+
+template <>
+struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
+{
+};
+
template <typename LibObjT>
struct CommonStructureFieldClassSpec;
class CommonStructureFieldClass final : public CommonFieldClass<LibObjT>
{
private:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
public:
- using Shared = internal::SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
+ using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>;
using Member =
- typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember,
- StructureFieldClassMember>::type;
+ internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>;
- explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonStructureFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isStructure());
}
template <typename OtherLibObjT>
- CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT>& fc) noexcept :
+ CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonFieldClass {fc}
{
}
template <typename OtherLibObjT>
- CommonStructureFieldClass<LibObjT>&
- operator=(const CommonStructureFieldClass<OtherLibObjT>& fc) noexcept
+ CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonFieldClass::operator=(fc);
return *this;
}
- void appendMember(const char * const name, const FieldClass& fc)
+ CommonStructureFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonStructureFieldClass<const bt_field_class> {*this};
+ }
+
+ CommonStructureFieldClass appendMember(const bt2c::CStringView name, const FieldClass fc) const
{
- static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+ static_assert(!std::is_const<LibObjT>::value,
+ "Not available with `bt2::ConstStructureFieldClass`.");
const auto status =
- bt_field_class_structure_append_member(this->_libObjPtr(), name, fc._libObjPtr());
+ bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) {
- throw LibMemoryError {};
+ throw MemoryError {};
}
- }
-
- void appendMember(const std::string& name, const FieldClass& fc)
- {
- this->appendMember(name.data(), fc);
- }
-
- std::uint64_t size() const noexcept
- {
- return bt_field_class_structure_get_member_count(this->_libObjPtr());
- }
- ConstStructureFieldClassMember operator[](const std::uint64_t index) const noexcept
- {
- return ConstStructureFieldClassMember {
- internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByIndex(
- this->_libObjPtr(), index)};
+ return *this;
}
- Member operator[](const std::uint64_t index) noexcept
+ std::uint64_t length() const noexcept
{
- return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex(
- this->_libObjPtr(), index)};
+ return bt_field_class_structure_get_member_count(this->libObjPtr());
}
- nonstd::optional<ConstStructureFieldClassMember>
- operator[](const char * const name) const noexcept
+ Iterator begin() const noexcept
{
- const auto libObjPtr =
- internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByName(
- this->_libObjPtr(), name);
-
- if (libObjPtr) {
- return ConstStructureFieldClassMember {libObjPtr};
- }
-
- return nonstd::nullopt;
+ return Iterator {*this, 0};
}
- nonstd::optional<ConstStructureFieldClassMember>
- operator[](const std::string& name) const noexcept
+ Iterator end() const noexcept
{
- return (*this)[name.data()];
+ return Iterator {*this, this->length()};
}
- nonstd::optional<Member> operator[](const char * const name) noexcept
+ Member operator[](const std::uint64_t index) const noexcept
{
- const auto libObjPtr = internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(
- this->_libObjPtr(), name);
-
- if (libObjPtr) {
- return Member {libObjPtr};
- }
-
- return nonstd::nullopt;
+ return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex(
+ this->libObjPtr(), index)};
}
- nonstd::optional<Member> operator[](const std::string& name) noexcept
+ OptionalBorrowedObject<Member> operator[](const bt2c::CStringView name) const noexcept
{
- return (*this)[name.data()];
+ return internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(),
+ name);
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
namespace internal {
+struct StructureFieldClassTypeDescr
+{
+ using Const = ConstStructureFieldClass;
+ using NonConst = StructureFieldClass;
+};
+
+template <>
+struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr
+{
+};
+
template <typename LibObjT>
struct CommonArrayFieldClassSpec;
{
private:
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
-
- using _FieldClass =
- typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+ using _FieldClass = internal::DepFc<LibObjT>;
protected:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
- explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isArray());
}
template <typename OtherLibObjT>
- CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT>& fc) noexcept :
+ CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT>& fc) noexcept
+ CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonFieldClass::operator=(fc);
return *this;
}
- ConstFieldClass elementFieldClass() const noexcept
+ CommonArrayFieldClass<const bt_field_class> asConst() const noexcept
{
- return ConstFieldClass {
- internal::CommonArrayFieldClassSpec<const bt_field_class>::elementFieldClass(
- this->_libObjPtr())};
+ return CommonArrayFieldClass<const bt_field_class> {*this};
}
- _FieldClass elementFieldClass() noexcept
+ _FieldClass elementFieldClass() const noexcept
{
return _FieldClass {
- internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->_libObjPtr())};
+ internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>;
using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>;
+namespace internal {
+
+struct ArrayFieldClassTypeDescr
+{
+ using Const = ConstArrayFieldClass;
+ using NonConst = ArrayFieldClass;
+};
+
+template <>
+struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT>
{
private:
using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
public:
- using Shared = internal::SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
- explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonStaticArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonArrayFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isStaticArray());
}
template <typename OtherLibObjT>
- CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT>& fc) noexcept :
+ CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonArrayFieldClass {fc}
{
}
template <typename OtherLibObjT>
- CommonStaticArrayFieldClass<LibObjT>&
- operator=(const CommonStaticArrayFieldClass<OtherLibObjT>& fc) noexcept
+ CommonStaticArrayFieldClass
+ operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonArrayFieldClass::operator=(fc);
return *this;
}
+ CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonStaticArrayFieldClass<const bt_field_class> {*this};
+ }
+
std::uint64_t length() const noexcept
{
- return bt_field_class_array_static_get_length(this->_libObjPtr());
+ return bt_field_class_array_static_get_length(this->libObjPtr());
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>;
using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>;
+namespace internal {
+
+struct StaticArrayFieldClassTypeDescr
+{
+ using Const = ConstStaticArrayFieldClass;
+ using NonConst = StaticArrayFieldClass;
+};
+
+template <>
+struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT>
{
private:
using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
public:
- using Shared =
- internal::SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
- explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonDynamicArrayWithLengthFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonArrayFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isDynamicArrayWithLength());
template <typename OtherLibObjT>
CommonDynamicArrayWithLengthFieldClass(
- const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT>& fc) noexcept :
+ const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonArrayFieldClass {fc}
{
}
template <typename OtherLibObjT>
- CommonDynamicArrayWithLengthFieldClass<LibObjT>&
- operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT>& fc) noexcept
+ CommonDynamicArrayWithLengthFieldClass
+ operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonArrayFieldClass::operator=(fc);
return *this;
}
+ CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this};
+ }
+
ConstFieldPath lengthFieldPath() const noexcept
{
return ConstFieldPath {
bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
- this->_libObjPtr())};
+ this->libObjPtr())};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
namespace internal {
+struct DynamicArrayWithLengthFieldClassTypeDescr
+{
+ using Const = ConstDynamicArrayWithLengthFieldClass;
+ using NonConst = DynamicArrayWithLengthFieldClass;
+};
+
+template <>
+struct TypeDescr<DynamicArrayWithLengthFieldClass> :
+ public DynamicArrayWithLengthFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> :
+ public DynamicArrayWithLengthFieldClassTypeDescr
+{
+};
+
template <typename LibObjT>
struct CommonOptionFieldClassSpec;
{
private:
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
-
- using _FieldClass =
- typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+ using _FieldClass = internal::DepFc<LibObjT>;
protected:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
- explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonOptionFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isOption());
}
template <typename OtherLibObjT>
- CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT>& fc) noexcept :
+ CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT>& fc) noexcept
+ CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonFieldClass::operator=(fc);
return *this;
}
- ConstFieldClass fieldClass() const noexcept
+ CommonOptionFieldClass<const bt_field_class> asConst() const noexcept
{
- return ConstFieldClass {
- internal::CommonOptionFieldClassSpec<const bt_field_class>::fieldClass(
- this->_libObjPtr())};
+ return CommonOptionFieldClass<const bt_field_class> {*this};
}
- _FieldClass fieldClass() noexcept
+ _FieldClass fieldClass() const noexcept
{
return _FieldClass {
- internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->_libObjPtr())};
+ internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using OptionFieldClass = CommonOptionFieldClass<bt_field_class>;
using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>;
+namespace internal {
+
+struct OptionFieldClassTypeDescr
+{
+ using Const = ConstOptionFieldClass;
+ using NonConst = OptionFieldClass;
+};
+
+template <>
+struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT>
{
using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass;
protected:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
- explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonOptionWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonOptionFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isOptionWithSelector());
template <typename OtherLibObjT>
CommonOptionWithSelectorFieldClass(
- const CommonOptionWithSelectorFieldClass<OtherLibObjT>& fc) noexcept :
+ const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonOptionFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonOptionWithSelectorFieldClass&
- operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT>& fc) noexcept
+ CommonOptionWithSelectorFieldClass
+ operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonOptionFieldClass::operator=(fc);
return *this;
}
+ CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this};
+ }
+
ConstFieldPath selectorFieldPath() const noexcept
{
return ConstFieldPath {
bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
- this->_libObjPtr())};
+ this->libObjPtr())};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>;
using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>;
+namespace internal {
+
+struct OptionWithSelectorFieldClassTypeDescr
+{
+ using Const = ConstOptionWithSelectorFieldClass;
+ using NonConst = OptionWithSelectorFieldClass;
+};
+
+template <>
+struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
{
private:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-
using typename CommonOptionWithSelectorFieldClass<
LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
public:
- using Shared =
- internal::SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
- explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonOptionWithBoolSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonOptionWithSelectorFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isOptionWithBoolSelector());
template <typename OtherLibObjT>
CommonOptionWithBoolSelectorFieldClass(
- const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT>& fc) noexcept :
+ const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonOptionWithSelectorFieldClass {fc}
{
}
template <typename OtherLibObjT>
- CommonOptionWithBoolSelectorFieldClass<LibObjT>&
- operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT>& fc) noexcept
+ CommonOptionWithBoolSelectorFieldClass
+ operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonOptionWithSelectorFieldClass::operator=(fc);
return *this;
}
+ CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this};
+ }
+
bool selectorIsReversed() const noexcept
{
return bt_field_class_option_with_selector_field_bool_selector_is_reversed(
- this->_libObjPtr());
+ this->libObjPtr());
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
namespace internal {
+struct OptionWithBoolSelectorFieldClassTypeDescr
+{
+ using Const = ConstOptionWithBoolSelectorFieldClass;
+ using NonConst = OptionWithBoolSelectorFieldClass;
+};
+
+template <>
+struct TypeDescr<OptionWithBoolSelectorFieldClass> :
+ public OptionWithBoolSelectorFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> :
+ public OptionWithBoolSelectorFieldClassTypeDescr
+{
+};
+
template <typename RangeSetT>
struct CommonOptionWithIntegerSelectorFieldClassSpec;
class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
{
private:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-
using typename CommonOptionWithSelectorFieldClass<
LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
- using _ThisCommonOptionWithIntegerSelectorFieldClass =
- CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
-
public:
- using Shared =
- internal::SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
-
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>;
using RangeSet = RangeSetT;
- explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonOptionWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonOptionWithSelectorFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isOptionWithIntegerSelector());
template <typename OtherLibObjT>
CommonOptionWithIntegerSelectorFieldClass(
- const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT>& fc) noexcept :
+ const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept :
_ThisCommonOptionWithSelectorFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonOptionWithIntegerSelectorFieldClass&
- operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT>& fc) noexcept
+ CommonOptionWithIntegerSelectorFieldClass
+ operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
{
_ThisCommonOptionWithSelectorFieldClass::operator=(fc);
return *this;
RangeSet ranges() const noexcept
{
return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges(
- this->_libObjPtr())};
+ this->libObjPtr())};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
namespace internal {
+struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
+{
+ using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass;
+ using NonConst = OptionWithUnsignedIntegerSelectorFieldClass;
+};
+
+template <>
+struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> :
+ public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> :
+ public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
+struct OptionWithSignedIntegerSelectorFieldClassTypeDescr
+{
+ using Const = ConstOptionWithSignedIntegerSelectorFieldClass;
+ using NonConst = OptionWithSignedIntegerSelectorFieldClass;
+};
+
+template <>
+struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> :
+ public OptionWithSignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> :
+ public OptionWithSignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
template <typename LibObjT>
struct CommonVariantFieldClassOptionSpec;
{
return bt_field_class_variant_option_borrow_field_class(libObjPtr);
}
+
+ static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept
+ {
+ return bt_field_class_variant_option_borrow_user_attributes(libObjPtr);
+ }
};
/* Functions specific to constant variant field class options */
{
return bt_field_class_variant_option_borrow_field_class_const(libObjPtr);
}
+
+ static const bt_value *
+ userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept
+ {
+ return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr);
+ }
};
} /* namespace internal */
template <typename LibObjT>
-class CommonVariantFieldClassOption : public internal::BorrowedObj<LibObjT>
+class CommonVariantFieldClassOption : public BorrowedObject<LibObjT>
{
private:
- using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
- using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
-
- using _FieldClass =
- typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+ using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+ using _FieldClass = internal::DepFc<LibObjT>;
public:
- explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
- _ThisBorrowedObj {libObjPtr}
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
+ using UserAttributes = internal::DepUserAttrs<LibObjT>;
+
+ explicit CommonVariantFieldClassOption(const LibObjPtr libObjPtr) noexcept :
+ _ThisBorrowedObject {libObjPtr}
{
}
template <typename OtherLibObjT>
- CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT>& fc) noexcept :
- _ThisBorrowedObj {fc}
+ CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept :
+ _ThisBorrowedObject {fc}
{
}
template <typename OtherLibObjT>
- CommonVariantFieldClassOption<LibObjT>&
- operator=(const CommonVariantFieldClassOption<OtherLibObjT>& fc) noexcept
+ CommonVariantFieldClassOption
+ operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
{
- _ThisBorrowedObj::operator=(fc);
+ _ThisBorrowedObject::operator=(fc);
return *this;
}
- bpstd::string_view name() const noexcept
+ CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept
{
- return bt_field_class_variant_option_get_name(this->_libObjPtr());
+ return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
}
- ConstFieldClass fieldClass() const noexcept
+ bt2c::CStringView name() const noexcept
{
- return ConstFieldClass {internal::CommonVariantFieldClassOptionSpec<
- const bt_field_class_variant_option>::fieldClass(this->_libObjPtr())};
+ return bt_field_class_variant_option_get_name(this->libObjPtr());
}
- _FieldClass fieldClass() noexcept
+ _FieldClass fieldClass() const noexcept
{
return _FieldClass {
- internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->_libObjPtr())};
+ internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())};
+ }
+
+ template <typename LibValT>
+ CommonVariantFieldClassOption
+ userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+ {
+ static_assert(!std::is_const<LibObjT>::value,
+ "Not available with `bt2::ConstVariantFieldClassOption`.");
+
+ bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+ return *this;
+ }
+
+ UserAttributes userAttributes() const noexcept
+ {
+ return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes(
+ this->libObjPtr())};
}
};
namespace internal {
+struct VariantFieldClassOptionTypeDescr
+{
+ using Const = ConstVariantFieldClassOption;
+ using NonConst = VariantFieldClassOption;
+};
+
+template <>
+struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
+{
+};
+
template <typename LibObjT>
struct ConstVariantWithIntegerSelectorFieldClassOptionSpec;
} /* namespace internal */
template <typename LibObjT>
-class ConstVariantWithIntegerSelectorFieldClassOption : public internal::BorrowedObj<LibObjT>
+class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT>
{
private:
- using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
- using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+ using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
public:
+ using typename BorrowedObject<LibObjT>::LibObjPtr;
+
using RangeSet = typename std::conditional<
std::is_same<
LibObjT,
const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value,
ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
- explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
- _ThisBorrowedObj {libObjPtr}
+ explicit ConstVariantWithIntegerSelectorFieldClassOption(const LibObjPtr libObjPtr) noexcept :
+ _ThisBorrowedObject {libObjPtr}
{
}
template <typename OtherLibObjT>
ConstVariantWithIntegerSelectorFieldClassOption(
- const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT>& fc) noexcept :
- _ThisBorrowedObj {fc}
+ const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept :
+ _ThisBorrowedObject {fc}
{
}
template <typename OtherLibObjT>
- ConstVariantWithIntegerSelectorFieldClassOption<LibObjT>&
- operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT>& fc) noexcept
+ ConstVariantWithIntegerSelectorFieldClassOption
+ operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
{
- _ThisBorrowedObj::operator=(fc);
+ _ThisBorrowedObject::operator=(fc);
return *this;
}
ConstVariantFieldClassOption asBaseOption() const noexcept
{
- return ConstVariantFieldClassOption {_Spec::asBaseOption(this->_libObjPtr())};
+ return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
}
- bpstd::string_view name() const noexcept
+ bt2c::CStringView name() const noexcept
{
return this->asBaseOption().name();
}
RangeSet ranges() const noexcept
{
- return RangeSet {_Spec::ranges(this->_libObjPtr())};
+ return RangeSet {_Spec::ranges(this->libObjPtr())};
}
};
using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
protected:
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
public:
- using Shared = internal::SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
+ using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>;
using Option =
- typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption,
- VariantFieldClassOption>::type;
+ internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>;
- explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonVariantFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isVariant());
}
template <typename OtherLibObjT>
- CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT>& fc) noexcept :
+ CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonVariantFieldClass&
- operator=(const CommonVariantFieldClass<OtherLibObjT>& fc) noexcept
+ CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonFieldClass::operator=(fc);
return *this;
}
- std::uint64_t size() const noexcept
- {
- return bt_field_class_variant_get_option_count(this->_libObjPtr());
- }
-
- ConstVariantFieldClassOption operator[](const std::uint64_t index) const noexcept
+ CommonVariantFieldClass<const bt_field_class> asConst() const noexcept
{
- return ConstVariantFieldClassOption {
- internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByIndex(
- this->_libObjPtr(), index)};
+ return CommonVariantFieldClass<const bt_field_class> {*this};
}
- Option operator[](const std::uint64_t index) noexcept
+ std::uint64_t length() const noexcept
{
- return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex(
- this->_libObjPtr(), index)};
+ return bt_field_class_variant_get_option_count(this->libObjPtr());
}
- nonstd::optional<ConstVariantFieldClassOption>
- operator[](const char * const name) const noexcept
+ Iterator begin() const noexcept
{
- const auto libObjPtr =
- internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByName(
- this->_libObjPtr(), name);
-
- if (libObjPtr) {
- return ConstVariantFieldClassOption {libObjPtr};
- }
-
- return nonstd::nullopt;
+ return Iterator {*this, 0};
}
- nonstd::optional<ConstVariantFieldClassOption>
- operator[](const std::string& name) const noexcept
+ Iterator end() const noexcept
{
- return (*this)[name.data()];
+ return Iterator {*this, this->length()};
}
- nonstd::optional<Option> operator[](const char * const name) noexcept
+ Option operator[](const std::uint64_t index) const noexcept
{
- const auto libObjPtr =
- internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->_libObjPtr(), name);
-
- if (libObjPtr) {
- return Option {libObjPtr};
- }
-
- return nonstd::nullopt;
+ return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex(
+ this->libObjPtr(), index)};
}
- nonstd::optional<Option> operator[](const std::string& name) noexcept
+ OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
{
- return (*this)[name.data()];
+ return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(),
+ name);
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using VariantFieldClass = CommonVariantFieldClass<bt_field_class>;
using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>;
+namespace internal {
+
+struct VariantFieldClassTypeDescr
+{
+ using Const = ConstVariantFieldClass;
+ using NonConst = VariantFieldClass;
+};
+
+template <>
+struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
{
private:
using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
public:
- using Shared =
- internal::SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
- explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonVariantWithoutSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonVariantFieldClass {libObjPtr}
{
BT_ASSERT_DBG(this->isVariantWithoutSelector());
template <typename OtherLibObjT>
CommonVariantWithoutSelectorFieldClass(
- const CommonVariantWithoutSelectorFieldClass<OtherLibObjT>& fc) noexcept :
+ const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonVariantFieldClass {fc}
{
}
template <typename OtherLibObjT>
- CommonVariantWithoutSelectorFieldClass<LibObjT>&
- operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT>& fc) noexcept
+ CommonVariantWithoutSelectorFieldClass
+ operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonVariantFieldClass::operator=(fc);
return *this;
}
- void appendOption(const char * const name, const FieldClass& fc)
+ CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this};
+ }
+
+ CommonVariantWithoutSelectorFieldClass appendOption(const char * const name,
+ const FieldClass fc) const
{
- static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+ static_assert(!std::is_const<LibObjT>::value,
+ "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`.");
const auto status = bt_field_class_variant_without_selector_append_option(
- this->_libObjPtr(), name, fc._libObjPtr());
+ this->libObjPtr(), name, fc.libObjPtr());
if (status ==
BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
- throw LibMemoryError {};
+ throw MemoryError {};
}
+
+ return *this;
+ }
+
+ CommonVariantWithoutSelectorFieldClass appendOption(const bt2c::CStringView name,
+ const FieldClass fc) const
+ {
+ return this->appendOption(name.data(), fc);
}
- void appendOption(const std::string& name, const FieldClass& fc)
+ CommonVariantWithoutSelectorFieldClass appendOption(const bt2s::optional<std::string>& name,
+ const FieldClass fc) const
{
- this->appendOption(name.data(), fc);
+ return this->appendOption(name ? name->data() : nullptr, fc);
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
namespace internal {
+struct VariantWithoutSelectorFieldClassTypeDescr
+{
+ using Const = ConstVariantWithoutSelectorFieldClass;
+ using NonConst = VariantWithoutSelectorFieldClass;
+};
+
+template <>
+struct TypeDescr<VariantWithoutSelectorFieldClass> :
+ public VariantWithoutSelectorFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstVariantWithoutSelectorFieldClass> :
+ public VariantWithoutSelectorFieldClassTypeDescr
+{
+};
+
template <typename OptionT>
struct CommonVariantWithIntegerSelectorFieldClassSpec;
} /* namespace internal */
-template <typename LibObjT, typename OptionT>
-class CommonVariantWithIntegerSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
+template <typename LibObjT>
+class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
{
private:
using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
- using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-
- using _ThisCommonVariantWithIntegerSelectorFieldClass =
- CommonVariantWithIntegerSelectorFieldClass<LibObjT, OptionT>;
- using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
+protected:
+ using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
public:
- using Shared =
- internal::SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
-
- using Option = OptionT;
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
- explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
+ explicit CommonVariantWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
_ThisCommonVariantFieldClass {libObjPtr}
{
- BT_ASSERT_DBG(this->isVariant());
+ BT_ASSERT_DBG(this->isVariantWithSelector());
}
template <typename OtherLibObjT>
- CommonVariantWithIntegerSelectorFieldClass(
- const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT>& fc) noexcept :
+ CommonVariantWithSelectorFieldClass(
+ const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
_ThisCommonVariantFieldClass {fc}
{
}
template <typename OtherLibObjT>
- _ThisCommonVariantWithIntegerSelectorFieldClass&
- operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT>& fc) noexcept
+ CommonVariantWithSelectorFieldClass
+ operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
{
_ThisCommonVariantFieldClass::operator=(fc);
return *this;
}
+ CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
+ {
+ return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this};
+ }
+
ConstFieldPath selectorFieldPath() const noexcept
{
return ConstFieldPath {
- bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
- this->_libObjPtr())};
+ bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
+ this->libObjPtr())};
}
- Option operator[](const std::uint64_t index) const noexcept
+ Shared shared() const noexcept
+ {
+ return Shared::createWithRef(*this);
+ }
+};
+
+using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>;
+using ConstVariantWithSelectorFieldClass =
+ CommonVariantWithSelectorFieldClass<const bt_field_class>;
+
+template <typename LibObjT, typename OptionT>
+class CommonVariantWithIntegerSelectorFieldClass :
+ public CommonVariantWithSelectorFieldClass<LibObjT>
+{
+private:
+ using typename CommonVariantWithSelectorFieldClass<
+ LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
+
+ using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
+
+public:
+ using typename CommonFieldClass<LibObjT>::LibObjPtr;
+ using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>;
+ using Option = OptionT;
+
+ using Iterator =
+ BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>;
+
+ explicit CommonVariantWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
+ _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
{
- return Option {_Spec::optionByIndex(this->_libObjPtr(), index)};
+ BT_ASSERT_DBG(this->isVariantWithIntegerSelector());
}
- nonstd::optional<Option> operator[](const char * const name) const noexcept
+ template <typename OtherLibObjT>
+ CommonVariantWithIntegerSelectorFieldClass(
+ const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept :
+ _ThisCommonVariantWithSelectorFieldClass {fc}
{
- const auto libObjPtr = _Spec::optionByName(this->_libObjPtr(), name);
+ }
- if (libObjPtr) {
- return Option {libObjPtr};
- }
+ template <typename OtherLibObjT>
+ CommonVariantWithIntegerSelectorFieldClass
+ operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
+ {
+ _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
+ return *this;
+ }
- return nonstd::nullopt;
+ Option operator[](const std::uint64_t index) const noexcept
+ {
+ return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
}
- nonstd::optional<Option> operator[](const std::string& name) const noexcept
+ OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
{
- return (*this)[name.data()];
+ return _Spec::optionByName(this->libObjPtr(), name);
}
- void appendOption(const char * const name, const FieldClass& fc,
- const typename Option::RangeSet& ranges)
+ CommonVariantWithIntegerSelectorFieldClass
+ appendOption(const char * const name, const FieldClass fc,
+ const typename Option::RangeSet ranges) const
{
- static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+ static_assert(
+ !std::is_const<LibObjT>::value,
+ "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`.");
const auto status =
- _Spec::appendOption(this->_libObjPtr(), name, fc._libObjPtr(), ranges._libObjPtr());
+ _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr());
if (status ==
BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
- throw LibMemoryError {};
+ throw MemoryError {};
}
+
+ return *this;
+ }
+
+ CommonVariantWithIntegerSelectorFieldClass
+ appendOption(const bt2c::CStringView name, const FieldClass fc,
+ const typename Option::RangeSet ranges) const
+ {
+ return this->appendOption(name.data(), fc, ranges);
+ }
+
+ CommonVariantWithIntegerSelectorFieldClass
+ appendOption(const bt2s::optional<std::string>& name, const FieldClass fc,
+ const typename Option::RangeSet ranges) const
+ {
+ return this->appendOption(name ? name->data() : nullptr, fc, ranges);
+ }
+
+ Iterator begin() const noexcept
+ {
+ return Iterator {*this, 0};
}
- void appendOption(const std::string& name, const FieldClass& fc)
+ Iterator end() const noexcept
{
- this->appendOption(name.data(), fc);
+ return Iterator {*this, this->length()};
}
Shared shared() const noexcept
{
- return Shared {*this};
+ return Shared::createWithRef(*this);
}
};
using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
+namespace internal {
+
+struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
+{
+ using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass;
+ using NonConst = VariantWithUnsignedIntegerSelectorFieldClass;
+};
+
+template <>
+struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> :
+ public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> :
+ public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
+struct VariantWithSignedIntegerSelectorFieldClassTypeDescr
+{
+ using Const = ConstVariantWithSignedIntegerSelectorFieldClass;
+ using NonConst = VariantWithSignedIntegerSelectorFieldClass;
+};
+
+template <>
+struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> :
+ public VariantWithSignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> :
+ public VariantWithSignedIntegerSelectorFieldClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
template <typename LibObjT>
CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept
{
- BT_ASSERT_DBG(this->isBitArray());
- return CommonBitArrayFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept
{
- BT_ASSERT_DBG(this->isInteger());
- return CommonIntegerFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()};
+}
+
+template <typename LibObjT>
+CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept
+{
+ return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
{
BT_ASSERT_DBG(this->isUnsignedEnumeration());
return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> {
- this->_libObjPtr()};
+ this->libObjPtr()};
}
template <typename LibObjT>
{
BT_ASSERT_DBG(this->isSignedEnumeration());
return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> {
- this->_libObjPtr()};
+ this->libObjPtr()};
}
template <typename LibObjT>
CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept
{
- BT_ASSERT_DBG(this->isStructure());
- return CommonStructureFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonStructureFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept
{
- BT_ASSERT_DBG(this->isArray());
- return CommonArrayFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonArrayFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept
{
- BT_ASSERT_DBG(this->isStaticArray());
- return CommonStaticArrayFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonDynamicArrayWithLengthFieldClass<LibObjT>
CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept
{
- BT_ASSERT_DBG(this->isDynamicArrayWithLength());
- return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept
{
- BT_ASSERT_DBG(this->isOption());
- return CommonOptionFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonOptionFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonOptionWithSelectorFieldClass<LibObjT>
CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept
{
- BT_ASSERT_DBG(this->isOptionWithSelector());
- return CommonOptionWithSelectorFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonOptionWithBoolSelectorFieldClass<LibObjT>
CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept
{
- BT_ASSERT_DBG(this->isOptionWithBoolSelector());
- return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
{
BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector());
return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> {
- this->_libObjPtr()};
+ this->libObjPtr()};
}
template <typename LibObjT>
{
BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector());
return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> {
- this->_libObjPtr()};
+ this->libObjPtr()};
}
template <typename LibObjT>
CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept
{
- BT_ASSERT_DBG(this->isVariant());
- return CommonVariantFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonVariantFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
CommonVariantWithoutSelectorFieldClass<LibObjT>
CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept
{
- BT_ASSERT_DBG(this->isVariantWithoutSelector());
- return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->_libObjPtr()};
+ return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()};
+}
+
+template <typename LibObjT>
+CommonVariantWithSelectorFieldClass<LibObjT>
+CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept
+{
+ return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
}
template <typename LibObjT>
{
BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector());
return CommonVariantWithIntegerSelectorFieldClass<
- LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->_libObjPtr()};
+ LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
}
template <typename LibObjT>
{
BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector());
return CommonVariantWithIntegerSelectorFieldClass<
- LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->_libObjPtr()};
+ LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
}
} /* namespace bt2 */