2 * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
11 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "common/assert.h"
16 #include "cpp-common/optional.hpp"
17 #include "cpp-common/string_view.hpp"
19 #include "borrowed-obj.hpp"
20 #include "common-iter.hpp"
22 #include "field-path.hpp"
23 #include "integer-range-set.hpp"
24 #include "internal/shared-obj.hpp"
25 #include "internal/utils.hpp"
31 struct FieldClassRefFuncs final
33 static void get(const bt_field_class * const libObjPtr)
35 bt_field_class_get_ref(libObjPtr);
38 static void put(const bt_field_class * const libObjPtr)
40 bt_field_class_put_ref(libObjPtr);
44 template <typename ObjT, typename LibObjT>
45 using SharedFieldClass = internal::SharedObj<ObjT, LibObjT, internal::FieldClassRefFuncs>;
47 template <typename LibObjT>
48 struct CommonFieldClassSpec;
50 /* Functions specific to mutable field classes */
52 struct CommonFieldClassSpec<bt_field_class> final
54 static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept
56 return bt_field_class_borrow_user_attributes(libObjPtr);
60 /* Functions specific to constant field classes */
62 struct CommonFieldClassSpec<const bt_field_class> final
64 static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept
66 return bt_field_class_borrow_user_attributes_const(libObjPtr);
70 } /* namespace internal */
72 template <typename LibObjT>
73 class CommonBitArrayFieldClass;
75 template <typename LibObjT>
76 class CommonIntegerFieldClass;
78 template <typename LibObjT>
79 class ConstEnumerationFieldClassMapping;
81 template <typename LibObjT>
82 class CommonBaseEnumerationFieldClass;
84 template <typename LibObjT, typename MappingT>
85 class CommonEnumerationFieldClass;
87 template <typename LibObjT>
88 class CommonStructureFieldClass;
90 template <typename LibObjT>
91 class CommonArrayFieldClass;
93 template <typename LibObjT>
94 class CommonStaticArrayFieldClass;
96 template <typename LibObjT>
97 class CommonDynamicArrayWithLengthFieldClass;
99 template <typename LibObjT>
100 class CommonOptionFieldClass;
102 template <typename LibObjT>
103 class CommonOptionWithSelectorFieldClass;
105 template <typename LibObjT>
106 class CommonOptionWithBoolSelectorFieldClass;
108 template <typename LibObjT>
109 class CommonVariantFieldClass;
111 template <typename LibObjT, typename RangeSetT>
112 class CommonOptionWithIntegerSelectorFieldClass;
114 template <typename LibObjT>
115 class CommonVariantWithoutSelectorFieldClass;
117 template <typename LibObjT>
118 class CommonVariantWithSelectorFieldClass;
120 template <typename LibObjT>
121 class ConstVariantWithIntegerSelectorFieldClassOption;
123 template <typename LibObjT, typename RangeSetT>
124 class CommonVariantWithIntegerSelectorFieldClass;
126 template <typename LibObjT>
127 class CommonEventClass;
129 template <typename LibObjT>
130 class CommonStreamClass;
132 template <typename LibObjT>
133 class CommonTraceClass;
135 enum class FieldClassType
137 BOOL = BT_FIELD_CLASS_TYPE_BOOL,
138 BIT_ARRAY = BT_FIELD_CLASS_TYPE_BIT_ARRAY,
139 UNSIGNED_INTEGER = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER,
140 SIGNED_INTEGER = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER,
141 UNSIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION,
142 SIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION,
143 SINGLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL,
144 DOUBLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL,
145 STRING = BT_FIELD_CLASS_TYPE_STRING,
146 STRUCTURE = BT_FIELD_CLASS_TYPE_STRUCTURE,
147 STATIC_ARRAY = BT_FIELD_CLASS_TYPE_STATIC_ARRAY,
148 DYNAMIC_ARRAY_WITHOUT_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD,
149 DYNAMIC_ARRAY_WITH_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD,
150 OPTION_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD,
151 OPTION_WITH_BOOL_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD,
152 OPTION_WITH_UNSIGNED_INTEGER_SELECTOR =
153 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
154 OPTION_WITH_SIGNED_INTEGER_SELECTOR =
155 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
156 VARIANT_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD,
157 VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR =
158 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
159 VARIANT_WITH_SIGNED_INTEGER_SELECTOR =
160 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
163 template <typename LibObjT>
164 class CommonFieldClass : public BorrowedObj<LibObjT>
166 /* Allow appendMember() to call `fc.libObjPtr()` */
167 friend class CommonStructureFieldClass<bt_field_class>;
169 /* Allow appendOption() to call `fc.libObjPtr()` */
170 friend class CommonVariantWithoutSelectorFieldClass<bt_field_class>;
172 friend class CommonVariantWithIntegerSelectorFieldClass<
174 ConstVariantWithIntegerSelectorFieldClassOption<
175 const bt_field_class_variant_with_selector_field_integer_unsigned_option>>;
177 friend class CommonVariantWithIntegerSelectorFieldClass<
179 ConstVariantWithIntegerSelectorFieldClassOption<
180 const bt_field_class_variant_with_selector_field_integer_signed_option>>;
182 /* Allow *FieldClass() to call `fc.libObjPtr()` */
183 friend class CommonEventClass<bt_event_class>;
184 friend class CommonStreamClass<bt_stream_class>;
186 /* Allow create*FieldClass() to call `fc.libObjPtr()` */
187 friend class CommonTraceClass<bt_trace_class>;
190 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
193 using typename BorrowedObj<LibObjT>::_LibObjPtr;
194 using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
197 using Shared = internal::SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
199 using UserAttributes =
200 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
202 explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
206 template <typename OtherLibObjT>
207 CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObj {fc}
211 template <typename OtherLibObjT>
212 CommonFieldClass& operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
214 _ThisBorrowedObj::operator=(fc);
218 FieldClassType type() const noexcept
220 return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr()));
223 bool isBool() const noexcept
225 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BOOL);
228 bool isBitArray() const noexcept
230 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BIT_ARRAY);
233 bool isInteger() const noexcept
235 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_INTEGER);
238 bool isUnsignedInteger() const noexcept
240 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
243 bool isSignedInteger() const noexcept
245 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
248 bool isEnumeration() const noexcept
250 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ENUMERATION);
253 bool isUnsignedEnumeration() const noexcept
255 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION);
258 bool isSignedEnumeration() const noexcept
260 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
263 bool isReal() const noexcept
265 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_REAL);
268 bool isSinglePrecisionReal() const noexcept
270 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
273 bool isDoublePrecisionReal() const noexcept
275 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL);
278 bool isString() const noexcept
280 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRING);
283 bool isStructure() const noexcept
285 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRUCTURE);
288 bool isArray() const noexcept
290 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ARRAY);
293 bool isStaticArray() const noexcept
295 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STATIC_ARRAY);
298 bool isDynamicArray() const noexcept
300 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
303 bool isDynamicArrayWithoutLength() const noexcept
305 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD);
308 bool isDynamicArrayWithLength() const noexcept
310 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD);
313 bool isOption() const noexcept
315 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION);
318 bool isOptionWithoutSelector() const noexcept
320 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD);
323 bool isOptionWithSelector() const noexcept
325 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD);
328 bool isOptionWithBoolSelector() const noexcept
330 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD);
333 bool isOptionWithIntegerSelector() const noexcept
335 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_INTEGER_SELECTOR_FIELD);
338 bool isOptionWithUnsignedIntegerSelector() const noexcept
340 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD);
343 bool isOptionWithSignedIntegerSelector() const noexcept
345 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
348 bool isVariant() const noexcept
350 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT);
353 bool isVariantWithoutSelector() const noexcept
355 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD);
358 bool isVariantWithSelector() const noexcept
360 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD);
363 bool isVariantWithIntegerSelector() const noexcept
365 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_INTEGER_SELECTOR_FIELD);
368 bool isVariantWithUnsignedIntegerSelector() const noexcept
370 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD);
373 bool isVariantWithSignedIntegerSelector() const noexcept
375 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
378 template <typename FieldClassT>
379 FieldClassT as() const noexcept
381 return FieldClassT {this->libObjPtr()};
384 CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept;
385 CommonIntegerFieldClass<LibObjT> asInteger() const noexcept;
386 CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept;
387 CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping<
388 const bt_field_class_enumeration_unsigned_mapping>>
389 asUnsignedEnumeration() const noexcept;
391 CommonEnumerationFieldClass<
392 LibObjT, ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>>
393 asSignedEnumeration() const noexcept;
395 CommonStructureFieldClass<LibObjT> asStructure() const noexcept;
396 CommonArrayFieldClass<LibObjT> asArray() const noexcept;
397 CommonStaticArrayFieldClass<LibObjT> asStaticArray() const noexcept;
398 CommonDynamicArrayWithLengthFieldClass<LibObjT> asDynamicArrayWithLength() const noexcept;
399 CommonOptionFieldClass<LibObjT> asOption() const noexcept;
400 CommonOptionWithSelectorFieldClass<LibObjT> asOptionWithSelector() const noexcept;
401 CommonOptionWithBoolSelectorFieldClass<LibObjT> asOptionWithBoolSelector() const noexcept;
403 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet>
404 asOptionWithUnsignedIntegerSelector() const noexcept;
406 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet>
407 asOptionWithSignedIntegerSelector() const noexcept;
409 CommonVariantFieldClass<LibObjT> asVariant() const noexcept;
410 CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept;
411 CommonVariantWithSelectorFieldClass<LibObjT> asVariantWithSelector() const noexcept;
413 CommonVariantWithIntegerSelectorFieldClass<
414 LibObjT, ConstVariantWithIntegerSelectorFieldClassOption<
415 const bt_field_class_variant_with_selector_field_integer_unsigned_option>>
416 asVariantWithUnsignedIntegerSelector() const noexcept;
418 CommonVariantWithIntegerSelectorFieldClass<
419 LibObjT, ConstVariantWithIntegerSelectorFieldClassOption<
420 const bt_field_class_variant_with_selector_field_integer_signed_option>>
421 asVariantWithSignedIntegerSelector() const noexcept;
423 template <typename LibValT>
424 void userAttributes(const CommonMapValue<LibValT> userAttrs)
426 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
428 bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
431 ConstMapValue userAttributes() const noexcept
433 return ConstMapValue {internal::CommonFieldClassSpec<const bt_field_class>::userAttributes(
437 UserAttributes userAttributes() noexcept
439 return UserAttributes {
440 internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
443 Shared shared() const noexcept
445 return Shared::createWithRef(*this);
449 bool _libTypeIs(const bt_field_class_type type) const noexcept
451 return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type);
455 using FieldClass = CommonFieldClass<bt_field_class>;
456 using ConstFieldClass = CommonFieldClass<const bt_field_class>;
460 struct FieldClassTypeDescr
462 using Const = ConstFieldClass;
463 using NonConst = FieldClass;
467 struct TypeDescr<FieldClass> : public FieldClassTypeDescr
472 struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr
476 } /* namespace internal */
478 template <typename LibObjT>
479 class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT>
482 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
483 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
486 using Shared = internal::SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
488 explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
489 _ThisCommonFieldClass {libObjPtr}
491 BT_ASSERT_DBG(this->isBitArray());
494 template <typename OtherLibObjT>
495 CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept :
496 _ThisCommonFieldClass {fc}
500 template <typename OtherLibObjT>
501 CommonBitArrayFieldClass<LibObjT>&
502 operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
504 _ThisCommonFieldClass::operator=(fc);
508 std::uint64_t length() const noexcept
510 return bt_field_class_bit_array_get_length(this->libObjPtr());
513 Shared shared() const noexcept
515 return Shared::createWithRef(*this);
519 using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>;
520 using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>;
524 struct BitArrayFieldClassTypeDescr
526 using Const = ConstBitArrayFieldClass;
527 using NonConst = BitArrayFieldClass;
531 struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr
536 struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr
540 } /* namespace internal */
542 enum class DisplayBase
544 BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY,
545 OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL,
546 DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
547 HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL,
550 template <typename LibObjT>
551 class CommonIntegerFieldClass : public CommonFieldClass<LibObjT>
554 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
557 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
558 using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
561 using Shared = internal::SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
563 explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept :
564 _ThisCommonFieldClass {libObjPtr}
566 BT_ASSERT_DBG(this->isInteger());
569 template <typename OtherLibObjT>
570 CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept :
571 _ThisCommonFieldClass {fc}
575 template <typename OtherLibObjT>
576 CommonIntegerFieldClass& operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
578 _ThisCommonFieldClass::operator=(fc);
582 void fieldValueRange(const std::uint64_t n) noexcept
584 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
586 bt_field_class_integer_set_field_value_range(this->libObjPtr(), n);
589 std::uint64_t fieldValueRange() const noexcept
591 return bt_field_class_integer_get_field_value_range(this->libObjPtr());
594 void preferredDisplayBase(const DisplayBase base) noexcept
596 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
598 bt_field_class_integer_set_preferred_display_base(
599 this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
602 DisplayBase preferredDisplayBase() const noexcept
604 return static_cast<DisplayBase>(
605 bt_field_class_integer_get_preferred_display_base(this->libObjPtr()));
608 Shared shared() const noexcept
610 return Shared::createWithRef(*this);
614 using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>;
615 using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>;
619 struct IntegerFieldClassTypeDescr
621 using Const = ConstIntegerFieldClass;
622 using NonConst = IntegerFieldClass;
626 struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr
631 struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
635 } /* namespace internal */
639 template <typename LibObjT>
640 struct ConstEnumerationFieldClassMappingSpec;
642 /* Functions specific to unsigned enumeration field class mappings */
644 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping>
647 static const bt_integer_range_set_unsigned *
648 ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
650 return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr);
654 label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
656 return bt_field_class_enumeration_mapping_get_label(
657 bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr));
661 /* Functions specific to signed enumeration field class mappings */
663 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final
665 static const bt_integer_range_set_signed *
666 ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
668 return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr);
672 label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
674 return bt_field_class_enumeration_mapping_get_label(
675 bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr));
679 } /* namespace internal */
681 template <typename LibObjT>
682 class ConstEnumerationFieldClassMapping final : public BorrowedObj<LibObjT>
685 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
686 using typename BorrowedObj<LibObjT>::_LibObjPtr;
689 using RangeSet = typename std::conditional<
690 std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value,
691 ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
693 explicit ConstEnumerationFieldClassMapping(const _LibObjPtr libObjPtr) noexcept :
694 _ThisBorrowedObj {libObjPtr}
698 ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept :
699 _ThisBorrowedObj {mapping}
703 ConstEnumerationFieldClassMapping&
704 operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept
706 _ThisBorrowedObj::operator=(mapping);
710 RangeSet ranges() const noexcept
713 internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
716 bpstd::string_view label() const noexcept
718 return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
722 using ConstUnsignedEnumerationFieldClassMapping =
723 ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_unsigned_mapping>;
725 using ConstSignedEnumerationFieldClassMapping =
726 ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>;
730 template <typename MappingT>
731 struct CommonEnumerationFieldClassSpec;
733 /* Functions specific to unsigned enumeration field classes */
735 struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping> final
737 static const bt_field_class_enumeration_unsigned_mapping *
738 mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
740 return bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(libObjPtr, index);
743 static const bt_field_class_enumeration_unsigned_mapping *
744 mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept
746 return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label);
749 static bt_field_class_enumeration_add_mapping_status
750 addMapping(bt_field_class * const libObjPtr, const char * const label,
751 const bt_integer_range_set_unsigned * const libRanges) noexcept
753 return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges);
757 /* Functions specific to signed enumeration field classes */
759 struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping> final
761 static const bt_field_class_enumeration_signed_mapping *
762 mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
764 return bt_field_class_enumeration_signed_borrow_mapping_by_index_const(libObjPtr, index);
767 static const bt_field_class_enumeration_signed_mapping *
768 mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept
770 return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label);
773 static bt_field_class_enumeration_add_mapping_status
774 addMapping(bt_field_class * const libObjPtr, const char * const label,
775 const bt_integer_range_set_signed * const libRanges) noexcept
777 return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges);
781 } /* namespace internal */
783 template <typename LibObjT>
784 class CommonBaseEnumerationFieldClass : public CommonIntegerFieldClass<LibObjT>
787 using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass;
790 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
791 using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
794 using Shared = internal::SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
796 explicit CommonBaseEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
797 _ThisCommonIntegerFieldClass {libObjPtr}
799 BT_ASSERT_DBG(this->isEnumeration());
802 template <typename OtherLibObjT>
803 CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
805 _ThisCommonIntegerFieldClass {fc}
809 template <typename OtherLibObjT>
810 CommonBaseEnumerationFieldClass&
811 operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
813 _ThisCommonIntegerFieldClass::operator=(fc);
817 std::uint64_t size() const noexcept
819 return bt_field_class_enumeration_get_mapping_count(this->libObjPtr());
822 Shared shared() const noexcept
824 return Shared::createWithRef(*this);
828 template <typename LibObjT, typename MappingT>
829 class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT>
832 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
833 using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
834 using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
837 using Shared = internal::SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
838 using Iterator = CommonIterator<CommonEnumerationFieldClass, MappingT>;
839 using Mapping = MappingT;
841 explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
842 _ThisCommonBaseEnumerationFieldClass {libObjPtr}
844 BT_ASSERT_DBG(this->isEnumeration());
847 template <typename OtherLibObjT>
848 CommonEnumerationFieldClass(
849 const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept :
850 _ThisCommonEnumerationFieldClass {fc}
854 template <typename OtherLibObjT>
855 CommonEnumerationFieldClass&
856 operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept
858 _ThisCommonEnumerationFieldClass::operator=(fc);
862 Mapping operator[](const std::uint64_t index) const noexcept
864 return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex(
865 this->libObjPtr(), index)};
868 nonstd::optional<Mapping> operator[](const char * const label) const noexcept
870 const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
871 this->libObjPtr(), label);
874 return Mapping {libObjPtr};
877 return nonstd::nullopt;
880 nonstd::optional<Mapping> operator[](const std::string& label) const noexcept
882 return (*this)[label.data()];
885 void addMapping(const char * const label, const typename Mapping::RangeSet ranges)
887 const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
888 this->libObjPtr(), label, ranges.libObjPtr());
890 if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
891 throw MemoryError {};
895 void addMapping(const std::string& label, const typename Mapping::RangeSet ranges)
897 this->addMapping(label.data(), ranges);
900 Iterator begin() const noexcept
902 return Iterator {*this, 0};
905 Iterator end() const noexcept
907 return Iterator {*this, this->size()};
910 Shared shared() const noexcept
912 return Shared::createWithRef(*this);
916 using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>;
917 using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>;
919 using UnsignedEnumerationFieldClass =
920 CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
922 using ConstUnsignedEnumerationFieldClass =
923 CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
925 using SignedEnumerationFieldClass =
926 CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>;
928 using ConstSignedEnumerationFieldClass =
929 CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>;
933 struct UnsignedEnumerationFieldClassTypeDescr
935 using Const = ConstUnsignedEnumerationFieldClass;
936 using NonConst = UnsignedEnumerationFieldClass;
940 struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
945 struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
949 struct SignedEnumerationFieldClassTypeDescr
951 using Const = ConstSignedEnumerationFieldClass;
952 using NonConst = SignedEnumerationFieldClass;
956 struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
961 struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
965 template <typename LibObjT>
966 struct CommonStructureFieldClassMemberSpec;
968 /* Functions specific to mutable structure field class members */
970 struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final
972 static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept
974 return bt_field_class_structure_member_borrow_field_class(libObjPtr);
977 static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept
979 return bt_field_class_structure_member_borrow_user_attributes(libObjPtr);
983 /* Functions specific to constant structure field class members */
985 struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final
987 static const bt_field_class *
988 fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept
990 return bt_field_class_structure_member_borrow_field_class_const(libObjPtr);
993 static const bt_value *
994 userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept
996 return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr);
1000 } /* namespace internal */
1002 template <typename LibObjT>
1003 class CommonStructureFieldClassMember final : public BorrowedObj<LibObjT>
1006 using typename BorrowedObj<LibObjT>::_LibObjPtr;
1007 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
1010 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1013 using UserAttributes =
1014 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1016 explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept :
1017 _ThisBorrowedObj {libObjPtr}
1021 template <typename OtherLibObjT>
1022 CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
1024 _ThisBorrowedObj {fc}
1028 template <typename OtherLibObjT>
1029 CommonStructureFieldClassMember<LibObjT>&
1030 operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
1032 _ThisBorrowedObj::operator=(fc);
1036 bpstd::string_view name() const noexcept
1038 return bt_field_class_structure_member_get_name(this->libObjPtr());
1041 ConstFieldClass fieldClass() const noexcept
1043 return ConstFieldClass {internal::CommonStructureFieldClassMemberSpec<
1044 const bt_field_class_structure_member>::fieldClass(this->libObjPtr())};
1047 _FieldClass fieldClass() noexcept
1049 return _FieldClass {
1050 internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())};
1053 template <typename LibValT>
1054 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1056 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1058 bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
1059 userAttrs.libObjPtr());
1062 ConstMapValue userAttributes() const noexcept
1064 return ConstMapValue {internal::CommonStructureFieldClassMemberSpec<
1065 const bt_field_class_structure_member>::userAttributes(this->libObjPtr())};
1068 UserAttributes userAttributes() noexcept
1070 return UserAttributes {
1071 internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes(
1072 this->libObjPtr())};
1076 using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>;
1078 using ConstStructureFieldClassMember =
1079 CommonStructureFieldClassMember<const bt_field_class_structure_member>;
1081 namespace internal {
1083 struct StructureFieldClassMemberTypeDescr
1085 using Const = ConstStructureFieldClassMember;
1086 using NonConst = StructureFieldClassMember;
1090 struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1095 struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1099 template <typename LibObjT>
1100 struct CommonStructureFieldClassSpec;
1102 /* Functions specific to mutable structure field classes */
1104 struct CommonStructureFieldClassSpec<bt_field_class> final
1106 static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr,
1107 const std::uint64_t index) noexcept
1109 return bt_field_class_structure_borrow_member_by_index(libObjPtr, index);
1112 static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr,
1113 const char * const name) noexcept
1115 return bt_field_class_structure_borrow_member_by_name(libObjPtr, name);
1119 /* Functions specific to constant structure field classes */
1121 struct CommonStructureFieldClassSpec<const bt_field_class> final
1123 static const bt_field_class_structure_member *
1124 memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
1126 return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index);
1129 static const bt_field_class_structure_member *
1130 memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
1132 return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name);
1136 } /* namespace internal */
1138 template <typename LibObjT>
1139 class CommonStructureFieldClass final : public CommonFieldClass<LibObjT>
1142 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1143 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1146 using Shared = internal::SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
1148 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember,
1149 StructureFieldClassMember>::type;
1151 using Iterator = CommonIterator<CommonStructureFieldClass<LibObjT>, Member>;
1153 explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept :
1154 _ThisCommonFieldClass {libObjPtr}
1156 BT_ASSERT_DBG(this->isStructure());
1159 template <typename OtherLibObjT>
1160 CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept :
1161 _ThisCommonFieldClass {fc}
1165 template <typename OtherLibObjT>
1166 CommonStructureFieldClass& operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
1168 _ThisCommonFieldClass::operator=(fc);
1172 void appendMember(const char * const name, const FieldClass fc)
1174 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1177 bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
1179 if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) {
1180 throw MemoryError {};
1184 void appendMember(const std::string& name, const FieldClass fc)
1186 this->appendMember(name.data(), fc);
1189 std::uint64_t size() const noexcept
1191 return bt_field_class_structure_get_member_count(this->libObjPtr());
1194 Iterator begin() const noexcept
1196 return Iterator {*this, 0};
1199 Iterator end() const noexcept
1201 return Iterator {*this, this->size()};
1204 ConstStructureFieldClassMember operator[](const std::uint64_t index) const noexcept
1206 return ConstStructureFieldClassMember {
1207 internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByIndex(
1208 this->libObjPtr(), index)};
1211 Member operator[](const std::uint64_t index) noexcept
1213 return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex(
1214 this->libObjPtr(), index)};
1217 nonstd::optional<ConstStructureFieldClassMember>
1218 operator[](const char * const name) const noexcept
1220 const auto libObjPtr =
1221 internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByName(
1222 this->libObjPtr(), name);
1225 return ConstStructureFieldClassMember {libObjPtr};
1228 return nonstd::nullopt;
1231 nonstd::optional<ConstStructureFieldClassMember>
1232 operator[](const std::string& name) const noexcept
1234 return (*this)[name.data()];
1237 nonstd::optional<Member> operator[](const char * const name) noexcept
1239 const auto libObjPtr =
1240 internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name);
1243 return Member {libObjPtr};
1246 return nonstd::nullopt;
1249 nonstd::optional<Member> operator[](const std::string& name) noexcept
1251 return (*this)[name.data()];
1254 Shared shared() const noexcept
1256 return Shared::createWithRef(*this);
1260 using StructureFieldClass = CommonStructureFieldClass<bt_field_class>;
1261 using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>;
1263 namespace internal {
1265 struct StructureFieldClassTypeDescr
1267 using Const = ConstStructureFieldClass;
1268 using NonConst = StructureFieldClass;
1272 struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr
1277 struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr
1281 template <typename LibObjT>
1282 struct CommonArrayFieldClassSpec;
1284 /* Functions specific to mutable array field classes */
1286 struct CommonArrayFieldClassSpec<bt_field_class> final
1288 static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept
1290 return bt_field_class_array_borrow_element_field_class(libObjPtr);
1294 /* Functions specific to constant array field classes */
1296 struct CommonArrayFieldClassSpec<const bt_field_class> final
1298 static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept
1300 return bt_field_class_array_borrow_element_field_class_const(libObjPtr);
1304 } /* namespace internal */
1306 template <typename LibObjT>
1307 class CommonArrayFieldClass : public CommonFieldClass<LibObjT>
1310 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1313 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1316 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1317 using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
1320 using Shared = internal::SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
1322 explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
1323 _ThisCommonFieldClass {libObjPtr}
1325 BT_ASSERT_DBG(this->isArray());
1328 template <typename OtherLibObjT>
1329 CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept :
1330 _ThisCommonFieldClass {fc}
1334 template <typename OtherLibObjT>
1335 CommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
1337 _ThisCommonFieldClass::operator=(fc);
1341 ConstFieldClass elementFieldClass() const noexcept
1343 return ConstFieldClass {
1344 internal::CommonArrayFieldClassSpec<const bt_field_class>::elementFieldClass(
1345 this->libObjPtr())};
1348 _FieldClass elementFieldClass() noexcept
1350 return _FieldClass {
1351 internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())};
1354 Shared shared() const noexcept
1356 return Shared::createWithRef(*this);
1360 using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>;
1361 using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>;
1363 namespace internal {
1365 struct ArrayFieldClassTypeDescr
1367 using Const = ConstArrayFieldClass;
1368 using NonConst = ArrayFieldClass;
1372 struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr
1377 struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr
1381 } /* namespace internal */
1383 template <typename LibObjT>
1384 class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT>
1387 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1388 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1391 using Shared = internal::SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
1393 explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
1394 _ThisCommonArrayFieldClass {libObjPtr}
1396 BT_ASSERT_DBG(this->isStaticArray());
1399 template <typename OtherLibObjT>
1400 CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept :
1401 _ThisCommonArrayFieldClass {fc}
1405 template <typename OtherLibObjT>
1406 CommonStaticArrayFieldClass&
1407 operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
1409 _ThisCommonArrayFieldClass::operator=(fc);
1413 std::uint64_t length() const noexcept
1415 return bt_field_class_array_static_get_length(this->libObjPtr());
1418 Shared shared() const noexcept
1420 return Shared::createWithRef(*this);
1424 using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>;
1425 using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>;
1427 namespace internal {
1429 struct StaticArrayFieldClassTypeDescr
1431 using Const = ConstStaticArrayFieldClass;
1432 using NonConst = StaticArrayFieldClass;
1436 struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1441 struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1445 } /* namespace internal */
1447 template <typename LibObjT>
1448 class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT>
1451 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1452 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1456 internal::SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
1458 explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept :
1459 _ThisCommonArrayFieldClass {libObjPtr}
1461 BT_ASSERT_DBG(this->isDynamicArrayWithLength());
1464 template <typename OtherLibObjT>
1465 CommonDynamicArrayWithLengthFieldClass(
1466 const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept :
1467 _ThisCommonArrayFieldClass {fc}
1471 template <typename OtherLibObjT>
1472 CommonDynamicArrayWithLengthFieldClass&
1473 operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
1475 _ThisCommonArrayFieldClass::operator=(fc);
1479 ConstFieldPath lengthFieldPath() const noexcept
1481 return ConstFieldPath {
1482 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
1483 this->libObjPtr())};
1486 Shared shared() const noexcept
1488 return Shared::createWithRef(*this);
1492 using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>;
1494 using ConstDynamicArrayWithLengthFieldClass =
1495 CommonDynamicArrayWithLengthFieldClass<const bt_field_class>;
1497 namespace internal {
1499 struct DynamicArrayWithLengthFieldClassTypeDescr
1501 using Const = ConstDynamicArrayWithLengthFieldClass;
1502 using NonConst = DynamicArrayWithLengthFieldClass;
1506 struct TypeDescr<DynamicArrayWithLengthFieldClass> :
1507 public DynamicArrayWithLengthFieldClassTypeDescr
1512 struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> :
1513 public DynamicArrayWithLengthFieldClassTypeDescr
1517 template <typename LibObjT>
1518 struct CommonOptionFieldClassSpec;
1520 /* Functions specific to mutable option field classes */
1522 struct CommonOptionFieldClassSpec<bt_field_class> final
1524 static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept
1526 return bt_field_class_option_borrow_field_class(libObjPtr);
1530 /* Functions specific to constant option field classes */
1532 struct CommonOptionFieldClassSpec<const bt_field_class> final
1534 static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept
1536 return bt_field_class_option_borrow_field_class_const(libObjPtr);
1540 } /* namespace internal */
1542 template <typename LibObjT>
1543 class CommonOptionFieldClass : public CommonFieldClass<LibObjT>
1546 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1549 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1552 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1553 using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
1556 using Shared = internal::SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
1558 explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept :
1559 _ThisCommonFieldClass {libObjPtr}
1561 BT_ASSERT_DBG(this->isOption());
1564 template <typename OtherLibObjT>
1565 CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept :
1566 _ThisCommonFieldClass {fc}
1570 template <typename OtherLibObjT>
1571 CommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
1573 _ThisCommonFieldClass::operator=(fc);
1577 ConstFieldClass fieldClass() const noexcept
1579 return ConstFieldClass {
1580 internal::CommonOptionFieldClassSpec<const bt_field_class>::fieldClass(
1581 this->libObjPtr())};
1584 _FieldClass fieldClass() noexcept
1586 return _FieldClass {
1587 internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())};
1590 Shared shared() const noexcept
1592 return Shared::createWithRef(*this);
1596 using OptionFieldClass = CommonOptionFieldClass<bt_field_class>;
1597 using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>;
1599 namespace internal {
1601 struct OptionFieldClassTypeDescr
1603 using Const = ConstOptionFieldClass;
1604 using NonConst = OptionFieldClass;
1608 struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr
1613 struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr
1617 } /* namespace internal */
1619 template <typename LibObjT>
1620 class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT>
1623 using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass;
1626 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1627 using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
1630 using Shared = internal::SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
1632 explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1633 _ThisCommonOptionFieldClass {libObjPtr}
1635 BT_ASSERT_DBG(this->isOptionWithSelector());
1638 template <typename OtherLibObjT>
1639 CommonOptionWithSelectorFieldClass(
1640 const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
1641 _ThisCommonOptionFieldClass {fc}
1645 template <typename OtherLibObjT>
1646 CommonOptionWithSelectorFieldClass&
1647 operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
1649 _ThisCommonOptionFieldClass::operator=(fc);
1653 ConstFieldPath selectorFieldPath() const noexcept
1655 return ConstFieldPath {
1656 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1657 this->libObjPtr())};
1660 Shared shared() const noexcept
1662 return Shared::createWithRef(*this);
1666 using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>;
1667 using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>;
1669 namespace internal {
1671 struct OptionWithSelectorFieldClassTypeDescr
1673 using Const = ConstOptionWithSelectorFieldClass;
1674 using NonConst = OptionWithSelectorFieldClass;
1678 struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1683 struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1687 } /* namespace internal */
1689 template <typename LibObjT>
1690 class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1693 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1695 using typename CommonOptionWithSelectorFieldClass<
1696 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1700 internal::SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
1702 explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1703 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1705 BT_ASSERT_DBG(this->isOptionWithBoolSelector());
1708 template <typename OtherLibObjT>
1709 CommonOptionWithBoolSelectorFieldClass(
1710 const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept :
1711 _ThisCommonOptionWithSelectorFieldClass {fc}
1715 template <typename OtherLibObjT>
1716 CommonOptionWithBoolSelectorFieldClass&
1717 operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
1719 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1723 bool selectorIsReversed() const noexcept
1725 return bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1729 Shared shared() const noexcept
1731 return Shared::createWithRef(*this);
1735 using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>;
1737 using ConstOptionWithBoolSelectorFieldClass =
1738 CommonOptionWithBoolSelectorFieldClass<const bt_field_class>;
1740 namespace internal {
1742 struct OptionWithBoolSelectorFieldClassTypeDescr
1744 using Const = ConstOptionWithBoolSelectorFieldClass;
1745 using NonConst = OptionWithBoolSelectorFieldClass;
1749 struct TypeDescr<OptionWithBoolSelectorFieldClass> :
1750 public OptionWithBoolSelectorFieldClassTypeDescr
1755 struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> :
1756 public OptionWithBoolSelectorFieldClassTypeDescr
1760 template <typename RangeSetT>
1761 struct CommonOptionWithIntegerSelectorFieldClassSpec;
1763 /* Functions specific to option field classes with unsigned integer ranges */
1765 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final
1767 static const bt_integer_range_set_unsigned *
1768 ranges(const bt_field_class * const libObjPtr) noexcept
1770 return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1775 /* Functions specific to option field classes with signed ranges */
1777 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final
1779 static const bt_integer_range_set_signed *
1780 ranges(const bt_field_class * const libObjPtr) noexcept
1782 return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1787 } /* namespace internal */
1789 template <typename LibObjT, typename RangeSetT>
1790 class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1793 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1795 using typename CommonOptionWithSelectorFieldClass<
1796 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1798 using _ThisCommonOptionWithIntegerSelectorFieldClass =
1799 CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
1803 internal::SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
1805 using RangeSet = RangeSetT;
1807 explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1808 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1810 BT_ASSERT_DBG(this->isOptionWithIntegerSelector());
1813 template <typename OtherLibObjT>
1814 CommonOptionWithIntegerSelectorFieldClass(
1815 const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept :
1816 _ThisCommonOptionWithSelectorFieldClass {fc}
1820 template <typename OtherLibObjT>
1821 CommonOptionWithIntegerSelectorFieldClass&
1822 operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
1824 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1828 RangeSet ranges() const noexcept
1830 return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges(
1831 this->libObjPtr())};
1834 Shared shared() const noexcept
1836 return Shared::createWithRef(*this);
1840 using OptionWithUnsignedIntegerSelectorFieldClass =
1841 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>;
1843 using ConstOptionWithUnsignedIntegerSelectorFieldClass =
1844 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>;
1846 using OptionWithSignedIntegerSelectorFieldClass =
1847 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>;
1849 using ConstOptionWithSignedIntegerSelectorFieldClass =
1850 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>;
1852 namespace internal {
1854 struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1856 using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass;
1857 using NonConst = OptionWithUnsignedIntegerSelectorFieldClass;
1861 struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> :
1862 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1867 struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> :
1868 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1872 struct OptionWithSignedIntegerSelectorFieldClassTypeDescr
1874 using Const = ConstOptionWithSignedIntegerSelectorFieldClass;
1875 using NonConst = OptionWithSignedIntegerSelectorFieldClass;
1879 struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> :
1880 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1885 struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> :
1886 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1890 template <typename LibObjT>
1891 struct CommonVariantFieldClassOptionSpec;
1893 /* Functions specific to mutable variant field class options */
1895 struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final
1897 static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept
1899 return bt_field_class_variant_option_borrow_field_class(libObjPtr);
1902 static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept
1904 return bt_field_class_variant_option_borrow_user_attributes(libObjPtr);
1908 /* Functions specific to constant variant field class options */
1910 struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final
1912 static const bt_field_class *
1913 fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept
1915 return bt_field_class_variant_option_borrow_field_class_const(libObjPtr);
1918 static const bt_value *
1919 userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept
1921 return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr);
1925 } /* namespace internal */
1927 template <typename LibObjT>
1928 class CommonVariantFieldClassOption : public BorrowedObj<LibObjT>
1931 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
1932 using typename BorrowedObj<LibObjT>::_LibObjPtr;
1935 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1938 using UserAttributes =
1939 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1941 explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
1942 _ThisBorrowedObj {libObjPtr}
1946 template <typename OtherLibObjT>
1947 CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept :
1948 _ThisBorrowedObj {fc}
1952 template <typename OtherLibObjT>
1953 CommonVariantFieldClassOption&
1954 operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
1956 _ThisBorrowedObj::operator=(fc);
1960 nonstd::optional<bpstd::string_view> name() const noexcept
1962 const auto name = bt_field_class_variant_option_get_name(this->libObjPtr());
1968 return nonstd::nullopt;
1971 ConstFieldClass fieldClass() const noexcept
1973 return ConstFieldClass {internal::CommonVariantFieldClassOptionSpec<
1974 const bt_field_class_variant_option>::fieldClass(this->libObjPtr())};
1977 _FieldClass fieldClass() noexcept
1979 return _FieldClass {
1980 internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())};
1983 template <typename LibValT>
1984 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1986 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1988 bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1991 ConstMapValue userAttributes() const noexcept
1993 return ConstMapValue {internal::CommonVariantFieldClassOptionSpec<
1994 const bt_field_class_variant_option>::userAttributes(this->libObjPtr())};
1997 UserAttributes userAttributes() noexcept
1999 return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes(
2000 this->libObjPtr())};
2004 using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>;
2006 using ConstVariantFieldClassOption =
2007 CommonVariantFieldClassOption<const bt_field_class_variant_option>;
2009 namespace internal {
2011 struct VariantFieldClassOptionTypeDescr
2013 using Const = ConstVariantFieldClassOption;
2014 using NonConst = VariantFieldClassOption;
2018 struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
2023 struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
2027 template <typename LibObjT>
2028 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec;
2030 /* Functions specific to variant field class options with unsigned integer selector */
2032 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
2033 const bt_field_class_variant_with_selector_field_integer_unsigned_option>
2036 static const bt_integer_range_set_unsigned *
2037 ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option
2038 * const libObjPtr) noexcept
2040 return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
2044 static const bt_field_class_variant_option *
2045 asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option
2046 * const libObjPtr) noexcept
2048 return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const(
2053 /* Functions specific to variant field class options with signed integer selector */
2055 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
2056 const bt_field_class_variant_with_selector_field_integer_signed_option>
2059 static const bt_integer_range_set_signed *
2060 ranges(const bt_field_class_variant_with_selector_field_integer_signed_option
2061 * const libObjPtr) noexcept
2063 return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
2067 static const bt_field_class_variant_option *
2068 asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option
2069 * const libObjPtr) noexcept
2071 return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const(
2076 } /* namespace internal */
2078 template <typename LibObjT>
2079 class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObj<LibObjT>
2082 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
2083 using typename BorrowedObj<LibObjT>::_LibObjPtr;
2084 using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
2087 using RangeSet = typename std::conditional<
2090 const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value,
2091 ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
2093 explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
2094 _ThisBorrowedObj {libObjPtr}
2098 template <typename OtherLibObjT>
2099 ConstVariantWithIntegerSelectorFieldClassOption(
2100 const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept :
2101 _ThisBorrowedObj {fc}
2105 template <typename OtherLibObjT>
2106 ConstVariantWithIntegerSelectorFieldClassOption&
2107 operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
2109 _ThisBorrowedObj::operator=(fc);
2113 ConstVariantFieldClassOption asBaseOption() const noexcept
2115 return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
2118 nonstd::optional<bpstd::string_view> name() const noexcept
2120 return this->asBaseOption().name();
2123 ConstFieldClass fieldClass() const noexcept
2125 return this->asBaseOption().fieldClass();
2128 RangeSet ranges() const noexcept
2130 return RangeSet {_Spec::ranges(this->libObjPtr())};
2134 using ConstVariantWithUnsignedIntegerSelectorFieldClassOption =
2135 ConstVariantWithIntegerSelectorFieldClassOption<
2136 const bt_field_class_variant_with_selector_field_integer_unsigned_option>;
2138 using ConstVariantWithSignedIntegerSelectorFieldClassOption =
2139 ConstVariantWithIntegerSelectorFieldClassOption<
2140 const bt_field_class_variant_with_selector_field_integer_signed_option>;
2142 namespace internal {
2144 template <typename LibObjT>
2145 struct CommonVariantFieldClassSpec;
2147 /* Functions specific to mutable variant field classes */
2149 struct CommonVariantFieldClassSpec<bt_field_class> final
2151 static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr,
2152 const std::uint64_t index) noexcept
2154 return bt_field_class_variant_borrow_option_by_index(libObjPtr, index);
2157 static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr,
2158 const char * const name) noexcept
2160 return bt_field_class_variant_borrow_option_by_name(libObjPtr, name);
2164 /* Functions specific to constant variant field classes */
2166 struct CommonVariantFieldClassSpec<const bt_field_class> final
2168 static const bt_field_class_variant_option *
2169 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2171 return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index);
2174 static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr,
2175 const char * const name) noexcept
2177 return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name);
2181 } /* namespace internal */
2183 template <typename LibObjT>
2184 class CommonVariantFieldClass : public CommonFieldClass<LibObjT>
2187 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
2190 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2191 using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
2194 using Shared = internal::SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
2197 typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption,
2198 VariantFieldClassOption>::type;
2200 using Iterator = CommonIterator<CommonVariantFieldClass, Option>;
2202 explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept :
2203 _ThisCommonFieldClass {libObjPtr}
2205 BT_ASSERT_DBG(this->isVariant());
2208 template <typename OtherLibObjT>
2209 CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept :
2210 _ThisCommonFieldClass {fc}
2214 template <typename OtherLibObjT>
2215 CommonVariantFieldClass& operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
2217 _ThisCommonFieldClass::operator=(fc);
2221 std::uint64_t size() const noexcept
2223 return bt_field_class_variant_get_option_count(this->libObjPtr());
2226 Iterator begin() const noexcept
2228 return Iterator {*this, 0};
2231 Iterator end() const noexcept
2233 return Iterator {*this, this->size()};
2236 ConstVariantFieldClassOption operator[](const std::uint64_t index) const noexcept
2238 return ConstVariantFieldClassOption {
2239 internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByIndex(
2240 this->libObjPtr(), index)};
2243 Option operator[](const std::uint64_t index) noexcept
2245 return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex(
2246 this->libObjPtr(), index)};
2249 nonstd::optional<ConstVariantFieldClassOption>
2250 operator[](const char * const name) const noexcept
2252 const auto libObjPtr =
2253 internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByName(
2254 this->libObjPtr(), name);
2257 return ConstVariantFieldClassOption {libObjPtr};
2260 return nonstd::nullopt;
2263 nonstd::optional<ConstVariantFieldClassOption>
2264 operator[](const std::string& name) const noexcept
2266 return (*this)[name.data()];
2269 nonstd::optional<Option> operator[](const char * const name) noexcept
2271 const auto libObjPtr =
2272 internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name);
2275 return Option {libObjPtr};
2278 return nonstd::nullopt;
2281 nonstd::optional<Option> operator[](const std::string& name) noexcept
2283 return (*this)[name.data()];
2286 Shared shared() const noexcept
2288 return Shared::createWithRef(*this);
2292 using VariantFieldClass = CommonVariantFieldClass<bt_field_class>;
2293 using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>;
2295 namespace internal {
2297 struct VariantFieldClassTypeDescr
2299 using Const = ConstVariantFieldClass;
2300 using NonConst = VariantFieldClass;
2304 struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr
2309 struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr
2313 } /* namespace internal */
2315 template <typename LibObjT>
2316 class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2319 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2320 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2324 internal::SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
2326 explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2327 _ThisCommonVariantFieldClass {libObjPtr}
2329 BT_ASSERT_DBG(this->isVariantWithoutSelector());
2332 template <typename OtherLibObjT>
2333 CommonVariantWithoutSelectorFieldClass(
2334 const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept :
2335 _ThisCommonVariantFieldClass {fc}
2339 template <typename OtherLibObjT>
2340 CommonVariantWithoutSelectorFieldClass&
2341 operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
2343 _ThisCommonVariantFieldClass::operator=(fc);
2347 void appendOption(const char * const name, const FieldClass fc)
2349 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2351 const auto status = bt_field_class_variant_without_selector_append_option(
2352 this->libObjPtr(), name, fc.libObjPtr());
2355 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2356 throw MemoryError {};
2360 void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc)
2362 this->appendOption(name ? name->data() : nullptr, fc);
2365 Shared shared() const noexcept
2367 return Shared::createWithRef(*this);
2371 using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>;
2372 using ConstVariantWithoutSelectorFieldClass =
2373 CommonVariantWithoutSelectorFieldClass<const bt_field_class>;
2375 namespace internal {
2377 struct VariantWithoutSelectorFieldClassTypeDescr
2379 using Const = ConstVariantWithoutSelectorFieldClass;
2380 using NonConst = VariantWithoutSelectorFieldClass;
2384 struct TypeDescr<VariantWithoutSelectorFieldClass> :
2385 public VariantWithoutSelectorFieldClassTypeDescr
2390 struct TypeDescr<ConstVariantWithoutSelectorFieldClass> :
2391 public VariantWithoutSelectorFieldClassTypeDescr
2395 template <typename OptionT>
2396 struct CommonVariantWithIntegerSelectorFieldClassSpec;
2398 /* Functions specific to variant field classes with unsigned integer selector */
2400 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2401 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2404 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2405 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2407 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
2411 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2412 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2414 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
2418 static bt_field_class_variant_with_selector_field_integer_append_option_status
2419 appendOption(bt_field_class * const libObjPtr, const char * const name,
2420 bt_field_class * const libOptFcPtr,
2421 const bt_integer_range_set_unsigned * const libRangesPtr)
2423 return bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
2424 libObjPtr, name, libOptFcPtr, libRangesPtr);
2428 /* Functions specific to variant field classes with signed integer selector */
2430 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2431 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2434 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2435 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2437 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
2441 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2442 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2444 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
2448 static bt_field_class_variant_with_selector_field_integer_append_option_status
2449 appendOption(bt_field_class * const libObjPtr, const char * const name,
2450 bt_field_class * const libOptFcPtr,
2451 const bt_integer_range_set_signed * const libRangesPtr)
2453 return bt_field_class_variant_with_selector_field_integer_signed_append_option(
2454 libObjPtr, name, libOptFcPtr, libRangesPtr);
2458 } /* namespace internal */
2460 template <typename LibObjT>
2461 class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2464 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2467 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2468 using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
2471 using Shared = internal::SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
2473 explicit CommonVariantWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2474 _ThisCommonVariantFieldClass {libObjPtr}
2476 BT_ASSERT_DBG(this->isVariantWithSelector());
2479 template <typename OtherLibObjT>
2480 CommonVariantWithSelectorFieldClass(
2481 const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
2482 _ThisCommonVariantFieldClass {fc}
2486 template <typename OtherLibObjT>
2487 CommonVariantWithSelectorFieldClass&
2488 operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
2490 _ThisCommonVariantFieldClass::operator=(fc);
2494 ConstFieldPath selectorFieldPath() const noexcept
2496 return ConstFieldPath {
2497 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
2498 this->libObjPtr())};
2501 Shared shared() const noexcept
2503 return Shared::createWithRef(*this);
2507 using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>;
2508 using ConstVariantWithSelectorFieldClass =
2509 CommonVariantWithSelectorFieldClass<const bt_field_class>;
2511 template <typename LibObjT, typename OptionT>
2512 class CommonVariantWithIntegerSelectorFieldClass :
2513 public CommonVariantWithSelectorFieldClass<LibObjT>
2516 using typename CommonVariantWithSelectorFieldClass<
2517 LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
2518 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2519 using _ThisCommonVariantWithIntegerSelectorFieldClass =
2520 CommonVariantWithIntegerSelectorFieldClass<LibObjT, OptionT>;
2522 using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
2526 internal::SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
2528 using Option = OptionT;
2530 CommonIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>, Option>;
2532 explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2533 _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
2535 BT_ASSERT_DBG(this->isVariant());
2538 template <typename OtherLibObjT>
2539 CommonVariantWithIntegerSelectorFieldClass(
2540 const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept :
2541 _ThisCommonVariantWithSelectorFieldClass {fc}
2545 template <typename OtherLibObjT>
2546 CommonVariantWithIntegerSelectorFieldClass&
2547 operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
2549 _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
2553 Option operator[](const std::uint64_t index) const noexcept
2555 return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
2558 nonstd::optional<Option> operator[](const char * const name) const noexcept
2560 const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name);
2563 return Option {libObjPtr};
2566 return nonstd::nullopt;
2569 nonstd::optional<Option> operator[](const std::string& name) const noexcept
2571 return (*this)[name.data()];
2574 void appendOption(const char * const name, const FieldClass fc,
2575 const typename Option::RangeSet ranges)
2577 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2580 _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr());
2583 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2584 throw MemoryError {};
2588 void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc,
2589 const typename Option::RangeSet ranges)
2591 this->appendOption(name ? name->data() : nullptr, fc, ranges);
2594 Iterator begin() const noexcept
2596 return Iterator {*this, 0};
2599 Iterator end() const noexcept
2601 return Iterator {*this, this->size()};
2604 Shared shared() const noexcept
2606 return Shared::createWithRef(*this);
2610 using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2611 bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2613 using ConstVariantWithUnsignedIntegerSelectorFieldClass =
2614 CommonVariantWithIntegerSelectorFieldClass<
2615 const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2617 using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2618 bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2620 using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2621 const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2623 namespace internal {
2625 struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2627 using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass;
2628 using NonConst = VariantWithUnsignedIntegerSelectorFieldClass;
2632 struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> :
2633 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2638 struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> :
2639 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2643 struct VariantWithSignedIntegerSelectorFieldClassTypeDescr
2645 using Const = ConstVariantWithSignedIntegerSelectorFieldClass;
2646 using NonConst = VariantWithSignedIntegerSelectorFieldClass;
2650 struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> :
2651 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2656 struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> :
2657 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2661 } /* namespace internal */
2663 template <typename LibObjT>
2664 CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept
2666 BT_ASSERT_DBG(this->isBitArray());
2667 return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()};
2670 template <typename LibObjT>
2671 CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept
2673 BT_ASSERT_DBG(this->isInteger());
2674 return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()};
2677 template <typename LibObjT>
2678 CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept
2680 BT_ASSERT_DBG(this->isEnumeration());
2681 return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()};
2684 template <typename LibObjT>
2685 CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping>
2686 CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept
2688 BT_ASSERT_DBG(this->isUnsignedEnumeration());
2689 return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> {
2693 template <typename LibObjT>
2694 CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping>
2695 CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept
2697 BT_ASSERT_DBG(this->isSignedEnumeration());
2698 return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> {
2702 template <typename LibObjT>
2703 CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept
2705 BT_ASSERT_DBG(this->isStructure());
2706 return CommonStructureFieldClass<LibObjT> {this->libObjPtr()};
2709 template <typename LibObjT>
2710 CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept
2712 BT_ASSERT_DBG(this->isArray());
2713 return CommonArrayFieldClass<LibObjT> {this->libObjPtr()};
2716 template <typename LibObjT>
2717 CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept
2719 BT_ASSERT_DBG(this->isStaticArray());
2720 return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()};
2723 template <typename LibObjT>
2724 CommonDynamicArrayWithLengthFieldClass<LibObjT>
2725 CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept
2727 BT_ASSERT_DBG(this->isDynamicArrayWithLength());
2728 return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()};
2731 template <typename LibObjT>
2732 CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept
2734 BT_ASSERT_DBG(this->isOption());
2735 return CommonOptionFieldClass<LibObjT> {this->libObjPtr()};
2738 template <typename LibObjT>
2739 CommonOptionWithSelectorFieldClass<LibObjT>
2740 CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept
2742 BT_ASSERT_DBG(this->isOptionWithSelector());
2743 return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2746 template <typename LibObjT>
2747 CommonOptionWithBoolSelectorFieldClass<LibObjT>
2748 CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept
2750 BT_ASSERT_DBG(this->isOptionWithBoolSelector());
2751 return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()};
2754 template <typename LibObjT>
2755 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet>
2756 CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept
2758 BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector());
2759 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> {
2763 template <typename LibObjT>
2764 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet>
2765 CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept
2767 BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector());
2768 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> {
2772 template <typename LibObjT>
2773 CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept
2775 BT_ASSERT_DBG(this->isVariant());
2776 return CommonVariantFieldClass<LibObjT> {this->libObjPtr()};
2779 template <typename LibObjT>
2780 CommonVariantWithoutSelectorFieldClass<LibObjT>
2781 CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept
2783 BT_ASSERT_DBG(this->isVariantWithoutSelector());
2784 return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()};
2787 template <typename LibObjT>
2788 CommonVariantWithSelectorFieldClass<LibObjT>
2789 CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept
2791 BT_ASSERT_DBG(this->isVariantWithSelector());
2792 return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2795 template <typename LibObjT>
2796 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2797 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2798 CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept
2800 BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector());
2801 return CommonVariantWithIntegerSelectorFieldClass<
2802 LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2805 template <typename LibObjT>
2806 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2807 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2808 CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept
2810 BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector());
2811 return CommonVariantWithIntegerSelectorFieldClass<
2812 LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2815 } /* namespace bt2 */
2817 #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */