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/bt2c/c-string-view.hpp"
17 #include "cpp-common/bt2s/optional.hpp"
19 #include "borrowed-object-iterator.hpp"
20 #include "borrowed-object.hpp"
22 #include "field-path.hpp"
23 #include "integer-range-set.hpp"
24 #include "internal/utils.hpp"
25 #include "optional-borrowed-object.hpp"
26 #include "shared-object.hpp"
32 struct FieldClassRefFuncs final
34 static void get(const bt_field_class * const libObjPtr) noexcept
36 bt_field_class_get_ref(libObjPtr);
39 static void put(const bt_field_class * const libObjPtr) noexcept
41 bt_field_class_put_ref(libObjPtr);
45 template <typename LibObjT>
46 struct CommonFieldClassSpec;
48 /* Functions specific to mutable field classes */
50 struct CommonFieldClassSpec<bt_field_class> final
52 static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept
54 return bt_field_class_borrow_user_attributes(libObjPtr);
58 /* Functions specific to constant field classes */
60 struct CommonFieldClassSpec<const bt_field_class> final
62 static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept
64 return bt_field_class_borrow_user_attributes_const(libObjPtr);
68 } /* namespace internal */
70 template <typename ObjT, typename LibObjT>
71 using SharedFieldClass = SharedObject<ObjT, LibObjT, internal::FieldClassRefFuncs>;
73 template <typename LibObjT>
74 class CommonBitArrayFieldClass;
76 template <typename LibObjT>
77 class CommonIntegerFieldClass;
79 template <typename LibObjT>
80 class ConstEnumerationFieldClassMapping;
82 template <typename LibObjT>
83 class CommonBaseEnumerationFieldClass;
85 template <typename LibObjT, typename MappingT>
86 class CommonEnumerationFieldClass;
88 template <typename LibObjT>
89 class CommonStructureFieldClass;
91 template <typename LibObjT>
92 class CommonArrayFieldClass;
94 template <typename LibObjT>
95 class CommonStaticArrayFieldClass;
97 template <typename LibObjT>
98 class CommonDynamicArrayWithLengthFieldClass;
100 template <typename LibObjT>
101 class CommonOptionFieldClass;
103 template <typename LibObjT>
104 class CommonOptionWithSelectorFieldClass;
106 template <typename LibObjT>
107 class CommonOptionWithBoolSelectorFieldClass;
109 template <typename LibObjT>
110 class CommonVariantFieldClass;
112 template <typename LibObjT, typename RangeSetT>
113 class CommonOptionWithIntegerSelectorFieldClass;
115 template <typename LibObjT>
116 class CommonVariantWithoutSelectorFieldClass;
118 template <typename LibObjT>
119 class CommonVariantWithSelectorFieldClass;
121 template <typename LibObjT>
122 class ConstVariantWithIntegerSelectorFieldClassOption;
124 template <typename LibObjT, typename RangeSetT>
125 class CommonVariantWithIntegerSelectorFieldClass;
127 template <typename LibObjT>
128 class CommonEventClass;
130 template <typename LibObjT>
131 class CommonStreamClass;
133 template <typename LibObjT>
134 class CommonTraceClass;
136 enum class FieldClassType
138 Bool = BT_FIELD_CLASS_TYPE_BOOL,
139 BitArray = BT_FIELD_CLASS_TYPE_BIT_ARRAY,
140 UnsignedInteger = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER,
141 SignedInteger = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER,
142 UnsignedEnumeration = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION,
143 SignedEnumeration = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION,
144 SinglePrecisionReal = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL,
145 DoublePrecisionReal = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL,
146 String = BT_FIELD_CLASS_TYPE_STRING,
147 Structure = BT_FIELD_CLASS_TYPE_STRUCTURE,
148 StaticArray = BT_FIELD_CLASS_TYPE_STATIC_ARRAY,
149 DynamicArrayWithoutLength = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD,
150 DynamicArrayWithLength = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD,
151 OptionWithoutSelector = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD,
152 OptionWithBoolSelector = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD,
153 OptionWithUnsignedIntegerSelector =
154 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
155 OptionWithSignedIntegerSelector = BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
156 VariantWithoutSelector = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD,
157 VariantWithUnsignedIntegerSelector =
158 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD,
159 VariantWithSignedIntegerSelector =
160 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD,
163 template <typename LibObjT>
164 class CommonFieldClass : public BorrowedObject<LibObjT>
167 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
170 using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
173 using typename BorrowedObject<LibObjT>::LibObjPtr;
174 using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
175 using UserAttributes = internal::DepUserAttrs<LibObjT>;
177 explicit CommonFieldClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
181 template <typename OtherLibObjT>
182 CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObject {fc}
186 template <typename OtherLibObjT>
187 CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
189 _ThisBorrowedObject::operator=(fc);
193 CommonFieldClass<const bt_field_class> asConst() const noexcept
195 return CommonFieldClass<const bt_field_class> {*this};
198 FieldClassType type() const noexcept
200 return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr()));
203 bool isBool() const noexcept
205 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BOOL);
208 bool isBitArray() const noexcept
210 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BIT_ARRAY);
213 bool isInteger() const noexcept
215 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_INTEGER);
218 bool isUnsignedInteger() const noexcept
220 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
223 bool isSignedInteger() const noexcept
225 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
228 bool isEnumeration() const noexcept
230 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ENUMERATION);
233 bool isUnsignedEnumeration() const noexcept
235 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION);
238 bool isSignedEnumeration() const noexcept
240 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
243 bool isReal() const noexcept
245 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_REAL);
248 bool isSinglePrecisionReal() const noexcept
250 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
253 bool isDoublePrecisionReal() const noexcept
255 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL);
258 bool isString() const noexcept
260 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRING);
263 bool isStructure() const noexcept
265 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRUCTURE);
268 bool isArray() const noexcept
270 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ARRAY);
273 bool isStaticArray() const noexcept
275 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STATIC_ARRAY);
278 bool isDynamicArray() const noexcept
280 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
283 bool isDynamicArrayWithoutLength() const noexcept
285 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD);
288 bool isDynamicArrayWithLength() const noexcept
290 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD);
293 bool isOption() const noexcept
295 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION);
298 bool isOptionWithoutSelector() const noexcept
300 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD);
303 bool isOptionWithSelector() const noexcept
305 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD);
308 bool isOptionWithBoolSelector() const noexcept
310 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD);
313 bool isOptionWithIntegerSelector() const noexcept
315 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_INTEGER_SELECTOR_FIELD);
318 bool isOptionWithUnsignedIntegerSelector() const noexcept
320 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD);
323 bool isOptionWithSignedIntegerSelector() const noexcept
325 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
328 bool isVariant() const noexcept
330 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT);
333 bool isVariantWithoutSelector() const noexcept
335 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD);
338 bool isVariantWithSelector() const noexcept
340 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD);
343 bool isVariantWithIntegerSelector() const noexcept
345 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_INTEGER_SELECTOR_FIELD);
348 bool isVariantWithUnsignedIntegerSelector() const noexcept
350 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD);
353 bool isVariantWithSignedIntegerSelector() const noexcept
355 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
358 template <typename FieldClassT>
359 FieldClassT as() const noexcept
361 return FieldClassT {this->libObjPtr()};
364 CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept;
365 CommonIntegerFieldClass<LibObjT> asInteger() const noexcept;
366 CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept;
367 CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping<
368 const bt_field_class_enumeration_unsigned_mapping>>
369 asUnsignedEnumeration() const noexcept;
371 CommonEnumerationFieldClass<
372 LibObjT, ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>>
373 asSignedEnumeration() const noexcept;
375 CommonStructureFieldClass<LibObjT> asStructure() const noexcept;
376 CommonArrayFieldClass<LibObjT> asArray() const noexcept;
377 CommonStaticArrayFieldClass<LibObjT> asStaticArray() const noexcept;
378 CommonDynamicArrayWithLengthFieldClass<LibObjT> asDynamicArrayWithLength() const noexcept;
379 CommonOptionFieldClass<LibObjT> asOption() const noexcept;
380 CommonOptionWithSelectorFieldClass<LibObjT> asOptionWithSelector() const noexcept;
381 CommonOptionWithBoolSelectorFieldClass<LibObjT> asOptionWithBoolSelector() const noexcept;
383 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet>
384 asOptionWithUnsignedIntegerSelector() const noexcept;
386 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet>
387 asOptionWithSignedIntegerSelector() const noexcept;
389 CommonVariantFieldClass<LibObjT> asVariant() const noexcept;
390 CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept;
391 CommonVariantWithSelectorFieldClass<LibObjT> asVariantWithSelector() const noexcept;
393 CommonVariantWithIntegerSelectorFieldClass<
394 LibObjT, ConstVariantWithIntegerSelectorFieldClassOption<
395 const bt_field_class_variant_with_selector_field_integer_unsigned_option>>
396 asVariantWithUnsignedIntegerSelector() const noexcept;
398 CommonVariantWithIntegerSelectorFieldClass<
399 LibObjT, ConstVariantWithIntegerSelectorFieldClassOption<
400 const bt_field_class_variant_with_selector_field_integer_signed_option>>
401 asVariantWithSignedIntegerSelector() const noexcept;
403 template <typename LibValT>
404 CommonFieldClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
406 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstFieldClass`.");
408 bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
412 UserAttributes userAttributes() const noexcept
414 return UserAttributes {
415 internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
418 Shared shared() const noexcept
420 return Shared::createWithRef(*this);
424 bool _libTypeIs(const bt_field_class_type type) const noexcept
426 return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type);
430 using FieldClass = CommonFieldClass<bt_field_class>;
431 using ConstFieldClass = CommonFieldClass<const bt_field_class>;
435 struct FieldClassTypeDescr
437 using Const = ConstFieldClass;
438 using NonConst = FieldClass;
442 struct TypeDescr<FieldClass> : public FieldClassTypeDescr
447 struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr
451 } /* namespace internal */
453 template <typename LibObjT>
454 class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT>
457 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
460 using typename CommonFieldClass<LibObjT>::LibObjPtr;
461 using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
463 explicit CommonBitArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
464 _ThisCommonFieldClass {libObjPtr}
466 BT_ASSERT_DBG(this->isBitArray());
469 template <typename OtherLibObjT>
470 CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept :
471 _ThisCommonFieldClass {fc}
475 template <typename OtherLibObjT>
476 CommonBitArrayFieldClass<LibObjT>
477 operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
479 _ThisCommonFieldClass::operator=(fc);
483 CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept
485 return CommonBitArrayFieldClass<const bt_field_class> {*this};
488 std::uint64_t length() const noexcept
490 return bt_field_class_bit_array_get_length(this->libObjPtr());
493 Shared shared() const noexcept
495 return Shared::createWithRef(*this);
499 using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>;
500 using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>;
504 struct BitArrayFieldClassTypeDescr
506 using Const = ConstBitArrayFieldClass;
507 using NonConst = BitArrayFieldClass;
511 struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr
516 struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr
520 } /* namespace internal */
522 enum class DisplayBase
524 Binary = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY,
525 Octal = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL,
526 Decimal = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
527 Hexadecimal = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL,
530 template <typename LibObjT>
531 class CommonIntegerFieldClass : public CommonFieldClass<LibObjT>
534 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
537 using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
540 using typename CommonFieldClass<LibObjT>::LibObjPtr;
541 using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
543 explicit CommonIntegerFieldClass(const LibObjPtr libObjPtr) noexcept :
544 _ThisCommonFieldClass {libObjPtr}
546 BT_ASSERT_DBG(this->isInteger());
549 template <typename OtherLibObjT>
550 CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept :
551 _ThisCommonFieldClass {fc}
555 template <typename OtherLibObjT>
556 CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
558 _ThisCommonFieldClass::operator=(fc);
562 CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept
564 return CommonIntegerFieldClass<const bt_field_class> {*this};
567 CommonIntegerFieldClass fieldValueRange(const std::uint64_t n) const noexcept
569 static_assert(!std::is_const<LibObjT>::value,
570 "Not available with `bt2::ConstIntegerFieldClass`.");
572 bt_field_class_integer_set_field_value_range(this->libObjPtr(), n);
576 std::uint64_t fieldValueRange() const noexcept
578 return bt_field_class_integer_get_field_value_range(this->libObjPtr());
581 CommonIntegerFieldClass preferredDisplayBase(const DisplayBase base) const noexcept
583 static_assert(!std::is_const<LibObjT>::value,
584 "Not available with `bt2::ConstIntegerFieldClass`.");
586 bt_field_class_integer_set_preferred_display_base(
587 this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
591 DisplayBase preferredDisplayBase() const noexcept
593 return static_cast<DisplayBase>(
594 bt_field_class_integer_get_preferred_display_base(this->libObjPtr()));
597 Shared shared() const noexcept
599 return Shared::createWithRef(*this);
603 using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>;
604 using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>;
608 struct IntegerFieldClassTypeDescr
610 using Const = ConstIntegerFieldClass;
611 using NonConst = IntegerFieldClass;
615 struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr
620 struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
624 template <typename LibObjT>
625 struct ConstEnumerationFieldClassMappingSpec;
627 /* Functions specific to unsigned enumeration field class mappings */
629 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping>
632 static const bt_integer_range_set_unsigned *
633 ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
635 return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr);
639 label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
641 return bt_field_class_enumeration_mapping_get_label(
642 bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr));
646 /* Functions specific to signed enumeration field class mappings */
648 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final
650 static const bt_integer_range_set_signed *
651 ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
653 return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr);
657 label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
659 return bt_field_class_enumeration_mapping_get_label(
660 bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr));
664 } /* namespace internal */
666 template <typename LibObjT>
667 class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT>
670 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
673 using typename BorrowedObject<LibObjT>::LibObjPtr;
675 using RangeSet = typename std::conditional<
676 std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value,
677 ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
679 explicit ConstEnumerationFieldClassMapping(const LibObjPtr libObjPtr) noexcept :
680 _ThisBorrowedObject {libObjPtr}
684 ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept :
685 _ThisBorrowedObject {mapping}
689 ConstEnumerationFieldClassMapping
690 operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept
692 _ThisBorrowedObject::operator=(mapping);
696 RangeSet ranges() const noexcept
699 internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
702 bt2c::CStringView label() const noexcept
704 return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
708 using ConstUnsignedEnumerationFieldClassMapping =
709 ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_unsigned_mapping>;
711 using ConstSignedEnumerationFieldClassMapping =
712 ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>;
716 template <typename MappingT>
717 struct CommonEnumerationFieldClassSpec;
719 /* Functions specific to unsigned enumeration field classes */
721 struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping> final
723 static const bt_field_class_enumeration_unsigned_mapping *
724 mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
726 return bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(libObjPtr, index);
729 static const bt_field_class_enumeration_unsigned_mapping *
730 mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept
732 return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label);
735 static bt_field_class_enumeration_add_mapping_status
736 addMapping(bt_field_class * const libObjPtr, const char * const label,
737 const bt_integer_range_set_unsigned * const libRanges) noexcept
739 return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges);
743 /* Functions specific to signed enumeration field classes */
745 struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping> final
747 static const bt_field_class_enumeration_signed_mapping *
748 mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
750 return bt_field_class_enumeration_signed_borrow_mapping_by_index_const(libObjPtr, index);
753 static const bt_field_class_enumeration_signed_mapping *
754 mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept
756 return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label);
759 static bt_field_class_enumeration_add_mapping_status
760 addMapping(bt_field_class * const libObjPtr, const char * const label,
761 const bt_integer_range_set_signed * const libRanges) noexcept
763 return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges);
767 } /* namespace internal */
769 template <typename LibObjT>
770 class CommonBaseEnumerationFieldClass : public CommonIntegerFieldClass<LibObjT>
773 using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass;
776 using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
779 using typename CommonFieldClass<LibObjT>::LibObjPtr;
780 using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
782 explicit CommonBaseEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept :
783 _ThisCommonIntegerFieldClass {libObjPtr}
785 BT_ASSERT_DBG(this->isEnumeration());
788 template <typename OtherLibObjT>
789 CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
791 _ThisCommonIntegerFieldClass {fc}
795 template <typename OtherLibObjT>
796 CommonBaseEnumerationFieldClass
797 operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
799 _ThisCommonIntegerFieldClass::operator=(fc);
803 CommonBaseEnumerationFieldClass<const bt_field_class> asConst() const noexcept
805 return CommonBaseEnumerationFieldClass<const bt_field_class> {*this};
808 std::uint64_t length() const noexcept
810 return bt_field_class_enumeration_get_mapping_count(this->libObjPtr());
813 Shared shared() const noexcept
815 return Shared::createWithRef(*this);
819 template <typename LibObjT, typename MappingT>
820 class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT>
823 using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
826 using typename CommonFieldClass<LibObjT>::LibObjPtr;
827 using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>;
828 using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>;
829 using Mapping = MappingT;
831 explicit CommonEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept :
832 _ThisCommonBaseEnumerationFieldClass {libObjPtr}
834 BT_ASSERT_DBG(this->isEnumeration());
837 template <typename OtherLibObjT>
838 CommonEnumerationFieldClass(
839 const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept :
840 CommonEnumerationFieldClass {fc}
844 template <typename OtherLibObjT>
845 CommonEnumerationFieldClass
846 operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept
848 CommonEnumerationFieldClass::operator=(fc);
852 Mapping operator[](const std::uint64_t index) const noexcept
854 return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex(
855 this->libObjPtr(), index)};
858 OptionalBorrowedObject<Mapping> operator[](const bt2c::CStringView label) const noexcept
860 return internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
861 this->libObjPtr(), label);
864 CommonEnumerationFieldClass addMapping(const bt2c::CStringView label,
865 const typename Mapping::RangeSet ranges) const
867 const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
868 this->libObjPtr(), label, ranges.libObjPtr());
870 if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
871 throw MemoryError {};
877 Iterator begin() const noexcept
879 return Iterator {*this, 0};
882 Iterator end() const noexcept
884 return Iterator {*this, this->length()};
887 Shared shared() const noexcept
889 return Shared::createWithRef(*this);
893 using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>;
894 using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>;
896 using UnsignedEnumerationFieldClass =
897 CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
899 using ConstUnsignedEnumerationFieldClass =
900 CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
902 using SignedEnumerationFieldClass =
903 CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>;
905 using ConstSignedEnumerationFieldClass =
906 CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>;
910 struct UnsignedEnumerationFieldClassTypeDescr
912 using Const = ConstUnsignedEnumerationFieldClass;
913 using NonConst = UnsignedEnumerationFieldClass;
917 struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
922 struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
926 struct SignedEnumerationFieldClassTypeDescr
928 using Const = ConstSignedEnumerationFieldClass;
929 using NonConst = SignedEnumerationFieldClass;
933 struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
938 struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
942 template <typename LibObjT>
943 struct CommonStructureFieldClassMemberSpec;
945 /* Functions specific to mutable structure field class members */
947 struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final
949 static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept
951 return bt_field_class_structure_member_borrow_field_class(libObjPtr);
954 static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept
956 return bt_field_class_structure_member_borrow_user_attributes(libObjPtr);
960 /* Functions specific to constant structure field class members */
962 struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final
964 static const bt_field_class *
965 fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept
967 return bt_field_class_structure_member_borrow_field_class_const(libObjPtr);
970 static const bt_value *
971 userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept
973 return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr);
977 } /* namespace internal */
979 template <typename LibObjT>
980 class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT>
983 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
984 using _FieldClass = internal::DepFc<LibObjT>;
987 using typename BorrowedObject<LibObjT>::LibObjPtr;
988 using UserAttributes = internal::DepUserAttrs<LibObjT>;
990 explicit CommonStructureFieldClassMember(const LibObjPtr libObjPtr) noexcept :
991 _ThisBorrowedObject {libObjPtr}
995 template <typename OtherLibObjT>
996 CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
998 _ThisBorrowedObject {fc}
1002 template <typename OtherLibObjT>
1003 CommonStructureFieldClassMember<LibObjT>
1004 operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
1006 _ThisBorrowedObject::operator=(fc);
1010 CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept
1012 return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
1015 bt2c::CStringView name() const noexcept
1017 return bt_field_class_structure_member_get_name(this->libObjPtr());
1020 _FieldClass fieldClass() const noexcept
1022 return _FieldClass {
1023 internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())};
1026 template <typename LibValT>
1027 CommonStructureFieldClassMember
1028 userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1030 static_assert(!std::is_const<LibObjT>::value,
1031 "Not available with `bt2::ConstStructureFieldClassMember`.");
1033 bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
1034 userAttrs.libObjPtr());
1038 UserAttributes userAttributes() const noexcept
1040 return UserAttributes {
1041 internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes(
1042 this->libObjPtr())};
1046 using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>;
1048 using ConstStructureFieldClassMember =
1049 CommonStructureFieldClassMember<const bt_field_class_structure_member>;
1051 namespace internal {
1053 struct StructureFieldClassMemberTypeDescr
1055 using Const = ConstStructureFieldClassMember;
1056 using NonConst = StructureFieldClassMember;
1060 struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1065 struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1069 template <typename LibObjT>
1070 struct CommonStructureFieldClassSpec;
1072 /* Functions specific to mutable structure field classes */
1074 struct CommonStructureFieldClassSpec<bt_field_class> final
1076 static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr,
1077 const std::uint64_t index) noexcept
1079 return bt_field_class_structure_borrow_member_by_index(libObjPtr, index);
1082 static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr,
1083 const char * const name) noexcept
1085 return bt_field_class_structure_borrow_member_by_name(libObjPtr, name);
1089 /* Functions specific to constant structure field classes */
1091 struct CommonStructureFieldClassSpec<const bt_field_class> final
1093 static const bt_field_class_structure_member *
1094 memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
1096 return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index);
1099 static const bt_field_class_structure_member *
1100 memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
1102 return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name);
1106 } /* namespace internal */
1108 template <typename LibObjT>
1109 class CommonStructureFieldClass final : public CommonFieldClass<LibObjT>
1112 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1115 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1116 using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
1117 using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>;
1120 internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>;
1122 explicit CommonStructureFieldClass(const LibObjPtr libObjPtr) noexcept :
1123 _ThisCommonFieldClass {libObjPtr}
1125 BT_ASSERT_DBG(this->isStructure());
1128 template <typename OtherLibObjT>
1129 CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept :
1130 _ThisCommonFieldClass {fc}
1134 template <typename OtherLibObjT>
1135 CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
1137 _ThisCommonFieldClass::operator=(fc);
1141 CommonStructureFieldClass<const bt_field_class> asConst() const noexcept
1143 return CommonStructureFieldClass<const bt_field_class> {*this};
1146 CommonStructureFieldClass appendMember(const bt2c::CStringView name, const FieldClass fc) const
1148 static_assert(!std::is_const<LibObjT>::value,
1149 "Not available with `bt2::ConstStructureFieldClass`.");
1152 bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
1154 if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) {
1155 throw MemoryError {};
1161 std::uint64_t length() const noexcept
1163 return bt_field_class_structure_get_member_count(this->libObjPtr());
1166 Iterator begin() const noexcept
1168 return Iterator {*this, 0};
1171 Iterator end() const noexcept
1173 return Iterator {*this, this->length()};
1176 Member operator[](const std::uint64_t index) const noexcept
1178 return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex(
1179 this->libObjPtr(), index)};
1182 OptionalBorrowedObject<Member> operator[](const bt2c::CStringView name) const noexcept
1184 return internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(),
1188 Shared shared() const noexcept
1190 return Shared::createWithRef(*this);
1194 using StructureFieldClass = CommonStructureFieldClass<bt_field_class>;
1195 using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>;
1197 namespace internal {
1199 struct StructureFieldClassTypeDescr
1201 using Const = ConstStructureFieldClass;
1202 using NonConst = StructureFieldClass;
1206 struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr
1211 struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr
1215 template <typename LibObjT>
1216 struct CommonArrayFieldClassSpec;
1218 /* Functions specific to mutable array field classes */
1220 struct CommonArrayFieldClassSpec<bt_field_class> final
1222 static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept
1224 return bt_field_class_array_borrow_element_field_class(libObjPtr);
1228 /* Functions specific to constant array field classes */
1230 struct CommonArrayFieldClassSpec<const bt_field_class> final
1232 static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept
1234 return bt_field_class_array_borrow_element_field_class_const(libObjPtr);
1238 } /* namespace internal */
1240 template <typename LibObjT>
1241 class CommonArrayFieldClass : public CommonFieldClass<LibObjT>
1244 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1245 using _FieldClass = internal::DepFc<LibObjT>;
1248 using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
1251 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1252 using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
1254 explicit CommonArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
1255 _ThisCommonFieldClass {libObjPtr}
1257 BT_ASSERT_DBG(this->isArray());
1260 template <typename OtherLibObjT>
1261 CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept :
1262 _ThisCommonFieldClass {fc}
1266 template <typename OtherLibObjT>
1267 CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
1269 _ThisCommonFieldClass::operator=(fc);
1273 CommonArrayFieldClass<const bt_field_class> asConst() const noexcept
1275 return CommonArrayFieldClass<const bt_field_class> {*this};
1278 _FieldClass elementFieldClass() const noexcept
1280 return _FieldClass {
1281 internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())};
1284 Shared shared() const noexcept
1286 return Shared::createWithRef(*this);
1290 using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>;
1291 using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>;
1293 namespace internal {
1295 struct ArrayFieldClassTypeDescr
1297 using Const = ConstArrayFieldClass;
1298 using NonConst = ArrayFieldClass;
1302 struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr
1307 struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr
1311 } /* namespace internal */
1313 template <typename LibObjT>
1314 class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT>
1317 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1320 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1321 using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
1323 explicit CommonStaticArrayFieldClass(const LibObjPtr libObjPtr) noexcept :
1324 _ThisCommonArrayFieldClass {libObjPtr}
1326 BT_ASSERT_DBG(this->isStaticArray());
1329 template <typename OtherLibObjT>
1330 CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept :
1331 _ThisCommonArrayFieldClass {fc}
1335 template <typename OtherLibObjT>
1336 CommonStaticArrayFieldClass
1337 operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
1339 _ThisCommonArrayFieldClass::operator=(fc);
1343 CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept
1345 return CommonStaticArrayFieldClass<const bt_field_class> {*this};
1348 std::uint64_t length() const noexcept
1350 return bt_field_class_array_static_get_length(this->libObjPtr());
1353 Shared shared() const noexcept
1355 return Shared::createWithRef(*this);
1359 using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>;
1360 using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>;
1362 namespace internal {
1364 struct StaticArrayFieldClassTypeDescr
1366 using Const = ConstStaticArrayFieldClass;
1367 using NonConst = StaticArrayFieldClass;
1371 struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1376 struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1380 } /* namespace internal */
1382 template <typename LibObjT>
1383 class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT>
1386 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1389 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1390 using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
1392 explicit CommonDynamicArrayWithLengthFieldClass(const LibObjPtr libObjPtr) noexcept :
1393 _ThisCommonArrayFieldClass {libObjPtr}
1395 BT_ASSERT_DBG(this->isDynamicArrayWithLength());
1398 template <typename OtherLibObjT>
1399 CommonDynamicArrayWithLengthFieldClass(
1400 const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept :
1401 _ThisCommonArrayFieldClass {fc}
1405 template <typename OtherLibObjT>
1406 CommonDynamicArrayWithLengthFieldClass
1407 operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
1409 _ThisCommonArrayFieldClass::operator=(fc);
1413 CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept
1415 return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this};
1418 ConstFieldPath lengthFieldPath() const noexcept
1420 return ConstFieldPath {
1421 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
1422 this->libObjPtr())};
1425 Shared shared() const noexcept
1427 return Shared::createWithRef(*this);
1431 using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>;
1433 using ConstDynamicArrayWithLengthFieldClass =
1434 CommonDynamicArrayWithLengthFieldClass<const bt_field_class>;
1436 namespace internal {
1438 struct DynamicArrayWithLengthFieldClassTypeDescr
1440 using Const = ConstDynamicArrayWithLengthFieldClass;
1441 using NonConst = DynamicArrayWithLengthFieldClass;
1445 struct TypeDescr<DynamicArrayWithLengthFieldClass> :
1446 public DynamicArrayWithLengthFieldClassTypeDescr
1451 struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> :
1452 public DynamicArrayWithLengthFieldClassTypeDescr
1456 template <typename LibObjT>
1457 struct CommonOptionFieldClassSpec;
1459 /* Functions specific to mutable option field classes */
1461 struct CommonOptionFieldClassSpec<bt_field_class> final
1463 static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept
1465 return bt_field_class_option_borrow_field_class(libObjPtr);
1469 /* Functions specific to constant option field classes */
1471 struct CommonOptionFieldClassSpec<const bt_field_class> final
1473 static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept
1475 return bt_field_class_option_borrow_field_class_const(libObjPtr);
1479 } /* namespace internal */
1481 template <typename LibObjT>
1482 class CommonOptionFieldClass : public CommonFieldClass<LibObjT>
1485 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1486 using _FieldClass = internal::DepFc<LibObjT>;
1489 using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
1492 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1493 using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
1495 explicit CommonOptionFieldClass(const LibObjPtr libObjPtr) noexcept :
1496 _ThisCommonFieldClass {libObjPtr}
1498 BT_ASSERT_DBG(this->isOption());
1501 template <typename OtherLibObjT>
1502 CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept :
1503 _ThisCommonFieldClass {fc}
1507 template <typename OtherLibObjT>
1508 CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
1510 _ThisCommonFieldClass::operator=(fc);
1514 CommonOptionFieldClass<const bt_field_class> asConst() const noexcept
1516 return CommonOptionFieldClass<const bt_field_class> {*this};
1519 _FieldClass fieldClass() const noexcept
1521 return _FieldClass {
1522 internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())};
1525 Shared shared() const noexcept
1527 return Shared::createWithRef(*this);
1531 using OptionFieldClass = CommonOptionFieldClass<bt_field_class>;
1532 using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>;
1534 namespace internal {
1536 struct OptionFieldClassTypeDescr
1538 using Const = ConstOptionFieldClass;
1539 using NonConst = OptionFieldClass;
1543 struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr
1548 struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr
1552 } /* namespace internal */
1554 template <typename LibObjT>
1555 class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT>
1558 using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass;
1561 using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
1564 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1565 using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
1567 explicit CommonOptionWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
1568 _ThisCommonOptionFieldClass {libObjPtr}
1570 BT_ASSERT_DBG(this->isOptionWithSelector());
1573 template <typename OtherLibObjT>
1574 CommonOptionWithSelectorFieldClass(
1575 const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
1576 _ThisCommonOptionFieldClass {fc}
1580 template <typename OtherLibObjT>
1581 CommonOptionWithSelectorFieldClass
1582 operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
1584 _ThisCommonOptionFieldClass::operator=(fc);
1588 CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
1590 return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this};
1593 ConstFieldPath selectorFieldPath() const noexcept
1595 return ConstFieldPath {
1596 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1597 this->libObjPtr())};
1600 Shared shared() const noexcept
1602 return Shared::createWithRef(*this);
1606 using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>;
1607 using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>;
1609 namespace internal {
1611 struct OptionWithSelectorFieldClassTypeDescr
1613 using Const = ConstOptionWithSelectorFieldClass;
1614 using NonConst = OptionWithSelectorFieldClass;
1618 struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1623 struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1627 } /* namespace internal */
1629 template <typename LibObjT>
1630 class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1633 using typename CommonOptionWithSelectorFieldClass<
1634 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1637 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1638 using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
1640 explicit CommonOptionWithBoolSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
1641 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1643 BT_ASSERT_DBG(this->isOptionWithBoolSelector());
1646 template <typename OtherLibObjT>
1647 CommonOptionWithBoolSelectorFieldClass(
1648 const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept :
1649 _ThisCommonOptionWithSelectorFieldClass {fc}
1653 template <typename OtherLibObjT>
1654 CommonOptionWithBoolSelectorFieldClass
1655 operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
1657 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1661 CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept
1663 return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this};
1666 bool selectorIsReversed() const noexcept
1668 return bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1672 Shared shared() const noexcept
1674 return Shared::createWithRef(*this);
1678 using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>;
1680 using ConstOptionWithBoolSelectorFieldClass =
1681 CommonOptionWithBoolSelectorFieldClass<const bt_field_class>;
1683 namespace internal {
1685 struct OptionWithBoolSelectorFieldClassTypeDescr
1687 using Const = ConstOptionWithBoolSelectorFieldClass;
1688 using NonConst = OptionWithBoolSelectorFieldClass;
1692 struct TypeDescr<OptionWithBoolSelectorFieldClass> :
1693 public OptionWithBoolSelectorFieldClassTypeDescr
1698 struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> :
1699 public OptionWithBoolSelectorFieldClassTypeDescr
1703 template <typename RangeSetT>
1704 struct CommonOptionWithIntegerSelectorFieldClassSpec;
1706 /* Functions specific to option field classes with unsigned integer ranges */
1708 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final
1710 static const bt_integer_range_set_unsigned *
1711 ranges(const bt_field_class * const libObjPtr) noexcept
1713 return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1718 /* Functions specific to option field classes with signed ranges */
1720 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final
1722 static const bt_integer_range_set_signed *
1723 ranges(const bt_field_class * const libObjPtr) noexcept
1725 return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1730 } /* namespace internal */
1732 template <typename LibObjT, typename RangeSetT>
1733 class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1736 using typename CommonOptionWithSelectorFieldClass<
1737 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1740 using typename CommonFieldClass<LibObjT>::LibObjPtr;
1741 using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>;
1742 using RangeSet = RangeSetT;
1744 explicit CommonOptionWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
1745 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1747 BT_ASSERT_DBG(this->isOptionWithIntegerSelector());
1750 template <typename OtherLibObjT>
1751 CommonOptionWithIntegerSelectorFieldClass(
1752 const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept :
1753 _ThisCommonOptionWithSelectorFieldClass {fc}
1757 template <typename OtherLibObjT>
1758 CommonOptionWithIntegerSelectorFieldClass
1759 operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
1761 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1765 RangeSet ranges() const noexcept
1767 return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges(
1768 this->libObjPtr())};
1771 Shared shared() const noexcept
1773 return Shared::createWithRef(*this);
1777 using OptionWithUnsignedIntegerSelectorFieldClass =
1778 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>;
1780 using ConstOptionWithUnsignedIntegerSelectorFieldClass =
1781 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>;
1783 using OptionWithSignedIntegerSelectorFieldClass =
1784 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>;
1786 using ConstOptionWithSignedIntegerSelectorFieldClass =
1787 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>;
1789 namespace internal {
1791 struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1793 using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass;
1794 using NonConst = OptionWithUnsignedIntegerSelectorFieldClass;
1798 struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> :
1799 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1804 struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> :
1805 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1809 struct OptionWithSignedIntegerSelectorFieldClassTypeDescr
1811 using Const = ConstOptionWithSignedIntegerSelectorFieldClass;
1812 using NonConst = OptionWithSignedIntegerSelectorFieldClass;
1816 struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> :
1817 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1822 struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> :
1823 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1827 template <typename LibObjT>
1828 struct CommonVariantFieldClassOptionSpec;
1830 /* Functions specific to mutable variant field class options */
1832 struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final
1834 static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept
1836 return bt_field_class_variant_option_borrow_field_class(libObjPtr);
1839 static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept
1841 return bt_field_class_variant_option_borrow_user_attributes(libObjPtr);
1845 /* Functions specific to constant variant field class options */
1847 struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final
1849 static const bt_field_class *
1850 fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept
1852 return bt_field_class_variant_option_borrow_field_class_const(libObjPtr);
1855 static const bt_value *
1856 userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept
1858 return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr);
1862 } /* namespace internal */
1864 template <typename LibObjT>
1865 class CommonVariantFieldClassOption : public BorrowedObject<LibObjT>
1868 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1869 using _FieldClass = internal::DepFc<LibObjT>;
1872 using typename BorrowedObject<LibObjT>::LibObjPtr;
1873 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1875 explicit CommonVariantFieldClassOption(const LibObjPtr libObjPtr) noexcept :
1876 _ThisBorrowedObject {libObjPtr}
1880 template <typename OtherLibObjT>
1881 CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept :
1882 _ThisBorrowedObject {fc}
1886 template <typename OtherLibObjT>
1887 CommonVariantFieldClassOption
1888 operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
1890 _ThisBorrowedObject::operator=(fc);
1894 CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept
1896 return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
1899 bt2c::CStringView name() const noexcept
1901 return bt_field_class_variant_option_get_name(this->libObjPtr());
1904 _FieldClass fieldClass() const noexcept
1906 return _FieldClass {
1907 internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())};
1910 template <typename LibValT>
1911 CommonVariantFieldClassOption
1912 userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1914 static_assert(!std::is_const<LibObjT>::value,
1915 "Not available with `bt2::ConstVariantFieldClassOption`.");
1917 bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1921 UserAttributes userAttributes() const noexcept
1923 return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes(
1924 this->libObjPtr())};
1928 using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>;
1930 using ConstVariantFieldClassOption =
1931 CommonVariantFieldClassOption<const bt_field_class_variant_option>;
1933 namespace internal {
1935 struct VariantFieldClassOptionTypeDescr
1937 using Const = ConstVariantFieldClassOption;
1938 using NonConst = VariantFieldClassOption;
1942 struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
1947 struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
1951 template <typename LibObjT>
1952 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec;
1954 /* Functions specific to variant field class options with unsigned integer selector */
1956 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
1957 const bt_field_class_variant_with_selector_field_integer_unsigned_option>
1960 static const bt_integer_range_set_unsigned *
1961 ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option
1962 * const libObjPtr) noexcept
1964 return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
1968 static const bt_field_class_variant_option *
1969 asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option
1970 * const libObjPtr) noexcept
1972 return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const(
1977 /* Functions specific to variant field class options with signed integer selector */
1979 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
1980 const bt_field_class_variant_with_selector_field_integer_signed_option>
1983 static const bt_integer_range_set_signed *
1984 ranges(const bt_field_class_variant_with_selector_field_integer_signed_option
1985 * const libObjPtr) noexcept
1987 return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
1991 static const bt_field_class_variant_option *
1992 asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option
1993 * const libObjPtr) noexcept
1995 return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const(
2000 } /* namespace internal */
2002 template <typename LibObjT>
2003 class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT>
2006 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
2007 using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
2010 using typename BorrowedObject<LibObjT>::LibObjPtr;
2012 using RangeSet = typename std::conditional<
2015 const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value,
2016 ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
2018 explicit ConstVariantWithIntegerSelectorFieldClassOption(const LibObjPtr libObjPtr) noexcept :
2019 _ThisBorrowedObject {libObjPtr}
2023 template <typename OtherLibObjT>
2024 ConstVariantWithIntegerSelectorFieldClassOption(
2025 const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept :
2026 _ThisBorrowedObject {fc}
2030 template <typename OtherLibObjT>
2031 ConstVariantWithIntegerSelectorFieldClassOption
2032 operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
2034 _ThisBorrowedObject::operator=(fc);
2038 ConstVariantFieldClassOption asBaseOption() const noexcept
2040 return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
2043 bt2c::CStringView name() const noexcept
2045 return this->asBaseOption().name();
2048 ConstFieldClass fieldClass() const noexcept
2050 return this->asBaseOption().fieldClass();
2053 RangeSet ranges() const noexcept
2055 return RangeSet {_Spec::ranges(this->libObjPtr())};
2059 using ConstVariantWithUnsignedIntegerSelectorFieldClassOption =
2060 ConstVariantWithIntegerSelectorFieldClassOption<
2061 const bt_field_class_variant_with_selector_field_integer_unsigned_option>;
2063 using ConstVariantWithSignedIntegerSelectorFieldClassOption =
2064 ConstVariantWithIntegerSelectorFieldClassOption<
2065 const bt_field_class_variant_with_selector_field_integer_signed_option>;
2067 namespace internal {
2069 template <typename LibObjT>
2070 struct CommonVariantFieldClassSpec;
2072 /* Functions specific to mutable variant field classes */
2074 struct CommonVariantFieldClassSpec<bt_field_class> final
2076 static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr,
2077 const std::uint64_t index) noexcept
2079 return bt_field_class_variant_borrow_option_by_index(libObjPtr, index);
2082 static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr,
2083 const char * const name) noexcept
2085 return bt_field_class_variant_borrow_option_by_name(libObjPtr, name);
2089 /* Functions specific to constant variant field classes */
2091 struct CommonVariantFieldClassSpec<const bt_field_class> final
2093 static const bt_field_class_variant_option *
2094 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2096 return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index);
2099 static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr,
2100 const char * const name) noexcept
2102 return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name);
2106 } /* namespace internal */
2108 template <typename LibObjT>
2109 class CommonVariantFieldClass : public CommonFieldClass<LibObjT>
2112 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
2115 using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
2118 using typename CommonFieldClass<LibObjT>::LibObjPtr;
2119 using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
2120 using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>;
2123 internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>;
2125 explicit CommonVariantFieldClass(const LibObjPtr libObjPtr) noexcept :
2126 _ThisCommonFieldClass {libObjPtr}
2128 BT_ASSERT_DBG(this->isVariant());
2131 template <typename OtherLibObjT>
2132 CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept :
2133 _ThisCommonFieldClass {fc}
2137 template <typename OtherLibObjT>
2138 CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
2140 _ThisCommonFieldClass::operator=(fc);
2144 CommonVariantFieldClass<const bt_field_class> asConst() const noexcept
2146 return CommonVariantFieldClass<const bt_field_class> {*this};
2149 std::uint64_t length() const noexcept
2151 return bt_field_class_variant_get_option_count(this->libObjPtr());
2154 Iterator begin() const noexcept
2156 return Iterator {*this, 0};
2159 Iterator end() const noexcept
2161 return Iterator {*this, this->length()};
2164 Option operator[](const std::uint64_t index) const noexcept
2166 return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex(
2167 this->libObjPtr(), index)};
2170 OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
2172 return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(),
2176 Shared shared() const noexcept
2178 return Shared::createWithRef(*this);
2182 using VariantFieldClass = CommonVariantFieldClass<bt_field_class>;
2183 using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>;
2185 namespace internal {
2187 struct VariantFieldClassTypeDescr
2189 using Const = ConstVariantFieldClass;
2190 using NonConst = VariantFieldClass;
2194 struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr
2199 struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr
2203 } /* namespace internal */
2205 template <typename LibObjT>
2206 class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2209 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2212 using typename CommonFieldClass<LibObjT>::LibObjPtr;
2213 using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
2215 explicit CommonVariantWithoutSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
2216 _ThisCommonVariantFieldClass {libObjPtr}
2218 BT_ASSERT_DBG(this->isVariantWithoutSelector());
2221 template <typename OtherLibObjT>
2222 CommonVariantWithoutSelectorFieldClass(
2223 const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept :
2224 _ThisCommonVariantFieldClass {fc}
2228 template <typename OtherLibObjT>
2229 CommonVariantWithoutSelectorFieldClass
2230 operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
2232 _ThisCommonVariantFieldClass::operator=(fc);
2236 CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept
2238 return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this};
2241 CommonVariantWithoutSelectorFieldClass appendOption(const char * const name,
2242 const FieldClass fc) const
2244 static_assert(!std::is_const<LibObjT>::value,
2245 "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`.");
2247 const auto status = bt_field_class_variant_without_selector_append_option(
2248 this->libObjPtr(), name, fc.libObjPtr());
2251 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2252 throw MemoryError {};
2258 CommonVariantWithoutSelectorFieldClass appendOption(const bt2c::CStringView name,
2259 const FieldClass fc) const
2261 return this->appendOption(name.data(), fc);
2264 CommonVariantWithoutSelectorFieldClass appendOption(const bt2s::optional<std::string>& name,
2265 const FieldClass fc) const
2267 return this->appendOption(name ? name->data() : nullptr, fc);
2270 Shared shared() const noexcept
2272 return Shared::createWithRef(*this);
2276 using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>;
2277 using ConstVariantWithoutSelectorFieldClass =
2278 CommonVariantWithoutSelectorFieldClass<const bt_field_class>;
2280 namespace internal {
2282 struct VariantWithoutSelectorFieldClassTypeDescr
2284 using Const = ConstVariantWithoutSelectorFieldClass;
2285 using NonConst = VariantWithoutSelectorFieldClass;
2289 struct TypeDescr<VariantWithoutSelectorFieldClass> :
2290 public VariantWithoutSelectorFieldClassTypeDescr
2295 struct TypeDescr<ConstVariantWithoutSelectorFieldClass> :
2296 public VariantWithoutSelectorFieldClassTypeDescr
2300 template <typename OptionT>
2301 struct CommonVariantWithIntegerSelectorFieldClassSpec;
2303 /* Functions specific to variant field classes with unsigned integer selector */
2305 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2306 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2309 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2310 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2312 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
2316 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2317 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2319 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
2323 static bt_field_class_variant_with_selector_field_integer_append_option_status
2324 appendOption(bt_field_class * const libObjPtr, const char * const name,
2325 bt_field_class * const libOptFcPtr,
2326 const bt_integer_range_set_unsigned * const libRangesPtr)
2328 return bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
2329 libObjPtr, name, libOptFcPtr, libRangesPtr);
2333 /* Functions specific to variant field classes with signed integer selector */
2335 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2336 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2339 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2340 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2342 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
2346 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2347 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2349 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
2353 static bt_field_class_variant_with_selector_field_integer_append_option_status
2354 appendOption(bt_field_class * const libObjPtr, const char * const name,
2355 bt_field_class * const libOptFcPtr,
2356 const bt_integer_range_set_signed * const libRangesPtr)
2358 return bt_field_class_variant_with_selector_field_integer_signed_append_option(
2359 libObjPtr, name, libOptFcPtr, libRangesPtr);
2363 } /* namespace internal */
2365 template <typename LibObjT>
2366 class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2369 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2372 using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
2375 using typename CommonFieldClass<LibObjT>::LibObjPtr;
2376 using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
2378 explicit CommonVariantWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
2379 _ThisCommonVariantFieldClass {libObjPtr}
2381 BT_ASSERT_DBG(this->isVariantWithSelector());
2384 template <typename OtherLibObjT>
2385 CommonVariantWithSelectorFieldClass(
2386 const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
2387 _ThisCommonVariantFieldClass {fc}
2391 template <typename OtherLibObjT>
2392 CommonVariantWithSelectorFieldClass
2393 operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
2395 _ThisCommonVariantFieldClass::operator=(fc);
2399 CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
2401 return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this};
2404 ConstFieldPath selectorFieldPath() const noexcept
2406 return ConstFieldPath {
2407 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
2408 this->libObjPtr())};
2411 Shared shared() const noexcept
2413 return Shared::createWithRef(*this);
2417 using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>;
2418 using ConstVariantWithSelectorFieldClass =
2419 CommonVariantWithSelectorFieldClass<const bt_field_class>;
2421 template <typename LibObjT, typename OptionT>
2422 class CommonVariantWithIntegerSelectorFieldClass :
2423 public CommonVariantWithSelectorFieldClass<LibObjT>
2426 using typename CommonVariantWithSelectorFieldClass<
2427 LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
2429 using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
2432 using typename CommonFieldClass<LibObjT>::LibObjPtr;
2433 using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>;
2434 using Option = OptionT;
2437 BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>;
2439 explicit CommonVariantWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept :
2440 _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
2442 BT_ASSERT_DBG(this->isVariantWithIntegerSelector());
2445 template <typename OtherLibObjT>
2446 CommonVariantWithIntegerSelectorFieldClass(
2447 const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept :
2448 _ThisCommonVariantWithSelectorFieldClass {fc}
2452 template <typename OtherLibObjT>
2453 CommonVariantWithIntegerSelectorFieldClass
2454 operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
2456 _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
2460 Option operator[](const std::uint64_t index) const noexcept
2462 return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
2465 OptionalBorrowedObject<Option> operator[](const bt2c::CStringView name) const noexcept
2467 return _Spec::optionByName(this->libObjPtr(), name);
2470 CommonVariantWithIntegerSelectorFieldClass
2471 appendOption(const char * const name, const FieldClass fc,
2472 const typename Option::RangeSet ranges) const
2475 !std::is_const<LibObjT>::value,
2476 "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`.");
2479 _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr());
2482 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2483 throw MemoryError {};
2489 CommonVariantWithIntegerSelectorFieldClass
2490 appendOption(const bt2c::CStringView name, const FieldClass fc,
2491 const typename Option::RangeSet ranges) const
2493 return this->appendOption(name.data(), fc, ranges);
2496 CommonVariantWithIntegerSelectorFieldClass
2497 appendOption(const bt2s::optional<std::string>& name, const FieldClass fc,
2498 const typename Option::RangeSet ranges) const
2500 return this->appendOption(name ? name->data() : nullptr, fc, ranges);
2503 Iterator begin() const noexcept
2505 return Iterator {*this, 0};
2508 Iterator end() const noexcept
2510 return Iterator {*this, this->length()};
2513 Shared shared() const noexcept
2515 return Shared::createWithRef(*this);
2519 using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2520 bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2522 using ConstVariantWithUnsignedIntegerSelectorFieldClass =
2523 CommonVariantWithIntegerSelectorFieldClass<
2524 const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2526 using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2527 bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2529 using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2530 const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2532 namespace internal {
2534 struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2536 using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass;
2537 using NonConst = VariantWithUnsignedIntegerSelectorFieldClass;
2541 struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> :
2542 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2547 struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> :
2548 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2552 struct VariantWithSignedIntegerSelectorFieldClassTypeDescr
2554 using Const = ConstVariantWithSignedIntegerSelectorFieldClass;
2555 using NonConst = VariantWithSignedIntegerSelectorFieldClass;
2559 struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> :
2560 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2565 struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> :
2566 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2570 } /* namespace internal */
2572 template <typename LibObjT>
2573 CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept
2575 return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()};
2578 template <typename LibObjT>
2579 CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept
2581 return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()};
2584 template <typename LibObjT>
2585 CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept
2587 return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()};
2590 template <typename LibObjT>
2591 CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping>
2592 CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept
2594 BT_ASSERT_DBG(this->isUnsignedEnumeration());
2595 return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> {
2599 template <typename LibObjT>
2600 CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping>
2601 CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept
2603 BT_ASSERT_DBG(this->isSignedEnumeration());
2604 return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> {
2608 template <typename LibObjT>
2609 CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept
2611 return CommonStructureFieldClass<LibObjT> {this->libObjPtr()};
2614 template <typename LibObjT>
2615 CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept
2617 return CommonArrayFieldClass<LibObjT> {this->libObjPtr()};
2620 template <typename LibObjT>
2621 CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept
2623 return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()};
2626 template <typename LibObjT>
2627 CommonDynamicArrayWithLengthFieldClass<LibObjT>
2628 CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept
2630 return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()};
2633 template <typename LibObjT>
2634 CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept
2636 return CommonOptionFieldClass<LibObjT> {this->libObjPtr()};
2639 template <typename LibObjT>
2640 CommonOptionWithSelectorFieldClass<LibObjT>
2641 CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept
2643 return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2646 template <typename LibObjT>
2647 CommonOptionWithBoolSelectorFieldClass<LibObjT>
2648 CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept
2650 return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()};
2653 template <typename LibObjT>
2654 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet>
2655 CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept
2657 BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector());
2658 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> {
2662 template <typename LibObjT>
2663 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet>
2664 CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept
2666 BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector());
2667 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> {
2671 template <typename LibObjT>
2672 CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept
2674 return CommonVariantFieldClass<LibObjT> {this->libObjPtr()};
2677 template <typename LibObjT>
2678 CommonVariantWithoutSelectorFieldClass<LibObjT>
2679 CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept
2681 return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()};
2684 template <typename LibObjT>
2685 CommonVariantWithSelectorFieldClass<LibObjT>
2686 CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept
2688 return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2691 template <typename LibObjT>
2692 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2693 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2694 CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept
2696 BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector());
2697 return CommonVariantWithIntegerSelectorFieldClass<
2698 LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2701 template <typename LibObjT>
2702 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2703 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2704 CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept
2706 BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector());
2707 return CommonVariantWithIntegerSelectorFieldClass<
2708 LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2711 } /* namespace bt2 */
2713 #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */