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-object.hpp"
20 #include "common-iterator.hpp"
22 #include "field-path.hpp"
23 #include "integer-range-set.hpp"
24 #include "internal/utils.hpp"
25 #include "shared-object.hpp"
31 struct FieldClassRefFuncs final
33 static void get(const bt_field_class * const libObjPtr) noexcept
35 bt_field_class_get_ref(libObjPtr);
38 static void put(const bt_field_class * const libObjPtr) noexcept
40 bt_field_class_put_ref(libObjPtr);
44 template <typename LibObjT>
45 struct CommonFieldClassSpec;
47 /* Functions specific to mutable field classes */
49 struct CommonFieldClassSpec<bt_field_class> final
51 static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept
53 return bt_field_class_borrow_user_attributes(libObjPtr);
57 /* Functions specific to constant field classes */
59 struct CommonFieldClassSpec<const bt_field_class> final
61 static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept
63 return bt_field_class_borrow_user_attributes_const(libObjPtr);
67 } /* namespace internal */
69 template <typename ObjT, typename LibObjT>
70 using SharedFieldClass = SharedObject<ObjT, LibObjT, internal::FieldClassRefFuncs>;
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 BorrowedObject<LibObjT>
167 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
170 using typename BorrowedObject<LibObjT>::_LibObjPtr;
171 using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
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 void 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());
411 UserAttributes userAttributes() const noexcept
413 return UserAttributes {
414 internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
417 Shared shared() const noexcept
419 return Shared::createWithRef(*this);
423 bool _libTypeIs(const bt_field_class_type type) const noexcept
425 return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type);
429 using FieldClass = CommonFieldClass<bt_field_class>;
430 using ConstFieldClass = CommonFieldClass<const bt_field_class>;
434 struct FieldClassTypeDescr
436 using Const = ConstFieldClass;
437 using NonConst = FieldClass;
441 struct TypeDescr<FieldClass> : public FieldClassTypeDescr
446 struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr
450 } /* namespace internal */
452 template <typename LibObjT>
453 class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT>
456 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
457 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
460 using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
462 explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
463 _ThisCommonFieldClass {libObjPtr}
465 BT_ASSERT_DBG(this->isBitArray());
468 template <typename OtherLibObjT>
469 CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept :
470 _ThisCommonFieldClass {fc}
474 template <typename OtherLibObjT>
475 CommonBitArrayFieldClass<LibObjT>&
476 operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
478 _ThisCommonFieldClass::operator=(fc);
482 CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept
484 return CommonBitArrayFieldClass<const bt_field_class> {*this};
487 std::uint64_t length() const noexcept
489 return bt_field_class_bit_array_get_length(this->libObjPtr());
492 Shared shared() const noexcept
494 return Shared::createWithRef(*this);
498 using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>;
499 using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>;
503 struct BitArrayFieldClassTypeDescr
505 using Const = ConstBitArrayFieldClass;
506 using NonConst = BitArrayFieldClass;
510 struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr
515 struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr
519 } /* namespace internal */
521 enum class DisplayBase
523 BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY,
524 OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL,
525 DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
526 HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL,
529 template <typename LibObjT>
530 class CommonIntegerFieldClass : public CommonFieldClass<LibObjT>
533 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
536 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
537 using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
540 using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
542 explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept :
543 _ThisCommonFieldClass {libObjPtr}
545 BT_ASSERT_DBG(this->isInteger());
548 template <typename OtherLibObjT>
549 CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept :
550 _ThisCommonFieldClass {fc}
554 template <typename OtherLibObjT>
555 CommonIntegerFieldClass& operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
557 _ThisCommonFieldClass::operator=(fc);
561 CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept
563 return CommonIntegerFieldClass<const bt_field_class> {*this};
566 void fieldValueRange(const std::uint64_t n) const noexcept
568 static_assert(!std::is_const<LibObjT>::value,
569 "Not available with `bt2::ConstIntegerFieldClass`.");
571 bt_field_class_integer_set_field_value_range(this->libObjPtr(), n);
574 std::uint64_t fieldValueRange() const noexcept
576 return bt_field_class_integer_get_field_value_range(this->libObjPtr());
579 void preferredDisplayBase(const DisplayBase base) const noexcept
581 static_assert(!std::is_const<LibObjT>::value,
582 "Not available with `bt2::ConstIntegerFieldClass`.");
584 bt_field_class_integer_set_preferred_display_base(
585 this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
588 DisplayBase preferredDisplayBase() const noexcept
590 return static_cast<DisplayBase>(
591 bt_field_class_integer_get_preferred_display_base(this->libObjPtr()));
594 Shared shared() const noexcept
596 return Shared::createWithRef(*this);
600 using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>;
601 using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>;
605 struct IntegerFieldClassTypeDescr
607 using Const = ConstIntegerFieldClass;
608 using NonConst = IntegerFieldClass;
612 struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr
617 struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
621 } /* namespace internal */
625 template <typename LibObjT>
626 struct ConstEnumerationFieldClassMappingSpec;
628 /* Functions specific to unsigned enumeration field class mappings */
630 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping>
633 static const bt_integer_range_set_unsigned *
634 ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
636 return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr);
640 label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
642 return bt_field_class_enumeration_mapping_get_label(
643 bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr));
647 /* Functions specific to signed enumeration field class mappings */
649 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final
651 static const bt_integer_range_set_signed *
652 ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
654 return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr);
658 label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
660 return bt_field_class_enumeration_mapping_get_label(
661 bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr));
665 } /* namespace internal */
667 template <typename LibObjT>
668 class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT>
671 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
672 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 bpstd::string_view 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 typename CommonFieldClass<LibObjT>::_LibObjPtr;
777 using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
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 CommonFieldClass<LibObjT>::_LibObjPtr;
824 using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
825 using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
828 using Shared = SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
829 using Iterator = CommonIterator<CommonEnumerationFieldClass, MappingT>;
830 using Mapping = MappingT;
832 explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
833 _ThisCommonBaseEnumerationFieldClass {libObjPtr}
835 BT_ASSERT_DBG(this->isEnumeration());
838 template <typename OtherLibObjT>
839 CommonEnumerationFieldClass(
840 const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept :
841 _ThisCommonEnumerationFieldClass {fc}
845 template <typename OtherLibObjT>
846 CommonEnumerationFieldClass&
847 operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept
849 _ThisCommonEnumerationFieldClass::operator=(fc);
853 Mapping operator[](const std::uint64_t index) const noexcept
855 return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex(
856 this->libObjPtr(), index)};
859 nonstd::optional<Mapping> operator[](const char * const label) const noexcept
861 const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
862 this->libObjPtr(), label);
865 return Mapping {libObjPtr};
868 return nonstd::nullopt;
871 nonstd::optional<Mapping> operator[](const std::string& label) const noexcept
873 return (*this)[label.data()];
876 void addMapping(const char * const label, const typename Mapping::RangeSet ranges) const
878 const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
879 this->libObjPtr(), label, ranges.libObjPtr());
881 if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
882 throw MemoryError {};
886 void addMapping(const std::string& label, const typename Mapping::RangeSet ranges) const
888 this->addMapping(label.data(), ranges);
891 Iterator begin() const noexcept
893 return Iterator {*this, 0};
896 Iterator end() const noexcept
898 return Iterator {*this, this->length()};
901 Shared shared() const noexcept
903 return Shared::createWithRef(*this);
907 using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>;
908 using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>;
910 using UnsignedEnumerationFieldClass =
911 CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
913 using ConstUnsignedEnumerationFieldClass =
914 CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
916 using SignedEnumerationFieldClass =
917 CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>;
919 using ConstSignedEnumerationFieldClass =
920 CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>;
924 struct UnsignedEnumerationFieldClassTypeDescr
926 using Const = ConstUnsignedEnumerationFieldClass;
927 using NonConst = UnsignedEnumerationFieldClass;
931 struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
936 struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
940 struct SignedEnumerationFieldClassTypeDescr
942 using Const = ConstSignedEnumerationFieldClass;
943 using NonConst = SignedEnumerationFieldClass;
947 struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
952 struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
956 template <typename LibObjT>
957 struct CommonStructureFieldClassMemberSpec;
959 /* Functions specific to mutable structure field class members */
961 struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final
963 static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept
965 return bt_field_class_structure_member_borrow_field_class(libObjPtr);
968 static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept
970 return bt_field_class_structure_member_borrow_user_attributes(libObjPtr);
974 /* Functions specific to constant structure field class members */
976 struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final
978 static const bt_field_class *
979 fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept
981 return bt_field_class_structure_member_borrow_field_class_const(libObjPtr);
984 static const bt_value *
985 userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept
987 return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr);
991 } /* namespace internal */
993 template <typename LibObjT>
994 class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT>
997 using typename BorrowedObject<LibObjT>::_LibObjPtr;
998 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
999 using _FieldClass = internal::DepFc<LibObjT>;
1002 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1004 explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept :
1005 _ThisBorrowedObject {libObjPtr}
1009 template <typename OtherLibObjT>
1010 CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
1012 _ThisBorrowedObject {fc}
1016 template <typename OtherLibObjT>
1017 CommonStructureFieldClassMember<LibObjT>&
1018 operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
1020 _ThisBorrowedObject::operator=(fc);
1024 CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept
1026 return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
1029 bpstd::string_view name() const noexcept
1031 return bt_field_class_structure_member_get_name(this->libObjPtr());
1034 _FieldClass fieldClass() const noexcept
1036 return _FieldClass {
1037 internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())};
1040 template <typename LibValT>
1041 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1043 static_assert(!std::is_const<LibObjT>::value,
1044 "Not available with `bt2::ConstStructureFieldClassMember`.");
1046 bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
1047 userAttrs.libObjPtr());
1050 UserAttributes userAttributes() const noexcept
1052 return UserAttributes {
1053 internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes(
1054 this->libObjPtr())};
1058 using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>;
1060 using ConstStructureFieldClassMember =
1061 CommonStructureFieldClassMember<const bt_field_class_structure_member>;
1063 namespace internal {
1065 struct StructureFieldClassMemberTypeDescr
1067 using Const = ConstStructureFieldClassMember;
1068 using NonConst = StructureFieldClassMember;
1072 struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1077 struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1081 template <typename LibObjT>
1082 struct CommonStructureFieldClassSpec;
1084 /* Functions specific to mutable structure field classes */
1086 struct CommonStructureFieldClassSpec<bt_field_class> final
1088 static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr,
1089 const std::uint64_t index) noexcept
1091 return bt_field_class_structure_borrow_member_by_index(libObjPtr, index);
1094 static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr,
1095 const char * const name) noexcept
1097 return bt_field_class_structure_borrow_member_by_name(libObjPtr, name);
1101 /* Functions specific to constant structure field classes */
1103 struct CommonStructureFieldClassSpec<const bt_field_class> final
1105 static const bt_field_class_structure_member *
1106 memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
1108 return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index);
1111 static const bt_field_class_structure_member *
1112 memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
1114 return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name);
1118 } /* namespace internal */
1120 template <typename LibObjT>
1121 class CommonStructureFieldClass final : public CommonFieldClass<LibObjT>
1124 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1125 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1128 using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
1131 internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>;
1133 using Iterator = CommonIterator<CommonStructureFieldClass<LibObjT>, Member>;
1135 explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept :
1136 _ThisCommonFieldClass {libObjPtr}
1138 BT_ASSERT_DBG(this->isStructure());
1141 template <typename OtherLibObjT>
1142 CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept :
1143 _ThisCommonFieldClass {fc}
1147 template <typename OtherLibObjT>
1148 CommonStructureFieldClass& operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
1150 _ThisCommonFieldClass::operator=(fc);
1154 CommonStructureFieldClass<const bt_field_class> asConst() const noexcept
1156 return CommonStructureFieldClass<const bt_field_class> {*this};
1159 void appendMember(const char * const name, const FieldClass fc) const
1161 static_assert(!std::is_const<LibObjT>::value,
1162 "Not available with `bt2::ConstStructureFieldClass`.");
1165 bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
1167 if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) {
1168 throw MemoryError {};
1172 void appendMember(const std::string& name, const FieldClass fc) const
1174 this->appendMember(name.data(), fc);
1177 std::uint64_t length() const noexcept
1179 return bt_field_class_structure_get_member_count(this->libObjPtr());
1182 Iterator begin() const noexcept
1184 return Iterator {*this, 0};
1187 Iterator end() const noexcept
1189 return Iterator {*this, this->length()};
1192 Member operator[](const std::uint64_t index) const noexcept
1194 return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex(
1195 this->libObjPtr(), index)};
1198 nonstd::optional<Member> operator[](const char * const name) const noexcept
1200 const auto libObjPtr =
1201 internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name);
1204 return Member {libObjPtr};
1207 return nonstd::nullopt;
1210 nonstd::optional<Member> operator[](const std::string& name) const noexcept
1212 return (*this)[name.data()];
1215 Shared shared() const noexcept
1217 return Shared::createWithRef(*this);
1221 using StructureFieldClass = CommonStructureFieldClass<bt_field_class>;
1222 using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>;
1224 namespace internal {
1226 struct StructureFieldClassTypeDescr
1228 using Const = ConstStructureFieldClass;
1229 using NonConst = StructureFieldClass;
1233 struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr
1238 struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr
1242 template <typename LibObjT>
1243 struct CommonArrayFieldClassSpec;
1245 /* Functions specific to mutable array field classes */
1247 struct CommonArrayFieldClassSpec<bt_field_class> final
1249 static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept
1251 return bt_field_class_array_borrow_element_field_class(libObjPtr);
1255 /* Functions specific to constant array field classes */
1257 struct CommonArrayFieldClassSpec<const bt_field_class> final
1259 static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept
1261 return bt_field_class_array_borrow_element_field_class_const(libObjPtr);
1265 } /* namespace internal */
1267 template <typename LibObjT>
1268 class CommonArrayFieldClass : public CommonFieldClass<LibObjT>
1271 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1272 using _FieldClass = internal::DepFc<LibObjT>;
1275 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1276 using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
1279 using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
1281 explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
1282 _ThisCommonFieldClass {libObjPtr}
1284 BT_ASSERT_DBG(this->isArray());
1287 template <typename OtherLibObjT>
1288 CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept :
1289 _ThisCommonFieldClass {fc}
1293 template <typename OtherLibObjT>
1294 CommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
1296 _ThisCommonFieldClass::operator=(fc);
1300 CommonArrayFieldClass<const bt_field_class> asConst() const noexcept
1302 return CommonArrayFieldClass<const bt_field_class> {*this};
1305 _FieldClass elementFieldClass() const noexcept
1307 return _FieldClass {
1308 internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())};
1311 Shared shared() const noexcept
1313 return Shared::createWithRef(*this);
1317 using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>;
1318 using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>;
1320 namespace internal {
1322 struct ArrayFieldClassTypeDescr
1324 using Const = ConstArrayFieldClass;
1325 using NonConst = ArrayFieldClass;
1329 struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr
1334 struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr
1338 } /* namespace internal */
1340 template <typename LibObjT>
1341 class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT>
1344 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1345 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1348 using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
1350 explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
1351 _ThisCommonArrayFieldClass {libObjPtr}
1353 BT_ASSERT_DBG(this->isStaticArray());
1356 template <typename OtherLibObjT>
1357 CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept :
1358 _ThisCommonArrayFieldClass {fc}
1362 template <typename OtherLibObjT>
1363 CommonStaticArrayFieldClass&
1364 operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
1366 _ThisCommonArrayFieldClass::operator=(fc);
1370 CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept
1372 return CommonStaticArrayFieldClass<const bt_field_class> {*this};
1375 std::uint64_t length() const noexcept
1377 return bt_field_class_array_static_get_length(this->libObjPtr());
1380 Shared shared() const noexcept
1382 return Shared::createWithRef(*this);
1386 using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>;
1387 using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>;
1389 namespace internal {
1391 struct StaticArrayFieldClassTypeDescr
1393 using Const = ConstStaticArrayFieldClass;
1394 using NonConst = StaticArrayFieldClass;
1398 struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1403 struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1407 } /* namespace internal */
1409 template <typename LibObjT>
1410 class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT>
1413 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1414 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1417 using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
1419 explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept :
1420 _ThisCommonArrayFieldClass {libObjPtr}
1422 BT_ASSERT_DBG(this->isDynamicArrayWithLength());
1425 template <typename OtherLibObjT>
1426 CommonDynamicArrayWithLengthFieldClass(
1427 const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept :
1428 _ThisCommonArrayFieldClass {fc}
1432 template <typename OtherLibObjT>
1433 CommonDynamicArrayWithLengthFieldClass&
1434 operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
1436 _ThisCommonArrayFieldClass::operator=(fc);
1440 CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept
1442 return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this};
1445 ConstFieldPath lengthFieldPath() const noexcept
1447 return ConstFieldPath {
1448 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
1449 this->libObjPtr())};
1452 Shared shared() const noexcept
1454 return Shared::createWithRef(*this);
1458 using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>;
1460 using ConstDynamicArrayWithLengthFieldClass =
1461 CommonDynamicArrayWithLengthFieldClass<const bt_field_class>;
1463 namespace internal {
1465 struct DynamicArrayWithLengthFieldClassTypeDescr
1467 using Const = ConstDynamicArrayWithLengthFieldClass;
1468 using NonConst = DynamicArrayWithLengthFieldClass;
1472 struct TypeDescr<DynamicArrayWithLengthFieldClass> :
1473 public DynamicArrayWithLengthFieldClassTypeDescr
1478 struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> :
1479 public DynamicArrayWithLengthFieldClassTypeDescr
1483 template <typename LibObjT>
1484 struct CommonOptionFieldClassSpec;
1486 /* Functions specific to mutable option field classes */
1488 struct CommonOptionFieldClassSpec<bt_field_class> final
1490 static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept
1492 return bt_field_class_option_borrow_field_class(libObjPtr);
1496 /* Functions specific to constant option field classes */
1498 struct CommonOptionFieldClassSpec<const bt_field_class> final
1500 static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept
1502 return bt_field_class_option_borrow_field_class_const(libObjPtr);
1506 } /* namespace internal */
1508 template <typename LibObjT>
1509 class CommonOptionFieldClass : public CommonFieldClass<LibObjT>
1512 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1513 using _FieldClass = internal::DepFc<LibObjT>;
1516 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1517 using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
1520 using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
1522 explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept :
1523 _ThisCommonFieldClass {libObjPtr}
1525 BT_ASSERT_DBG(this->isOption());
1528 template <typename OtherLibObjT>
1529 CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept :
1530 _ThisCommonFieldClass {fc}
1534 template <typename OtherLibObjT>
1535 CommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
1537 _ThisCommonFieldClass::operator=(fc);
1541 CommonOptionFieldClass<const bt_field_class> asConst() const noexcept
1543 return CommonOptionFieldClass<const bt_field_class> {*this};
1546 _FieldClass fieldClass() const noexcept
1548 return _FieldClass {
1549 internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())};
1552 Shared shared() const noexcept
1554 return Shared::createWithRef(*this);
1558 using OptionFieldClass = CommonOptionFieldClass<bt_field_class>;
1559 using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>;
1561 namespace internal {
1563 struct OptionFieldClassTypeDescr
1565 using Const = ConstOptionFieldClass;
1566 using NonConst = OptionFieldClass;
1570 struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr
1575 struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr
1579 } /* namespace internal */
1581 template <typename LibObjT>
1582 class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT>
1585 using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass;
1588 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1589 using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
1592 using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
1594 explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1595 _ThisCommonOptionFieldClass {libObjPtr}
1597 BT_ASSERT_DBG(this->isOptionWithSelector());
1600 template <typename OtherLibObjT>
1601 CommonOptionWithSelectorFieldClass(
1602 const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
1603 _ThisCommonOptionFieldClass {fc}
1607 template <typename OtherLibObjT>
1608 CommonOptionWithSelectorFieldClass&
1609 operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
1611 _ThisCommonOptionFieldClass::operator=(fc);
1615 CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
1617 return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this};
1620 ConstFieldPath selectorFieldPath() const noexcept
1622 return ConstFieldPath {
1623 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1624 this->libObjPtr())};
1627 Shared shared() const noexcept
1629 return Shared::createWithRef(*this);
1633 using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>;
1634 using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>;
1636 namespace internal {
1638 struct OptionWithSelectorFieldClassTypeDescr
1640 using Const = ConstOptionWithSelectorFieldClass;
1641 using NonConst = OptionWithSelectorFieldClass;
1645 struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1650 struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1654 } /* namespace internal */
1656 template <typename LibObjT>
1657 class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1660 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1662 using typename CommonOptionWithSelectorFieldClass<
1663 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1666 using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
1668 explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1669 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1671 BT_ASSERT_DBG(this->isOptionWithBoolSelector());
1674 template <typename OtherLibObjT>
1675 CommonOptionWithBoolSelectorFieldClass(
1676 const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept :
1677 _ThisCommonOptionWithSelectorFieldClass {fc}
1681 template <typename OtherLibObjT>
1682 CommonOptionWithBoolSelectorFieldClass&
1683 operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
1685 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1689 CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept
1691 return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this};
1694 bool selectorIsReversed() const noexcept
1696 return bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1700 Shared shared() const noexcept
1702 return Shared::createWithRef(*this);
1706 using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>;
1708 using ConstOptionWithBoolSelectorFieldClass =
1709 CommonOptionWithBoolSelectorFieldClass<const bt_field_class>;
1711 namespace internal {
1713 struct OptionWithBoolSelectorFieldClassTypeDescr
1715 using Const = ConstOptionWithBoolSelectorFieldClass;
1716 using NonConst = OptionWithBoolSelectorFieldClass;
1720 struct TypeDescr<OptionWithBoolSelectorFieldClass> :
1721 public OptionWithBoolSelectorFieldClassTypeDescr
1726 struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> :
1727 public OptionWithBoolSelectorFieldClassTypeDescr
1731 template <typename RangeSetT>
1732 struct CommonOptionWithIntegerSelectorFieldClassSpec;
1734 /* Functions specific to option field classes with unsigned integer ranges */
1736 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final
1738 static const bt_integer_range_set_unsigned *
1739 ranges(const bt_field_class * const libObjPtr) noexcept
1741 return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1746 /* Functions specific to option field classes with signed ranges */
1748 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final
1750 static const bt_integer_range_set_signed *
1751 ranges(const bt_field_class * const libObjPtr) noexcept
1753 return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1758 } /* namespace internal */
1760 template <typename LibObjT, typename RangeSetT>
1761 class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1764 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1766 using typename CommonOptionWithSelectorFieldClass<
1767 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1769 using _ThisCommonOptionWithIntegerSelectorFieldClass =
1770 CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
1773 using Shared = SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
1775 using RangeSet = RangeSetT;
1777 explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1778 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1780 BT_ASSERT_DBG(this->isOptionWithIntegerSelector());
1783 template <typename OtherLibObjT>
1784 CommonOptionWithIntegerSelectorFieldClass(
1785 const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept :
1786 _ThisCommonOptionWithSelectorFieldClass {fc}
1790 template <typename OtherLibObjT>
1791 CommonOptionWithIntegerSelectorFieldClass&
1792 operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
1794 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1798 RangeSet ranges() const noexcept
1800 return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges(
1801 this->libObjPtr())};
1804 Shared shared() const noexcept
1806 return Shared::createWithRef(*this);
1810 using OptionWithUnsignedIntegerSelectorFieldClass =
1811 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>;
1813 using ConstOptionWithUnsignedIntegerSelectorFieldClass =
1814 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>;
1816 using OptionWithSignedIntegerSelectorFieldClass =
1817 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>;
1819 using ConstOptionWithSignedIntegerSelectorFieldClass =
1820 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>;
1822 namespace internal {
1824 struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1826 using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass;
1827 using NonConst = OptionWithUnsignedIntegerSelectorFieldClass;
1831 struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> :
1832 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1837 struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> :
1838 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1842 struct OptionWithSignedIntegerSelectorFieldClassTypeDescr
1844 using Const = ConstOptionWithSignedIntegerSelectorFieldClass;
1845 using NonConst = OptionWithSignedIntegerSelectorFieldClass;
1849 struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> :
1850 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1855 struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> :
1856 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1860 template <typename LibObjT>
1861 struct CommonVariantFieldClassOptionSpec;
1863 /* Functions specific to mutable variant field class options */
1865 struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final
1867 static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept
1869 return bt_field_class_variant_option_borrow_field_class(libObjPtr);
1872 static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept
1874 return bt_field_class_variant_option_borrow_user_attributes(libObjPtr);
1878 /* Functions specific to constant variant field class options */
1880 struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final
1882 static const bt_field_class *
1883 fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept
1885 return bt_field_class_variant_option_borrow_field_class_const(libObjPtr);
1888 static const bt_value *
1889 userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept
1891 return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr);
1895 } /* namespace internal */
1897 template <typename LibObjT>
1898 class CommonVariantFieldClassOption : public BorrowedObject<LibObjT>
1901 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1902 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1903 using _FieldClass = internal::DepFc<LibObjT>;
1906 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1908 explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
1909 _ThisBorrowedObject {libObjPtr}
1913 template <typename OtherLibObjT>
1914 CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept :
1915 _ThisBorrowedObject {fc}
1919 template <typename OtherLibObjT>
1920 CommonVariantFieldClassOption&
1921 operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
1923 _ThisBorrowedObject::operator=(fc);
1927 CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept
1929 return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
1932 nonstd::optional<bpstd::string_view> name() const noexcept
1934 const auto name = bt_field_class_variant_option_get_name(this->libObjPtr());
1940 return nonstd::nullopt;
1943 _FieldClass fieldClass() const noexcept
1945 return _FieldClass {
1946 internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())};
1949 template <typename LibValT>
1950 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1952 static_assert(!std::is_const<LibObjT>::value,
1953 "Not available with `bt2::ConstVariantFieldClassOption`.");
1955 bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1958 UserAttributes userAttributes() const noexcept
1960 return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes(
1961 this->libObjPtr())};
1965 using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>;
1967 using ConstVariantFieldClassOption =
1968 CommonVariantFieldClassOption<const bt_field_class_variant_option>;
1970 namespace internal {
1972 struct VariantFieldClassOptionTypeDescr
1974 using Const = ConstVariantFieldClassOption;
1975 using NonConst = VariantFieldClassOption;
1979 struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
1984 struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
1988 template <typename LibObjT>
1989 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec;
1991 /* Functions specific to variant field class options with unsigned integer selector */
1993 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
1994 const bt_field_class_variant_with_selector_field_integer_unsigned_option>
1997 static const bt_integer_range_set_unsigned *
1998 ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option
1999 * const libObjPtr) noexcept
2001 return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
2005 static const bt_field_class_variant_option *
2006 asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option
2007 * const libObjPtr) noexcept
2009 return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const(
2014 /* Functions specific to variant field class options with signed integer selector */
2016 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
2017 const bt_field_class_variant_with_selector_field_integer_signed_option>
2020 static const bt_integer_range_set_signed *
2021 ranges(const bt_field_class_variant_with_selector_field_integer_signed_option
2022 * const libObjPtr) noexcept
2024 return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
2028 static const bt_field_class_variant_option *
2029 asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option
2030 * const libObjPtr) noexcept
2032 return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const(
2037 } /* namespace internal */
2039 template <typename LibObjT>
2040 class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT>
2043 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
2044 using typename BorrowedObject<LibObjT>::_LibObjPtr;
2045 using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
2048 using RangeSet = typename std::conditional<
2051 const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value,
2052 ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
2054 explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
2055 _ThisBorrowedObject {libObjPtr}
2059 template <typename OtherLibObjT>
2060 ConstVariantWithIntegerSelectorFieldClassOption(
2061 const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept :
2062 _ThisBorrowedObject {fc}
2066 template <typename OtherLibObjT>
2067 ConstVariantWithIntegerSelectorFieldClassOption&
2068 operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
2070 _ThisBorrowedObject::operator=(fc);
2074 ConstVariantFieldClassOption asBaseOption() const noexcept
2076 return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
2079 nonstd::optional<bpstd::string_view> name() const noexcept
2081 return this->asBaseOption().name();
2084 ConstFieldClass fieldClass() const noexcept
2086 return this->asBaseOption().fieldClass();
2089 RangeSet ranges() const noexcept
2091 return RangeSet {_Spec::ranges(this->libObjPtr())};
2095 using ConstVariantWithUnsignedIntegerSelectorFieldClassOption =
2096 ConstVariantWithIntegerSelectorFieldClassOption<
2097 const bt_field_class_variant_with_selector_field_integer_unsigned_option>;
2099 using ConstVariantWithSignedIntegerSelectorFieldClassOption =
2100 ConstVariantWithIntegerSelectorFieldClassOption<
2101 const bt_field_class_variant_with_selector_field_integer_signed_option>;
2103 namespace internal {
2105 template <typename LibObjT>
2106 struct CommonVariantFieldClassSpec;
2108 /* Functions specific to mutable variant field classes */
2110 struct CommonVariantFieldClassSpec<bt_field_class> final
2112 static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr,
2113 const std::uint64_t index) noexcept
2115 return bt_field_class_variant_borrow_option_by_index(libObjPtr, index);
2118 static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr,
2119 const char * const name) noexcept
2121 return bt_field_class_variant_borrow_option_by_name(libObjPtr, name);
2125 /* Functions specific to constant variant field classes */
2127 struct CommonVariantFieldClassSpec<const bt_field_class> final
2129 static const bt_field_class_variant_option *
2130 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2132 return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index);
2135 static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr,
2136 const char * const name) noexcept
2138 return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name);
2142 } /* namespace internal */
2144 template <typename LibObjT>
2145 class CommonVariantFieldClass : public CommonFieldClass<LibObjT>
2148 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
2151 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2152 using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
2155 using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
2158 internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>;
2160 using Iterator = CommonIterator<CommonVariantFieldClass, Option>;
2162 explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept :
2163 _ThisCommonFieldClass {libObjPtr}
2165 BT_ASSERT_DBG(this->isVariant());
2168 template <typename OtherLibObjT>
2169 CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept :
2170 _ThisCommonFieldClass {fc}
2174 template <typename OtherLibObjT>
2175 CommonVariantFieldClass& operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
2177 _ThisCommonFieldClass::operator=(fc);
2181 CommonVariantFieldClass<const bt_field_class> asConst() const noexcept
2183 return CommonVariantFieldClass<const bt_field_class> {*this};
2186 std::uint64_t length() const noexcept
2188 return bt_field_class_variant_get_option_count(this->libObjPtr());
2191 Iterator begin() const noexcept
2193 return Iterator {*this, 0};
2196 Iterator end() const noexcept
2198 return Iterator {*this, this->length()};
2201 Option operator[](const std::uint64_t index) const noexcept
2203 return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex(
2204 this->libObjPtr(), index)};
2207 nonstd::optional<Option> operator[](const char * const name) const noexcept
2209 const auto libObjPtr =
2210 internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name);
2213 return Option {libObjPtr};
2216 return nonstd::nullopt;
2219 nonstd::optional<Option> operator[](const std::string& name) const noexcept
2221 return (*this)[name.data()];
2224 Shared shared() const noexcept
2226 return Shared::createWithRef(*this);
2230 using VariantFieldClass = CommonVariantFieldClass<bt_field_class>;
2231 using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>;
2233 namespace internal {
2235 struct VariantFieldClassTypeDescr
2237 using Const = ConstVariantFieldClass;
2238 using NonConst = VariantFieldClass;
2242 struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr
2247 struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr
2251 } /* namespace internal */
2253 template <typename LibObjT>
2254 class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2257 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2258 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2261 using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
2263 explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2264 _ThisCommonVariantFieldClass {libObjPtr}
2266 BT_ASSERT_DBG(this->isVariantWithoutSelector());
2269 template <typename OtherLibObjT>
2270 CommonVariantWithoutSelectorFieldClass(
2271 const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept :
2272 _ThisCommonVariantFieldClass {fc}
2276 template <typename OtherLibObjT>
2277 CommonVariantWithoutSelectorFieldClass&
2278 operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
2280 _ThisCommonVariantFieldClass::operator=(fc);
2284 CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept
2286 return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this};
2289 void appendOption(const char * const name, const FieldClass fc) const
2291 static_assert(!std::is_const<LibObjT>::value,
2292 "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`.");
2294 const auto status = bt_field_class_variant_without_selector_append_option(
2295 this->libObjPtr(), name, fc.libObjPtr());
2298 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2299 throw MemoryError {};
2303 void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc) const
2305 this->appendOption(name ? name->data() : nullptr, fc);
2308 Shared shared() const noexcept
2310 return Shared::createWithRef(*this);
2314 using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>;
2315 using ConstVariantWithoutSelectorFieldClass =
2316 CommonVariantWithoutSelectorFieldClass<const bt_field_class>;
2318 namespace internal {
2320 struct VariantWithoutSelectorFieldClassTypeDescr
2322 using Const = ConstVariantWithoutSelectorFieldClass;
2323 using NonConst = VariantWithoutSelectorFieldClass;
2327 struct TypeDescr<VariantWithoutSelectorFieldClass> :
2328 public VariantWithoutSelectorFieldClassTypeDescr
2333 struct TypeDescr<ConstVariantWithoutSelectorFieldClass> :
2334 public VariantWithoutSelectorFieldClassTypeDescr
2338 template <typename OptionT>
2339 struct CommonVariantWithIntegerSelectorFieldClassSpec;
2341 /* Functions specific to variant field classes with unsigned integer selector */
2343 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2344 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2347 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2348 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2350 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
2354 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2355 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2357 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
2361 static bt_field_class_variant_with_selector_field_integer_append_option_status
2362 appendOption(bt_field_class * const libObjPtr, const char * const name,
2363 bt_field_class * const libOptFcPtr,
2364 const bt_integer_range_set_unsigned * const libRangesPtr)
2366 return bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
2367 libObjPtr, name, libOptFcPtr, libRangesPtr);
2371 /* Functions specific to variant field classes with signed integer selector */
2373 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2374 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2377 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2378 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2380 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
2384 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2385 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2387 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
2391 static bt_field_class_variant_with_selector_field_integer_append_option_status
2392 appendOption(bt_field_class * const libObjPtr, const char * const name,
2393 bt_field_class * const libOptFcPtr,
2394 const bt_integer_range_set_signed * const libRangesPtr)
2396 return bt_field_class_variant_with_selector_field_integer_signed_append_option(
2397 libObjPtr, name, libOptFcPtr, libRangesPtr);
2401 } /* namespace internal */
2403 template <typename LibObjT>
2404 class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2407 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2410 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2411 using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
2414 using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
2416 explicit CommonVariantWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2417 _ThisCommonVariantFieldClass {libObjPtr}
2419 BT_ASSERT_DBG(this->isVariantWithSelector());
2422 template <typename OtherLibObjT>
2423 CommonVariantWithSelectorFieldClass(
2424 const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
2425 _ThisCommonVariantFieldClass {fc}
2429 template <typename OtherLibObjT>
2430 CommonVariantWithSelectorFieldClass&
2431 operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
2433 _ThisCommonVariantFieldClass::operator=(fc);
2437 CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
2439 return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this};
2442 ConstFieldPath selectorFieldPath() const noexcept
2444 return ConstFieldPath {
2445 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
2446 this->libObjPtr())};
2449 Shared shared() const noexcept
2451 return Shared::createWithRef(*this);
2455 using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>;
2456 using ConstVariantWithSelectorFieldClass =
2457 CommonVariantWithSelectorFieldClass<const bt_field_class>;
2459 template <typename LibObjT, typename OptionT>
2460 class CommonVariantWithIntegerSelectorFieldClass :
2461 public CommonVariantWithSelectorFieldClass<LibObjT>
2464 using typename CommonVariantWithSelectorFieldClass<
2465 LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
2466 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2467 using _ThisCommonVariantWithIntegerSelectorFieldClass =
2468 CommonVariantWithIntegerSelectorFieldClass<LibObjT, OptionT>;
2470 using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
2473 using Shared = SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
2475 using Option = OptionT;
2477 CommonIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>, Option>;
2479 explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2480 _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
2482 BT_ASSERT_DBG(this->isVariant());
2485 template <typename OtherLibObjT>
2486 CommonVariantWithIntegerSelectorFieldClass(
2487 const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept :
2488 _ThisCommonVariantWithSelectorFieldClass {fc}
2492 template <typename OtherLibObjT>
2493 CommonVariantWithIntegerSelectorFieldClass&
2494 operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
2496 _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
2500 Option operator[](const std::uint64_t index) const noexcept
2502 return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
2505 nonstd::optional<Option> operator[](const char * const name) const noexcept
2507 const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name);
2510 return Option {libObjPtr};
2513 return nonstd::nullopt;
2516 nonstd::optional<Option> operator[](const std::string& name) const noexcept
2518 return (*this)[name.data()];
2521 void appendOption(const char * const name, const FieldClass fc,
2522 const typename Option::RangeSet ranges) const
2525 !std::is_const<LibObjT>::value,
2526 "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`.");
2529 _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr());
2532 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2533 throw MemoryError {};
2537 void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc,
2538 const typename Option::RangeSet ranges) const
2540 this->appendOption(name ? name->data() : nullptr, fc, ranges);
2543 Iterator begin() const noexcept
2545 return Iterator {*this, 0};
2548 Iterator end() const noexcept
2550 return Iterator {*this, this->length()};
2553 Shared shared() const noexcept
2555 return Shared::createWithRef(*this);
2559 using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2560 bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2562 using ConstVariantWithUnsignedIntegerSelectorFieldClass =
2563 CommonVariantWithIntegerSelectorFieldClass<
2564 const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2566 using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2567 bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2569 using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2570 const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2572 namespace internal {
2574 struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2576 using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass;
2577 using NonConst = VariantWithUnsignedIntegerSelectorFieldClass;
2581 struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> :
2582 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2587 struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> :
2588 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2592 struct VariantWithSignedIntegerSelectorFieldClassTypeDescr
2594 using Const = ConstVariantWithSignedIntegerSelectorFieldClass;
2595 using NonConst = VariantWithSignedIntegerSelectorFieldClass;
2599 struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> :
2600 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2605 struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> :
2606 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2610 } /* namespace internal */
2612 template <typename LibObjT>
2613 CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept
2615 BT_ASSERT_DBG(this->isBitArray());
2616 return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()};
2619 template <typename LibObjT>
2620 CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept
2622 BT_ASSERT_DBG(this->isInteger());
2623 return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()};
2626 template <typename LibObjT>
2627 CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept
2629 BT_ASSERT_DBG(this->isEnumeration());
2630 return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()};
2633 template <typename LibObjT>
2634 CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping>
2635 CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept
2637 BT_ASSERT_DBG(this->isUnsignedEnumeration());
2638 return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> {
2642 template <typename LibObjT>
2643 CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping>
2644 CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept
2646 BT_ASSERT_DBG(this->isSignedEnumeration());
2647 return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> {
2651 template <typename LibObjT>
2652 CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept
2654 BT_ASSERT_DBG(this->isStructure());
2655 return CommonStructureFieldClass<LibObjT> {this->libObjPtr()};
2658 template <typename LibObjT>
2659 CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept
2661 BT_ASSERT_DBG(this->isArray());
2662 return CommonArrayFieldClass<LibObjT> {this->libObjPtr()};
2665 template <typename LibObjT>
2666 CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept
2668 BT_ASSERT_DBG(this->isStaticArray());
2669 return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()};
2672 template <typename LibObjT>
2673 CommonDynamicArrayWithLengthFieldClass<LibObjT>
2674 CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept
2676 BT_ASSERT_DBG(this->isDynamicArrayWithLength());
2677 return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()};
2680 template <typename LibObjT>
2681 CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept
2683 BT_ASSERT_DBG(this->isOption());
2684 return CommonOptionFieldClass<LibObjT> {this->libObjPtr()};
2687 template <typename LibObjT>
2688 CommonOptionWithSelectorFieldClass<LibObjT>
2689 CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept
2691 BT_ASSERT_DBG(this->isOptionWithSelector());
2692 return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2695 template <typename LibObjT>
2696 CommonOptionWithBoolSelectorFieldClass<LibObjT>
2697 CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept
2699 BT_ASSERT_DBG(this->isOptionWithBoolSelector());
2700 return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()};
2703 template <typename LibObjT>
2704 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet>
2705 CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept
2707 BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector());
2708 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> {
2712 template <typename LibObjT>
2713 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet>
2714 CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept
2716 BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector());
2717 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> {
2721 template <typename LibObjT>
2722 CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept
2724 BT_ASSERT_DBG(this->isVariant());
2725 return CommonVariantFieldClass<LibObjT> {this->libObjPtr()};
2728 template <typename LibObjT>
2729 CommonVariantWithoutSelectorFieldClass<LibObjT>
2730 CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept
2732 BT_ASSERT_DBG(this->isVariantWithoutSelector());
2733 return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()};
2736 template <typename LibObjT>
2737 CommonVariantWithSelectorFieldClass<LibObjT>
2738 CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept
2740 BT_ASSERT_DBG(this->isVariantWithSelector());
2741 return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2744 template <typename LibObjT>
2745 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2746 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2747 CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept
2749 BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector());
2750 return CommonVariantWithIntegerSelectorFieldClass<
2751 LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2754 template <typename LibObjT>
2755 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2756 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2757 CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept
2759 BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector());
2760 return CommonVariantWithIntegerSelectorFieldClass<
2761 LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2764 } /* namespace bt2 */
2766 #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */