a8bbb3c462c5f8193810d0496e5d5c5bbd1a6d28
[babeltrace.git] / src / cpp-common / bt2 / field-class.hpp
1 /*
2 * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
9
10 #include <cstdint>
11 #include <type_traits>
12
13 #include <babeltrace2/babeltrace.h>
14
15 #include "common/assert.h"
16 #include "cpp-common/optional.hpp"
17 #include "cpp-common/string_view.hpp"
18
19 #include "borrowed-obj.hpp"
20 #include "common-iter.hpp"
21 #include "exc.hpp"
22 #include "field-path.hpp"
23 #include "integer-range-set.hpp"
24 #include "internal/shared-obj.hpp"
25 #include "internal/utils.hpp"
26 #include "value.hpp"
27
28 namespace bt2 {
29 namespace internal {
30
31 struct FieldClassRefFuncs final
32 {
33 static void get(const bt_field_class * const libObjPtr)
34 {
35 bt_field_class_get_ref(libObjPtr);
36 }
37
38 static void put(const bt_field_class * const libObjPtr)
39 {
40 bt_field_class_put_ref(libObjPtr);
41 }
42 };
43
44 template <typename ObjT, typename LibObjT>
45 using SharedFieldClass = internal::SharedObj<ObjT, LibObjT, internal::FieldClassRefFuncs>;
46
47 template <typename LibObjT>
48 struct CommonFieldClassSpec;
49
50 /* Functions specific to mutable field classes */
51 template <>
52 struct CommonFieldClassSpec<bt_field_class> final
53 {
54 static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept
55 {
56 return bt_field_class_borrow_user_attributes(libObjPtr);
57 }
58 };
59
60 /* Functions specific to constant field classes */
61 template <>
62 struct CommonFieldClassSpec<const bt_field_class> final
63 {
64 static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept
65 {
66 return bt_field_class_borrow_user_attributes_const(libObjPtr);
67 }
68 };
69
70 } /* namespace internal */
71
72 template <typename LibObjT>
73 class CommonBitArrayFieldClass;
74
75 template <typename LibObjT>
76 class CommonIntegerFieldClass;
77
78 template <typename LibObjT>
79 class ConstEnumerationFieldClassMapping;
80
81 template <typename LibObjT>
82 class CommonBaseEnumerationFieldClass;
83
84 template <typename LibObjT, typename MappingT>
85 class CommonEnumerationFieldClass;
86
87 template <typename LibObjT>
88 class CommonStructureFieldClass;
89
90 template <typename LibObjT>
91 class CommonArrayFieldClass;
92
93 template <typename LibObjT>
94 class CommonStaticArrayFieldClass;
95
96 template <typename LibObjT>
97 class CommonDynamicArrayWithLengthFieldClass;
98
99 template <typename LibObjT>
100 class CommonOptionFieldClass;
101
102 template <typename LibObjT>
103 class CommonOptionWithSelectorFieldClass;
104
105 template <typename LibObjT>
106 class CommonOptionWithBoolSelectorFieldClass;
107
108 template <typename LibObjT>
109 class CommonVariantFieldClass;
110
111 template <typename LibObjT, typename RangeSetT>
112 class CommonOptionWithIntegerSelectorFieldClass;
113
114 template <typename LibObjT>
115 class CommonVariantWithoutSelectorFieldClass;
116
117 template <typename LibObjT>
118 class CommonVariantWithSelectorFieldClass;
119
120 template <typename LibObjT>
121 class ConstVariantWithIntegerSelectorFieldClassOption;
122
123 template <typename LibObjT, typename RangeSetT>
124 class CommonVariantWithIntegerSelectorFieldClass;
125
126 template <typename LibObjT>
127 class CommonEventClass;
128
129 template <typename LibObjT>
130 class CommonStreamClass;
131
132 template <typename LibObjT>
133 class CommonTraceClass;
134
135 enum class FieldClassType
136 {
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,
161 };
162
163 template <typename LibObjT>
164 class CommonFieldClass : public BorrowedObj<LibObjT>
165 {
166 /* Allow appendMember() to call `fc.libObjPtr()` */
167 friend class CommonStructureFieldClass<bt_field_class>;
168
169 /* Allow appendOption() to call `fc.libObjPtr()` */
170 friend class CommonVariantWithoutSelectorFieldClass<bt_field_class>;
171
172 friend class CommonVariantWithIntegerSelectorFieldClass<
173 bt_field_class,
174 ConstVariantWithIntegerSelectorFieldClassOption<
175 const bt_field_class_variant_with_selector_field_integer_unsigned_option>>;
176
177 friend class CommonVariantWithIntegerSelectorFieldClass<
178 bt_field_class,
179 ConstVariantWithIntegerSelectorFieldClassOption<
180 const bt_field_class_variant_with_selector_field_integer_signed_option>>;
181
182 /* Allow *FieldClass() to call `fc.libObjPtr()` */
183 friend class CommonEventClass<bt_event_class>;
184 friend class CommonStreamClass<bt_stream_class>;
185
186 /* Allow create*FieldClass() to call `fc.libObjPtr()` */
187 friend class CommonTraceClass<bt_trace_class>;
188
189 private:
190 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
191
192 protected:
193 using typename BorrowedObj<LibObjT>::_LibObjPtr;
194 using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
195
196 public:
197 using Shared = internal::SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
198
199 using UserAttributes =
200 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
201
202 explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
203 {
204 }
205
206 template <typename OtherLibObjT>
207 CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObj {fc}
208 {
209 }
210
211 template <typename OtherLibObjT>
212 CommonFieldClass& operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
213 {
214 _ThisBorrowedObj::operator=(fc);
215 return *this;
216 }
217
218 FieldClassType type() const noexcept
219 {
220 return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr()));
221 }
222
223 bool isBool() const noexcept
224 {
225 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BOOL);
226 }
227
228 bool isBitArray() const noexcept
229 {
230 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BIT_ARRAY);
231 }
232
233 bool isInteger() const noexcept
234 {
235 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_INTEGER);
236 }
237
238 bool isUnsignedInteger() const noexcept
239 {
240 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
241 }
242
243 bool isSignedInteger() const noexcept
244 {
245 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_INTEGER);
246 }
247
248 bool isEnumeration() const noexcept
249 {
250 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ENUMERATION);
251 }
252
253 bool isUnsignedEnumeration() const noexcept
254 {
255 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION);
256 }
257
258 bool isSignedEnumeration() const noexcept
259 {
260 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
261 }
262
263 bool isReal() const noexcept
264 {
265 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_REAL);
266 }
267
268 bool isSinglePrecisionReal() const noexcept
269 {
270 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
271 }
272
273 bool isDoublePrecisionReal() const noexcept
274 {
275 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL);
276 }
277
278 bool isString() const noexcept
279 {
280 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRING);
281 }
282
283 bool isStructure() const noexcept
284 {
285 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRUCTURE);
286 }
287
288 bool isArray() const noexcept
289 {
290 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ARRAY);
291 }
292
293 bool isStaticArray() const noexcept
294 {
295 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STATIC_ARRAY);
296 }
297
298 bool isDynamicArray() const noexcept
299 {
300 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
301 }
302
303 bool isDynamicArrayWithoutLength() const noexcept
304 {
305 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD);
306 }
307
308 bool isDynamicArrayWithLength() const noexcept
309 {
310 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD);
311 }
312
313 bool isOption() const noexcept
314 {
315 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION);
316 }
317
318 bool isOptionWithoutSelector() const noexcept
319 {
320 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD);
321 }
322
323 bool isOptionWithSelector() const noexcept
324 {
325 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD);
326 }
327
328 bool isOptionWithBoolSelector() const noexcept
329 {
330 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD);
331 }
332
333 bool isOptionWithIntegerSelector() const noexcept
334 {
335 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_INTEGER_SELECTOR_FIELD);
336 }
337
338 bool isOptionWithUnsignedIntegerSelector() const noexcept
339 {
340 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD);
341 }
342
343 bool isOptionWithSignedIntegerSelector() const noexcept
344 {
345 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
346 }
347
348 bool isVariant() const noexcept
349 {
350 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT);
351 }
352
353 bool isVariantWithoutSelector() const noexcept
354 {
355 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD);
356 }
357
358 bool isVariantWithSelector() const noexcept
359 {
360 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD);
361 }
362
363 bool isVariantWithIntegerSelector() const noexcept
364 {
365 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_INTEGER_SELECTOR_FIELD);
366 }
367
368 bool isVariantWithUnsignedIntegerSelector() const noexcept
369 {
370 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD);
371 }
372
373 bool isVariantWithSignedIntegerSelector() const noexcept
374 {
375 return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
376 }
377
378 template <typename FieldClassT>
379 FieldClassT as() const noexcept
380 {
381 return FieldClassT {this->libObjPtr()};
382 }
383
384 CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept;
385 CommonIntegerFieldClass<LibObjT> asInteger() const noexcept;
386 CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept;
387 CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping<
388 const bt_field_class_enumeration_unsigned_mapping>>
389 asUnsignedEnumeration() const noexcept;
390
391 CommonEnumerationFieldClass<
392 LibObjT, ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>>
393 asSignedEnumeration() const noexcept;
394
395 CommonStructureFieldClass<LibObjT> asStructure() const noexcept;
396 CommonArrayFieldClass<LibObjT> asArray() const noexcept;
397 CommonStaticArrayFieldClass<LibObjT> asStaticArray() const noexcept;
398 CommonDynamicArrayWithLengthFieldClass<LibObjT> asDynamicArrayWithLength() const noexcept;
399 CommonOptionFieldClass<LibObjT> asOption() const noexcept;
400 CommonOptionWithSelectorFieldClass<LibObjT> asOptionWithSelector() const noexcept;
401 CommonOptionWithBoolSelectorFieldClass<LibObjT> asOptionWithBoolSelector() const noexcept;
402
403 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet>
404 asOptionWithUnsignedIntegerSelector() const noexcept;
405
406 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet>
407 asOptionWithSignedIntegerSelector() const noexcept;
408
409 CommonVariantFieldClass<LibObjT> asVariant() const noexcept;
410 CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept;
411 CommonVariantWithSelectorFieldClass<LibObjT> asVariantWithSelector() const noexcept;
412
413 CommonVariantWithIntegerSelectorFieldClass<
414 LibObjT, ConstVariantWithIntegerSelectorFieldClassOption<
415 const bt_field_class_variant_with_selector_field_integer_unsigned_option>>
416 asVariantWithUnsignedIntegerSelector() const noexcept;
417
418 CommonVariantWithIntegerSelectorFieldClass<
419 LibObjT, ConstVariantWithIntegerSelectorFieldClassOption<
420 const bt_field_class_variant_with_selector_field_integer_signed_option>>
421 asVariantWithSignedIntegerSelector() const noexcept;
422
423 template <typename LibValT>
424 void userAttributes(const CommonMapValue<LibValT> userAttrs)
425 {
426 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
427
428 bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
429 }
430
431 ConstMapValue userAttributes() const noexcept
432 {
433 return ConstMapValue {internal::CommonFieldClassSpec<const bt_field_class>::userAttributes(
434 this->libObjPtr())};
435 }
436
437 UserAttributes userAttributes() noexcept
438 {
439 return UserAttributes {
440 internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
441 }
442
443 Shared shared() const noexcept
444 {
445 return Shared::createWithRef(*this);
446 }
447
448 protected:
449 bool _libTypeIs(const bt_field_class_type type) const noexcept
450 {
451 return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type);
452 }
453 };
454
455 using FieldClass = CommonFieldClass<bt_field_class>;
456 using ConstFieldClass = CommonFieldClass<const bt_field_class>;
457
458 namespace internal {
459
460 struct FieldClassTypeDescr
461 {
462 using Const = ConstFieldClass;
463 using NonConst = FieldClass;
464 };
465
466 template <>
467 struct TypeDescr<FieldClass> : public FieldClassTypeDescr
468 {
469 };
470
471 template <>
472 struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr
473 {
474 };
475
476 } /* namespace internal */
477
478 template <typename LibObjT>
479 class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT>
480 {
481 private:
482 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
483 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
484
485 public:
486 using Shared = internal::SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
487
488 explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
489 _ThisCommonFieldClass {libObjPtr}
490 {
491 BT_ASSERT_DBG(this->isBitArray());
492 }
493
494 template <typename OtherLibObjT>
495 CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept :
496 _ThisCommonFieldClass {fc}
497 {
498 }
499
500 template <typename OtherLibObjT>
501 CommonBitArrayFieldClass<LibObjT>&
502 operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
503 {
504 _ThisCommonFieldClass::operator=(fc);
505 return *this;
506 }
507
508 std::uint64_t length() const noexcept
509 {
510 return bt_field_class_bit_array_get_length(this->libObjPtr());
511 }
512
513 Shared shared() const noexcept
514 {
515 return Shared::createWithRef(*this);
516 }
517 };
518
519 using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>;
520 using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>;
521
522 namespace internal {
523
524 struct BitArrayFieldClassTypeDescr
525 {
526 using Const = ConstBitArrayFieldClass;
527 using NonConst = BitArrayFieldClass;
528 };
529
530 template <>
531 struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr
532 {
533 };
534
535 template <>
536 struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr
537 {
538 };
539
540 } /* namespace internal */
541
542 enum class DisplayBase
543 {
544 BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY,
545 OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL,
546 DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL,
547 HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL,
548 };
549
550 template <typename LibObjT>
551 class CommonIntegerFieldClass : public CommonFieldClass<LibObjT>
552 {
553 private:
554 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
555
556 protected:
557 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
558 using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
559
560 public:
561 using Shared = internal::SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
562
563 explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept :
564 _ThisCommonFieldClass {libObjPtr}
565 {
566 BT_ASSERT_DBG(this->isInteger());
567 }
568
569 template <typename OtherLibObjT>
570 CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept :
571 _ThisCommonFieldClass {fc}
572 {
573 }
574
575 template <typename OtherLibObjT>
576 CommonIntegerFieldClass& operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
577 {
578 _ThisCommonFieldClass::operator=(fc);
579 return *this;
580 }
581
582 void fieldValueRange(const std::uint64_t n) noexcept
583 {
584 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
585
586 bt_field_class_integer_set_field_value_range(this->libObjPtr(), n);
587 }
588
589 std::uint64_t fieldValueRange() const noexcept
590 {
591 return bt_field_class_integer_get_field_value_range(this->libObjPtr());
592 }
593
594 void preferredDisplayBase(const DisplayBase base) noexcept
595 {
596 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
597
598 bt_field_class_integer_set_preferred_display_base(
599 this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
600 }
601
602 DisplayBase preferredDisplayBase() const noexcept
603 {
604 return static_cast<DisplayBase>(
605 bt_field_class_integer_get_preferred_display_base(this->libObjPtr()));
606 }
607
608 Shared shared() const noexcept
609 {
610 return Shared::createWithRef(*this);
611 }
612 };
613
614 using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>;
615 using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>;
616
617 namespace internal {
618
619 struct IntegerFieldClassTypeDescr
620 {
621 using Const = ConstIntegerFieldClass;
622 using NonConst = IntegerFieldClass;
623 };
624
625 template <>
626 struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr
627 {
628 };
629
630 template <>
631 struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
632 {
633 };
634
635 } /* namespace internal */
636
637 namespace internal {
638
639 template <typename LibObjT>
640 struct ConstEnumerationFieldClassMappingSpec;
641
642 /* Functions specific to unsigned enumeration field class mappings */
643 template <>
644 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping>
645 final
646 {
647 static const bt_integer_range_set_unsigned *
648 ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
649 {
650 return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr);
651 }
652
653 static const char *
654 label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept
655 {
656 return bt_field_class_enumeration_mapping_get_label(
657 bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr));
658 }
659 };
660
661 /* Functions specific to signed enumeration field class mappings */
662 template <>
663 struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final
664 {
665 static const bt_integer_range_set_signed *
666 ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
667 {
668 return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr);
669 }
670
671 static const char *
672 label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept
673 {
674 return bt_field_class_enumeration_mapping_get_label(
675 bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr));
676 }
677 };
678
679 } /* namespace internal */
680
681 template <typename LibObjT>
682 class ConstEnumerationFieldClassMapping final : public BorrowedObj<LibObjT>
683 {
684 private:
685 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
686 using typename BorrowedObj<LibObjT>::_LibObjPtr;
687
688 public:
689 using RangeSet = typename std::conditional<
690 std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value,
691 ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
692
693 explicit ConstEnumerationFieldClassMapping(const _LibObjPtr libObjPtr) noexcept :
694 _ThisBorrowedObj {libObjPtr}
695 {
696 }
697
698 ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept :
699 _ThisBorrowedObj {mapping}
700 {
701 }
702
703 ConstEnumerationFieldClassMapping&
704 operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept
705 {
706 _ThisBorrowedObj::operator=(mapping);
707 return *this;
708 }
709
710 RangeSet ranges() const noexcept
711 {
712 return RangeSet {
713 internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
714 }
715
716 bpstd::string_view label() const noexcept
717 {
718 return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
719 }
720 };
721
722 using ConstUnsignedEnumerationFieldClassMapping =
723 ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_unsigned_mapping>;
724
725 using ConstSignedEnumerationFieldClassMapping =
726 ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>;
727
728 namespace internal {
729
730 template <typename MappingT>
731 struct CommonEnumerationFieldClassSpec;
732
733 /* Functions specific to unsigned enumeration field classes */
734 template <>
735 struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping> final
736 {
737 static const bt_field_class_enumeration_unsigned_mapping *
738 mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
739 {
740 return bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(libObjPtr, index);
741 }
742
743 static const bt_field_class_enumeration_unsigned_mapping *
744 mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept
745 {
746 return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label);
747 }
748
749 static bt_field_class_enumeration_add_mapping_status
750 addMapping(bt_field_class * const libObjPtr, const char * const label,
751 const bt_integer_range_set_unsigned * const libRanges) noexcept
752 {
753 return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges);
754 }
755 };
756
757 /* Functions specific to signed enumeration field classes */
758 template <>
759 struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping> final
760 {
761 static const bt_field_class_enumeration_signed_mapping *
762 mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
763 {
764 return bt_field_class_enumeration_signed_borrow_mapping_by_index_const(libObjPtr, index);
765 }
766
767 static const bt_field_class_enumeration_signed_mapping *
768 mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept
769 {
770 return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label);
771 }
772
773 static bt_field_class_enumeration_add_mapping_status
774 addMapping(bt_field_class * const libObjPtr, const char * const label,
775 const bt_integer_range_set_signed * const libRanges) noexcept
776 {
777 return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges);
778 }
779 };
780
781 } /* namespace internal */
782
783 template <typename LibObjT>
784 class CommonBaseEnumerationFieldClass : public CommonIntegerFieldClass<LibObjT>
785 {
786 private:
787 using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass;
788
789 protected:
790 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
791 using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
792
793 public:
794 using Shared = internal::SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
795
796 explicit CommonBaseEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
797 _ThisCommonIntegerFieldClass {libObjPtr}
798 {
799 BT_ASSERT_DBG(this->isEnumeration());
800 }
801
802 template <typename OtherLibObjT>
803 CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
804 :
805 _ThisCommonIntegerFieldClass {fc}
806 {
807 }
808
809 template <typename OtherLibObjT>
810 CommonBaseEnumerationFieldClass&
811 operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
812 {
813 _ThisCommonIntegerFieldClass::operator=(fc);
814 return *this;
815 }
816
817 std::uint64_t size() const noexcept
818 {
819 return bt_field_class_enumeration_get_mapping_count(this->libObjPtr());
820 }
821
822 Shared shared() const noexcept
823 {
824 return Shared::createWithRef(*this);
825 }
826 };
827
828 template <typename LibObjT, typename MappingT>
829 class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT>
830 {
831 private:
832 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
833 using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
834 using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
835
836 public:
837 using Shared = internal::SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
838 using Iterator = CommonIterator<CommonEnumerationFieldClass, MappingT>;
839 using Mapping = MappingT;
840
841 explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
842 _ThisCommonBaseEnumerationFieldClass {libObjPtr}
843 {
844 BT_ASSERT_DBG(this->isEnumeration());
845 }
846
847 template <typename OtherLibObjT>
848 CommonEnumerationFieldClass(
849 const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept :
850 _ThisCommonEnumerationFieldClass {fc}
851 {
852 }
853
854 template <typename OtherLibObjT>
855 CommonEnumerationFieldClass&
856 operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept
857 {
858 _ThisCommonEnumerationFieldClass::operator=(fc);
859 return *this;
860 }
861
862 Mapping operator[](const std::uint64_t index) const noexcept
863 {
864 return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex(
865 this->libObjPtr(), index)};
866 }
867
868 nonstd::optional<Mapping> operator[](const char * const label) const noexcept
869 {
870 const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
871 this->libObjPtr(), label);
872
873 if (libObjPtr) {
874 return Mapping {libObjPtr};
875 }
876
877 return nonstd::nullopt;
878 }
879
880 nonstd::optional<Mapping> operator[](const std::string& label) const noexcept
881 {
882 return (*this)[label.data()];
883 }
884
885 void addMapping(const char * const label, const typename Mapping::RangeSet ranges)
886 {
887 const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
888 this->libObjPtr(), label, ranges.libObjPtr());
889
890 if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
891 throw MemoryError {};
892 }
893 }
894
895 void addMapping(const std::string& label, const typename Mapping::RangeSet ranges)
896 {
897 this->addMapping(label.data(), ranges);
898 }
899
900 Iterator begin() const noexcept
901 {
902 return Iterator {*this, 0};
903 }
904
905 Iterator end() const noexcept
906 {
907 return Iterator {*this, this->size()};
908 }
909
910 Shared shared() const noexcept
911 {
912 return Shared::createWithRef(*this);
913 }
914 };
915
916 using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>;
917 using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>;
918
919 using UnsignedEnumerationFieldClass =
920 CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
921
922 using ConstUnsignedEnumerationFieldClass =
923 CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>;
924
925 using SignedEnumerationFieldClass =
926 CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>;
927
928 using ConstSignedEnumerationFieldClass =
929 CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>;
930
931 namespace internal {
932
933 struct UnsignedEnumerationFieldClassTypeDescr
934 {
935 using Const = ConstUnsignedEnumerationFieldClass;
936 using NonConst = UnsignedEnumerationFieldClass;
937 };
938
939 template <>
940 struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
941 {
942 };
943
944 template <>
945 struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr
946 {
947 };
948
949 struct SignedEnumerationFieldClassTypeDescr
950 {
951 using Const = ConstSignedEnumerationFieldClass;
952 using NonConst = SignedEnumerationFieldClass;
953 };
954
955 template <>
956 struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
957 {
958 };
959
960 template <>
961 struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr
962 {
963 };
964
965 template <typename LibObjT>
966 struct CommonStructureFieldClassMemberSpec;
967
968 /* Functions specific to mutable structure field class members */
969 template <>
970 struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final
971 {
972 static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept
973 {
974 return bt_field_class_structure_member_borrow_field_class(libObjPtr);
975 }
976
977 static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept
978 {
979 return bt_field_class_structure_member_borrow_user_attributes(libObjPtr);
980 }
981 };
982
983 /* Functions specific to constant structure field class members */
984 template <>
985 struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final
986 {
987 static const bt_field_class *
988 fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept
989 {
990 return bt_field_class_structure_member_borrow_field_class_const(libObjPtr);
991 }
992
993 static const bt_value *
994 userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept
995 {
996 return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr);
997 }
998 };
999
1000 } /* namespace internal */
1001
1002 template <typename LibObjT>
1003 class CommonStructureFieldClassMember final : public BorrowedObj<LibObjT>
1004 {
1005 private:
1006 using typename BorrowedObj<LibObjT>::_LibObjPtr;
1007 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
1008
1009 using _FieldClass =
1010 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1011
1012 public:
1013 using UserAttributes =
1014 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1015
1016 explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept :
1017 _ThisBorrowedObj {libObjPtr}
1018 {
1019 }
1020
1021 template <typename OtherLibObjT>
1022 CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
1023 :
1024 _ThisBorrowedObj {fc}
1025 {
1026 }
1027
1028 template <typename OtherLibObjT>
1029 CommonStructureFieldClassMember<LibObjT>&
1030 operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
1031 {
1032 _ThisBorrowedObj::operator=(fc);
1033 return *this;
1034 }
1035
1036 bpstd::string_view name() const noexcept
1037 {
1038 return bt_field_class_structure_member_get_name(this->libObjPtr());
1039 }
1040
1041 ConstFieldClass fieldClass() const noexcept
1042 {
1043 return ConstFieldClass {internal::CommonStructureFieldClassMemberSpec<
1044 const bt_field_class_structure_member>::fieldClass(this->libObjPtr())};
1045 }
1046
1047 _FieldClass fieldClass() noexcept
1048 {
1049 return _FieldClass {
1050 internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())};
1051 }
1052
1053 template <typename LibValT>
1054 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1055 {
1056 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1057
1058 bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
1059 userAttrs.libObjPtr());
1060 }
1061
1062 ConstMapValue userAttributes() const noexcept
1063 {
1064 return ConstMapValue {internal::CommonStructureFieldClassMemberSpec<
1065 const bt_field_class_structure_member>::userAttributes(this->libObjPtr())};
1066 }
1067
1068 UserAttributes userAttributes() noexcept
1069 {
1070 return UserAttributes {
1071 internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes(
1072 this->libObjPtr())};
1073 }
1074 };
1075
1076 using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>;
1077
1078 using ConstStructureFieldClassMember =
1079 CommonStructureFieldClassMember<const bt_field_class_structure_member>;
1080
1081 namespace internal {
1082
1083 struct StructureFieldClassMemberTypeDescr
1084 {
1085 using Const = ConstStructureFieldClassMember;
1086 using NonConst = StructureFieldClassMember;
1087 };
1088
1089 template <>
1090 struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1091 {
1092 };
1093
1094 template <>
1095 struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr
1096 {
1097 };
1098
1099 template <typename LibObjT>
1100 struct CommonStructureFieldClassSpec;
1101
1102 /* Functions specific to mutable structure field classes */
1103 template <>
1104 struct CommonStructureFieldClassSpec<bt_field_class> final
1105 {
1106 static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr,
1107 const std::uint64_t index) noexcept
1108 {
1109 return bt_field_class_structure_borrow_member_by_index(libObjPtr, index);
1110 }
1111
1112 static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr,
1113 const char * const name) noexcept
1114 {
1115 return bt_field_class_structure_borrow_member_by_name(libObjPtr, name);
1116 }
1117 };
1118
1119 /* Functions specific to constant structure field classes */
1120 template <>
1121 struct CommonStructureFieldClassSpec<const bt_field_class> final
1122 {
1123 static const bt_field_class_structure_member *
1124 memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
1125 {
1126 return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index);
1127 }
1128
1129 static const bt_field_class_structure_member *
1130 memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
1131 {
1132 return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name);
1133 }
1134 };
1135
1136 } /* namespace internal */
1137
1138 template <typename LibObjT>
1139 class CommonStructureFieldClass final : public CommonFieldClass<LibObjT>
1140 {
1141 private:
1142 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1143 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1144
1145 public:
1146 using Shared = internal::SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
1147 using Member =
1148 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember,
1149 StructureFieldClassMember>::type;
1150
1151 using Iterator = CommonIterator<CommonStructureFieldClass<LibObjT>, Member>;
1152
1153 explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept :
1154 _ThisCommonFieldClass {libObjPtr}
1155 {
1156 BT_ASSERT_DBG(this->isStructure());
1157 }
1158
1159 template <typename OtherLibObjT>
1160 CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept :
1161 _ThisCommonFieldClass {fc}
1162 {
1163 }
1164
1165 template <typename OtherLibObjT>
1166 CommonStructureFieldClass& operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
1167 {
1168 _ThisCommonFieldClass::operator=(fc);
1169 return *this;
1170 }
1171
1172 void appendMember(const char * const name, const FieldClass fc)
1173 {
1174 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1175
1176 const auto status =
1177 bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
1178
1179 if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) {
1180 throw MemoryError {};
1181 }
1182 }
1183
1184 void appendMember(const std::string& name, const FieldClass fc)
1185 {
1186 this->appendMember(name.data(), fc);
1187 }
1188
1189 std::uint64_t size() const noexcept
1190 {
1191 return bt_field_class_structure_get_member_count(this->libObjPtr());
1192 }
1193
1194 Iterator begin() const noexcept
1195 {
1196 return Iterator {*this, 0};
1197 }
1198
1199 Iterator end() const noexcept
1200 {
1201 return Iterator {*this, this->size()};
1202 }
1203
1204 ConstStructureFieldClassMember operator[](const std::uint64_t index) const noexcept
1205 {
1206 return ConstStructureFieldClassMember {
1207 internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByIndex(
1208 this->libObjPtr(), index)};
1209 }
1210
1211 Member operator[](const std::uint64_t index) noexcept
1212 {
1213 return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex(
1214 this->libObjPtr(), index)};
1215 }
1216
1217 nonstd::optional<ConstStructureFieldClassMember>
1218 operator[](const char * const name) const noexcept
1219 {
1220 const auto libObjPtr =
1221 internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByName(
1222 this->libObjPtr(), name);
1223
1224 if (libObjPtr) {
1225 return ConstStructureFieldClassMember {libObjPtr};
1226 }
1227
1228 return nonstd::nullopt;
1229 }
1230
1231 nonstd::optional<ConstStructureFieldClassMember>
1232 operator[](const std::string& name) const noexcept
1233 {
1234 return (*this)[name.data()];
1235 }
1236
1237 nonstd::optional<Member> operator[](const char * const name) noexcept
1238 {
1239 const auto libObjPtr =
1240 internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name);
1241
1242 if (libObjPtr) {
1243 return Member {libObjPtr};
1244 }
1245
1246 return nonstd::nullopt;
1247 }
1248
1249 nonstd::optional<Member> operator[](const std::string& name) noexcept
1250 {
1251 return (*this)[name.data()];
1252 }
1253
1254 Shared shared() const noexcept
1255 {
1256 return Shared::createWithRef(*this);
1257 }
1258 };
1259
1260 using StructureFieldClass = CommonStructureFieldClass<bt_field_class>;
1261 using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>;
1262
1263 namespace internal {
1264
1265 struct StructureFieldClassTypeDescr
1266 {
1267 using Const = ConstStructureFieldClass;
1268 using NonConst = StructureFieldClass;
1269 };
1270
1271 template <>
1272 struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr
1273 {
1274 };
1275
1276 template <>
1277 struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr
1278 {
1279 };
1280
1281 template <typename LibObjT>
1282 struct CommonArrayFieldClassSpec;
1283
1284 /* Functions specific to mutable array field classes */
1285 template <>
1286 struct CommonArrayFieldClassSpec<bt_field_class> final
1287 {
1288 static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept
1289 {
1290 return bt_field_class_array_borrow_element_field_class(libObjPtr);
1291 }
1292 };
1293
1294 /* Functions specific to constant array field classes */
1295 template <>
1296 struct CommonArrayFieldClassSpec<const bt_field_class> final
1297 {
1298 static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept
1299 {
1300 return bt_field_class_array_borrow_element_field_class_const(libObjPtr);
1301 }
1302 };
1303
1304 } /* namespace internal */
1305
1306 template <typename LibObjT>
1307 class CommonArrayFieldClass : public CommonFieldClass<LibObjT>
1308 {
1309 private:
1310 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1311
1312 using _FieldClass =
1313 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1314
1315 protected:
1316 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1317 using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
1318
1319 public:
1320 using Shared = internal::SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
1321
1322 explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
1323 _ThisCommonFieldClass {libObjPtr}
1324 {
1325 BT_ASSERT_DBG(this->isArray());
1326 }
1327
1328 template <typename OtherLibObjT>
1329 CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept :
1330 _ThisCommonFieldClass {fc}
1331 {
1332 }
1333
1334 template <typename OtherLibObjT>
1335 CommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
1336 {
1337 _ThisCommonFieldClass::operator=(fc);
1338 return *this;
1339 }
1340
1341 ConstFieldClass elementFieldClass() const noexcept
1342 {
1343 return ConstFieldClass {
1344 internal::CommonArrayFieldClassSpec<const bt_field_class>::elementFieldClass(
1345 this->libObjPtr())};
1346 }
1347
1348 _FieldClass elementFieldClass() noexcept
1349 {
1350 return _FieldClass {
1351 internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())};
1352 }
1353
1354 Shared shared() const noexcept
1355 {
1356 return Shared::createWithRef(*this);
1357 }
1358 };
1359
1360 using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>;
1361 using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>;
1362
1363 namespace internal {
1364
1365 struct ArrayFieldClassTypeDescr
1366 {
1367 using Const = ConstArrayFieldClass;
1368 using NonConst = ArrayFieldClass;
1369 };
1370
1371 template <>
1372 struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr
1373 {
1374 };
1375
1376 template <>
1377 struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr
1378 {
1379 };
1380
1381 } /* namespace internal */
1382
1383 template <typename LibObjT>
1384 class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT>
1385 {
1386 private:
1387 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1388 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1389
1390 public:
1391 using Shared = internal::SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
1392
1393 explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
1394 _ThisCommonArrayFieldClass {libObjPtr}
1395 {
1396 BT_ASSERT_DBG(this->isStaticArray());
1397 }
1398
1399 template <typename OtherLibObjT>
1400 CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept :
1401 _ThisCommonArrayFieldClass {fc}
1402 {
1403 }
1404
1405 template <typename OtherLibObjT>
1406 CommonStaticArrayFieldClass&
1407 operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
1408 {
1409 _ThisCommonArrayFieldClass::operator=(fc);
1410 return *this;
1411 }
1412
1413 std::uint64_t length() const noexcept
1414 {
1415 return bt_field_class_array_static_get_length(this->libObjPtr());
1416 }
1417
1418 Shared shared() const noexcept
1419 {
1420 return Shared::createWithRef(*this);
1421 }
1422 };
1423
1424 using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>;
1425 using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>;
1426
1427 namespace internal {
1428
1429 struct StaticArrayFieldClassTypeDescr
1430 {
1431 using Const = ConstStaticArrayFieldClass;
1432 using NonConst = StaticArrayFieldClass;
1433 };
1434
1435 template <>
1436 struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1437 {
1438 };
1439
1440 template <>
1441 struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr
1442 {
1443 };
1444
1445 } /* namespace internal */
1446
1447 template <typename LibObjT>
1448 class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT>
1449 {
1450 private:
1451 using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass;
1452 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1453
1454 public:
1455 using Shared =
1456 internal::SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
1457
1458 explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept :
1459 _ThisCommonArrayFieldClass {libObjPtr}
1460 {
1461 BT_ASSERT_DBG(this->isDynamicArrayWithLength());
1462 }
1463
1464 template <typename OtherLibObjT>
1465 CommonDynamicArrayWithLengthFieldClass(
1466 const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept :
1467 _ThisCommonArrayFieldClass {fc}
1468 {
1469 }
1470
1471 template <typename OtherLibObjT>
1472 CommonDynamicArrayWithLengthFieldClass&
1473 operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
1474 {
1475 _ThisCommonArrayFieldClass::operator=(fc);
1476 return *this;
1477 }
1478
1479 ConstFieldPath lengthFieldPath() const noexcept
1480 {
1481 return ConstFieldPath {
1482 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
1483 this->libObjPtr())};
1484 }
1485
1486 Shared shared() const noexcept
1487 {
1488 return Shared::createWithRef(*this);
1489 }
1490 };
1491
1492 using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>;
1493
1494 using ConstDynamicArrayWithLengthFieldClass =
1495 CommonDynamicArrayWithLengthFieldClass<const bt_field_class>;
1496
1497 namespace internal {
1498
1499 struct DynamicArrayWithLengthFieldClassTypeDescr
1500 {
1501 using Const = ConstDynamicArrayWithLengthFieldClass;
1502 using NonConst = DynamicArrayWithLengthFieldClass;
1503 };
1504
1505 template <>
1506 struct TypeDescr<DynamicArrayWithLengthFieldClass> :
1507 public DynamicArrayWithLengthFieldClassTypeDescr
1508 {
1509 };
1510
1511 template <>
1512 struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> :
1513 public DynamicArrayWithLengthFieldClassTypeDescr
1514 {
1515 };
1516
1517 template <typename LibObjT>
1518 struct CommonOptionFieldClassSpec;
1519
1520 /* Functions specific to mutable option field classes */
1521 template <>
1522 struct CommonOptionFieldClassSpec<bt_field_class> final
1523 {
1524 static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept
1525 {
1526 return bt_field_class_option_borrow_field_class(libObjPtr);
1527 }
1528 };
1529
1530 /* Functions specific to constant option field classes */
1531 template <>
1532 struct CommonOptionFieldClassSpec<const bt_field_class> final
1533 {
1534 static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept
1535 {
1536 return bt_field_class_option_borrow_field_class_const(libObjPtr);
1537 }
1538 };
1539
1540 } /* namespace internal */
1541
1542 template <typename LibObjT>
1543 class CommonOptionFieldClass : public CommonFieldClass<LibObjT>
1544 {
1545 private:
1546 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
1547
1548 using _FieldClass =
1549 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1550
1551 protected:
1552 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1553 using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
1554
1555 public:
1556 using Shared = internal::SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
1557
1558 explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept :
1559 _ThisCommonFieldClass {libObjPtr}
1560 {
1561 BT_ASSERT_DBG(this->isOption());
1562 }
1563
1564 template <typename OtherLibObjT>
1565 CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept :
1566 _ThisCommonFieldClass {fc}
1567 {
1568 }
1569
1570 template <typename OtherLibObjT>
1571 CommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
1572 {
1573 _ThisCommonFieldClass::operator=(fc);
1574 return *this;
1575 }
1576
1577 ConstFieldClass fieldClass() const noexcept
1578 {
1579 return ConstFieldClass {
1580 internal::CommonOptionFieldClassSpec<const bt_field_class>::fieldClass(
1581 this->libObjPtr())};
1582 }
1583
1584 _FieldClass fieldClass() noexcept
1585 {
1586 return _FieldClass {
1587 internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())};
1588 }
1589
1590 Shared shared() const noexcept
1591 {
1592 return Shared::createWithRef(*this);
1593 }
1594 };
1595
1596 using OptionFieldClass = CommonOptionFieldClass<bt_field_class>;
1597 using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>;
1598
1599 namespace internal {
1600
1601 struct OptionFieldClassTypeDescr
1602 {
1603 using Const = ConstOptionFieldClass;
1604 using NonConst = OptionFieldClass;
1605 };
1606
1607 template <>
1608 struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr
1609 {
1610 };
1611
1612 template <>
1613 struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr
1614 {
1615 };
1616
1617 } /* namespace internal */
1618
1619 template <typename LibObjT>
1620 class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT>
1621 {
1622 private:
1623 using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass;
1624
1625 protected:
1626 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1627 using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
1628
1629 public:
1630 using Shared = internal::SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
1631
1632 explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1633 _ThisCommonOptionFieldClass {libObjPtr}
1634 {
1635 BT_ASSERT_DBG(this->isOptionWithSelector());
1636 }
1637
1638 template <typename OtherLibObjT>
1639 CommonOptionWithSelectorFieldClass(
1640 const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
1641 _ThisCommonOptionFieldClass {fc}
1642 {
1643 }
1644
1645 template <typename OtherLibObjT>
1646 CommonOptionWithSelectorFieldClass&
1647 operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
1648 {
1649 _ThisCommonOptionFieldClass::operator=(fc);
1650 return *this;
1651 }
1652
1653 ConstFieldPath selectorFieldPath() const noexcept
1654 {
1655 return ConstFieldPath {
1656 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1657 this->libObjPtr())};
1658 }
1659
1660 Shared shared() const noexcept
1661 {
1662 return Shared::createWithRef(*this);
1663 }
1664 };
1665
1666 using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>;
1667 using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>;
1668
1669 namespace internal {
1670
1671 struct OptionWithSelectorFieldClassTypeDescr
1672 {
1673 using Const = ConstOptionWithSelectorFieldClass;
1674 using NonConst = OptionWithSelectorFieldClass;
1675 };
1676
1677 template <>
1678 struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1679 {
1680 };
1681
1682 template <>
1683 struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr
1684 {
1685 };
1686
1687 } /* namespace internal */
1688
1689 template <typename LibObjT>
1690 class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1691 {
1692 private:
1693 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1694
1695 using typename CommonOptionWithSelectorFieldClass<
1696 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1697
1698 public:
1699 using Shared =
1700 internal::SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
1701
1702 explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1703 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1704 {
1705 BT_ASSERT_DBG(this->isOptionWithBoolSelector());
1706 }
1707
1708 template <typename OtherLibObjT>
1709 CommonOptionWithBoolSelectorFieldClass(
1710 const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept :
1711 _ThisCommonOptionWithSelectorFieldClass {fc}
1712 {
1713 }
1714
1715 template <typename OtherLibObjT>
1716 CommonOptionWithBoolSelectorFieldClass&
1717 operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
1718 {
1719 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1720 return *this;
1721 }
1722
1723 bool selectorIsReversed() const noexcept
1724 {
1725 return bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1726 this->libObjPtr());
1727 }
1728
1729 Shared shared() const noexcept
1730 {
1731 return Shared::createWithRef(*this);
1732 }
1733 };
1734
1735 using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>;
1736
1737 using ConstOptionWithBoolSelectorFieldClass =
1738 CommonOptionWithBoolSelectorFieldClass<const bt_field_class>;
1739
1740 namespace internal {
1741
1742 struct OptionWithBoolSelectorFieldClassTypeDescr
1743 {
1744 using Const = ConstOptionWithBoolSelectorFieldClass;
1745 using NonConst = OptionWithBoolSelectorFieldClass;
1746 };
1747
1748 template <>
1749 struct TypeDescr<OptionWithBoolSelectorFieldClass> :
1750 public OptionWithBoolSelectorFieldClassTypeDescr
1751 {
1752 };
1753
1754 template <>
1755 struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> :
1756 public OptionWithBoolSelectorFieldClassTypeDescr
1757 {
1758 };
1759
1760 template <typename RangeSetT>
1761 struct CommonOptionWithIntegerSelectorFieldClassSpec;
1762
1763 /* Functions specific to option field classes with unsigned integer ranges */
1764 template <>
1765 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final
1766 {
1767 static const bt_integer_range_set_unsigned *
1768 ranges(const bt_field_class * const libObjPtr) noexcept
1769 {
1770 return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1771 libObjPtr);
1772 }
1773 };
1774
1775 /* Functions specific to option field classes with signed ranges */
1776 template <>
1777 struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final
1778 {
1779 static const bt_integer_range_set_signed *
1780 ranges(const bt_field_class * const libObjPtr) noexcept
1781 {
1782 return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1783 libObjPtr);
1784 }
1785 };
1786
1787 } /* namespace internal */
1788
1789 template <typename LibObjT, typename RangeSetT>
1790 class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT>
1791 {
1792 private:
1793 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
1794
1795 using typename CommonOptionWithSelectorFieldClass<
1796 LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
1797
1798 using _ThisCommonOptionWithIntegerSelectorFieldClass =
1799 CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
1800
1801 public:
1802 using Shared =
1803 internal::SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
1804
1805 using RangeSet = RangeSetT;
1806
1807 explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
1808 _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
1809 {
1810 BT_ASSERT_DBG(this->isOptionWithIntegerSelector());
1811 }
1812
1813 template <typename OtherLibObjT>
1814 CommonOptionWithIntegerSelectorFieldClass(
1815 const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept :
1816 _ThisCommonOptionWithSelectorFieldClass {fc}
1817 {
1818 }
1819
1820 template <typename OtherLibObjT>
1821 CommonOptionWithIntegerSelectorFieldClass&
1822 operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
1823 {
1824 _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
1825 return *this;
1826 }
1827
1828 RangeSet ranges() const noexcept
1829 {
1830 return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges(
1831 this->libObjPtr())};
1832 }
1833
1834 Shared shared() const noexcept
1835 {
1836 return Shared::createWithRef(*this);
1837 }
1838 };
1839
1840 using OptionWithUnsignedIntegerSelectorFieldClass =
1841 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>;
1842
1843 using ConstOptionWithUnsignedIntegerSelectorFieldClass =
1844 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>;
1845
1846 using OptionWithSignedIntegerSelectorFieldClass =
1847 CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>;
1848
1849 using ConstOptionWithSignedIntegerSelectorFieldClass =
1850 CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>;
1851
1852 namespace internal {
1853
1854 struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1855 {
1856 using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass;
1857 using NonConst = OptionWithUnsignedIntegerSelectorFieldClass;
1858 };
1859
1860 template <>
1861 struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> :
1862 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1863 {
1864 };
1865
1866 template <>
1867 struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> :
1868 public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr
1869 {
1870 };
1871
1872 struct OptionWithSignedIntegerSelectorFieldClassTypeDescr
1873 {
1874 using Const = ConstOptionWithSignedIntegerSelectorFieldClass;
1875 using NonConst = OptionWithSignedIntegerSelectorFieldClass;
1876 };
1877
1878 template <>
1879 struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> :
1880 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1881 {
1882 };
1883
1884 template <>
1885 struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> :
1886 public OptionWithSignedIntegerSelectorFieldClassTypeDescr
1887 {
1888 };
1889
1890 template <typename LibObjT>
1891 struct CommonVariantFieldClassOptionSpec;
1892
1893 /* Functions specific to mutable variant field class options */
1894 template <>
1895 struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final
1896 {
1897 static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept
1898 {
1899 return bt_field_class_variant_option_borrow_field_class(libObjPtr);
1900 }
1901
1902 static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept
1903 {
1904 return bt_field_class_variant_option_borrow_user_attributes(libObjPtr);
1905 }
1906 };
1907
1908 /* Functions specific to constant variant field class options */
1909 template <>
1910 struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final
1911 {
1912 static const bt_field_class *
1913 fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept
1914 {
1915 return bt_field_class_variant_option_borrow_field_class_const(libObjPtr);
1916 }
1917
1918 static const bt_value *
1919 userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept
1920 {
1921 return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr);
1922 }
1923 };
1924
1925 } /* namespace internal */
1926
1927 template <typename LibObjT>
1928 class CommonVariantFieldClassOption : public BorrowedObj<LibObjT>
1929 {
1930 private:
1931 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
1932 using typename BorrowedObj<LibObjT>::_LibObjPtr;
1933
1934 using _FieldClass =
1935 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
1936
1937 public:
1938 using UserAttributes =
1939 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1940
1941 explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
1942 _ThisBorrowedObj {libObjPtr}
1943 {
1944 }
1945
1946 template <typename OtherLibObjT>
1947 CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept :
1948 _ThisBorrowedObj {fc}
1949 {
1950 }
1951
1952 template <typename OtherLibObjT>
1953 CommonVariantFieldClassOption&
1954 operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
1955 {
1956 _ThisBorrowedObj::operator=(fc);
1957 return *this;
1958 }
1959
1960 nonstd::optional<bpstd::string_view> name() const noexcept
1961 {
1962 const auto name = bt_field_class_variant_option_get_name(this->libObjPtr());
1963
1964 if (name) {
1965 return name;
1966 }
1967
1968 return nonstd::nullopt;
1969 }
1970
1971 ConstFieldClass fieldClass() const noexcept
1972 {
1973 return ConstFieldClass {internal::CommonVariantFieldClassOptionSpec<
1974 const bt_field_class_variant_option>::fieldClass(this->libObjPtr())};
1975 }
1976
1977 _FieldClass fieldClass() noexcept
1978 {
1979 return _FieldClass {
1980 internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())};
1981 }
1982
1983 template <typename LibValT>
1984 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1985 {
1986 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1987
1988 bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1989 }
1990
1991 ConstMapValue userAttributes() const noexcept
1992 {
1993 return ConstMapValue {internal::CommonVariantFieldClassOptionSpec<
1994 const bt_field_class_variant_option>::userAttributes(this->libObjPtr())};
1995 }
1996
1997 UserAttributes userAttributes() noexcept
1998 {
1999 return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes(
2000 this->libObjPtr())};
2001 }
2002 };
2003
2004 using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>;
2005
2006 using ConstVariantFieldClassOption =
2007 CommonVariantFieldClassOption<const bt_field_class_variant_option>;
2008
2009 namespace internal {
2010
2011 struct VariantFieldClassOptionTypeDescr
2012 {
2013 using Const = ConstVariantFieldClassOption;
2014 using NonConst = VariantFieldClassOption;
2015 };
2016
2017 template <>
2018 struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
2019 {
2020 };
2021
2022 template <>
2023 struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr
2024 {
2025 };
2026
2027 template <typename LibObjT>
2028 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec;
2029
2030 /* Functions specific to variant field class options with unsigned integer selector */
2031 template <>
2032 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
2033 const bt_field_class_variant_with_selector_field_integer_unsigned_option>
2034 final
2035 {
2036 static const bt_integer_range_set_unsigned *
2037 ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option
2038 * const libObjPtr) noexcept
2039 {
2040 return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
2041 libObjPtr);
2042 }
2043
2044 static const bt_field_class_variant_option *
2045 asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option
2046 * const libObjPtr) noexcept
2047 {
2048 return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const(
2049 libObjPtr);
2050 }
2051 };
2052
2053 /* Functions specific to variant field class options with signed integer selector */
2054 template <>
2055 struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
2056 const bt_field_class_variant_with_selector_field_integer_signed_option>
2057 final
2058 {
2059 static const bt_integer_range_set_signed *
2060 ranges(const bt_field_class_variant_with_selector_field_integer_signed_option
2061 * const libObjPtr) noexcept
2062 {
2063 return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
2064 libObjPtr);
2065 }
2066
2067 static const bt_field_class_variant_option *
2068 asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option
2069 * const libObjPtr) noexcept
2070 {
2071 return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const(
2072 libObjPtr);
2073 }
2074 };
2075
2076 } /* namespace internal */
2077
2078 template <typename LibObjT>
2079 class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObj<LibObjT>
2080 {
2081 private:
2082 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
2083 using typename BorrowedObj<LibObjT>::_LibObjPtr;
2084 using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
2085
2086 public:
2087 using RangeSet = typename std::conditional<
2088 std::is_same<
2089 LibObjT,
2090 const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value,
2091 ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
2092
2093 explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
2094 _ThisBorrowedObj {libObjPtr}
2095 {
2096 }
2097
2098 template <typename OtherLibObjT>
2099 ConstVariantWithIntegerSelectorFieldClassOption(
2100 const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept :
2101 _ThisBorrowedObj {fc}
2102 {
2103 }
2104
2105 template <typename OtherLibObjT>
2106 ConstVariantWithIntegerSelectorFieldClassOption&
2107 operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
2108 {
2109 _ThisBorrowedObj::operator=(fc);
2110 return *this;
2111 }
2112
2113 ConstVariantFieldClassOption asBaseOption() const noexcept
2114 {
2115 return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
2116 }
2117
2118 nonstd::optional<bpstd::string_view> name() const noexcept
2119 {
2120 return this->asBaseOption().name();
2121 }
2122
2123 ConstFieldClass fieldClass() const noexcept
2124 {
2125 return this->asBaseOption().fieldClass();
2126 }
2127
2128 RangeSet ranges() const noexcept
2129 {
2130 return RangeSet {_Spec::ranges(this->libObjPtr())};
2131 }
2132 };
2133
2134 using ConstVariantWithUnsignedIntegerSelectorFieldClassOption =
2135 ConstVariantWithIntegerSelectorFieldClassOption<
2136 const bt_field_class_variant_with_selector_field_integer_unsigned_option>;
2137
2138 using ConstVariantWithSignedIntegerSelectorFieldClassOption =
2139 ConstVariantWithIntegerSelectorFieldClassOption<
2140 const bt_field_class_variant_with_selector_field_integer_signed_option>;
2141
2142 namespace internal {
2143
2144 template <typename LibObjT>
2145 struct CommonVariantFieldClassSpec;
2146
2147 /* Functions specific to mutable variant field classes */
2148 template <>
2149 struct CommonVariantFieldClassSpec<bt_field_class> final
2150 {
2151 static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr,
2152 const std::uint64_t index) noexcept
2153 {
2154 return bt_field_class_variant_borrow_option_by_index(libObjPtr, index);
2155 }
2156
2157 static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr,
2158 const char * const name) noexcept
2159 {
2160 return bt_field_class_variant_borrow_option_by_name(libObjPtr, name);
2161 }
2162 };
2163
2164 /* Functions specific to constant variant field classes */
2165 template <>
2166 struct CommonVariantFieldClassSpec<const bt_field_class> final
2167 {
2168 static const bt_field_class_variant_option *
2169 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2170 {
2171 return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index);
2172 }
2173
2174 static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr,
2175 const char * const name) noexcept
2176 {
2177 return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name);
2178 }
2179 };
2180
2181 } /* namespace internal */
2182
2183 template <typename LibObjT>
2184 class CommonVariantFieldClass : public CommonFieldClass<LibObjT>
2185 {
2186 private:
2187 using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
2188
2189 protected:
2190 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2191 using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
2192
2193 public:
2194 using Shared = internal::SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
2195
2196 using Option =
2197 typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption,
2198 VariantFieldClassOption>::type;
2199
2200 using Iterator = CommonIterator<CommonVariantFieldClass, Option>;
2201
2202 explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept :
2203 _ThisCommonFieldClass {libObjPtr}
2204 {
2205 BT_ASSERT_DBG(this->isVariant());
2206 }
2207
2208 template <typename OtherLibObjT>
2209 CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept :
2210 _ThisCommonFieldClass {fc}
2211 {
2212 }
2213
2214 template <typename OtherLibObjT>
2215 CommonVariantFieldClass& operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
2216 {
2217 _ThisCommonFieldClass::operator=(fc);
2218 return *this;
2219 }
2220
2221 std::uint64_t size() const noexcept
2222 {
2223 return bt_field_class_variant_get_option_count(this->libObjPtr());
2224 }
2225
2226 Iterator begin() const noexcept
2227 {
2228 return Iterator {*this, 0};
2229 }
2230
2231 Iterator end() const noexcept
2232 {
2233 return Iterator {*this, this->size()};
2234 }
2235
2236 ConstVariantFieldClassOption operator[](const std::uint64_t index) const noexcept
2237 {
2238 return ConstVariantFieldClassOption {
2239 internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByIndex(
2240 this->libObjPtr(), index)};
2241 }
2242
2243 Option operator[](const std::uint64_t index) noexcept
2244 {
2245 return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex(
2246 this->libObjPtr(), index)};
2247 }
2248
2249 nonstd::optional<ConstVariantFieldClassOption>
2250 operator[](const char * const name) const noexcept
2251 {
2252 const auto libObjPtr =
2253 internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByName(
2254 this->libObjPtr(), name);
2255
2256 if (libObjPtr) {
2257 return ConstVariantFieldClassOption {libObjPtr};
2258 }
2259
2260 return nonstd::nullopt;
2261 }
2262
2263 nonstd::optional<ConstVariantFieldClassOption>
2264 operator[](const std::string& name) const noexcept
2265 {
2266 return (*this)[name.data()];
2267 }
2268
2269 nonstd::optional<Option> operator[](const char * const name) noexcept
2270 {
2271 const auto libObjPtr =
2272 internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name);
2273
2274 if (libObjPtr) {
2275 return Option {libObjPtr};
2276 }
2277
2278 return nonstd::nullopt;
2279 }
2280
2281 nonstd::optional<Option> operator[](const std::string& name) noexcept
2282 {
2283 return (*this)[name.data()];
2284 }
2285
2286 Shared shared() const noexcept
2287 {
2288 return Shared::createWithRef(*this);
2289 }
2290 };
2291
2292 using VariantFieldClass = CommonVariantFieldClass<bt_field_class>;
2293 using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>;
2294
2295 namespace internal {
2296
2297 struct VariantFieldClassTypeDescr
2298 {
2299 using Const = ConstVariantFieldClass;
2300 using NonConst = VariantFieldClass;
2301 };
2302
2303 template <>
2304 struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr
2305 {
2306 };
2307
2308 template <>
2309 struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr
2310 {
2311 };
2312
2313 } /* namespace internal */
2314
2315 template <typename LibObjT>
2316 class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2317 {
2318 private:
2319 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2320 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2321
2322 public:
2323 using Shared =
2324 internal::SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
2325
2326 explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2327 _ThisCommonVariantFieldClass {libObjPtr}
2328 {
2329 BT_ASSERT_DBG(this->isVariantWithoutSelector());
2330 }
2331
2332 template <typename OtherLibObjT>
2333 CommonVariantWithoutSelectorFieldClass(
2334 const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept :
2335 _ThisCommonVariantFieldClass {fc}
2336 {
2337 }
2338
2339 template <typename OtherLibObjT>
2340 CommonVariantWithoutSelectorFieldClass&
2341 operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
2342 {
2343 _ThisCommonVariantFieldClass::operator=(fc);
2344 return *this;
2345 }
2346
2347 void appendOption(const char * const name, const FieldClass fc)
2348 {
2349 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2350
2351 const auto status = bt_field_class_variant_without_selector_append_option(
2352 this->libObjPtr(), name, fc.libObjPtr());
2353
2354 if (status ==
2355 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2356 throw MemoryError {};
2357 }
2358 }
2359
2360 void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc)
2361 {
2362 this->appendOption(name ? name->data() : nullptr, fc);
2363 }
2364
2365 Shared shared() const noexcept
2366 {
2367 return Shared::createWithRef(*this);
2368 }
2369 };
2370
2371 using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>;
2372 using ConstVariantWithoutSelectorFieldClass =
2373 CommonVariantWithoutSelectorFieldClass<const bt_field_class>;
2374
2375 namespace internal {
2376
2377 struct VariantWithoutSelectorFieldClassTypeDescr
2378 {
2379 using Const = ConstVariantWithoutSelectorFieldClass;
2380 using NonConst = VariantWithoutSelectorFieldClass;
2381 };
2382
2383 template <>
2384 struct TypeDescr<VariantWithoutSelectorFieldClass> :
2385 public VariantWithoutSelectorFieldClassTypeDescr
2386 {
2387 };
2388
2389 template <>
2390 struct TypeDescr<ConstVariantWithoutSelectorFieldClass> :
2391 public VariantWithoutSelectorFieldClassTypeDescr
2392 {
2393 };
2394
2395 template <typename OptionT>
2396 struct CommonVariantWithIntegerSelectorFieldClassSpec;
2397
2398 /* Functions specific to variant field classes with unsigned integer selector */
2399 template <>
2400 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2401 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2402 final
2403 {
2404 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2405 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2406 {
2407 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
2408 libObjPtr, index);
2409 }
2410
2411 static const bt_field_class_variant_with_selector_field_integer_unsigned_option *
2412 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2413 {
2414 return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
2415 libObjPtr, name);
2416 }
2417
2418 static bt_field_class_variant_with_selector_field_integer_append_option_status
2419 appendOption(bt_field_class * const libObjPtr, const char * const name,
2420 bt_field_class * const libOptFcPtr,
2421 const bt_integer_range_set_unsigned * const libRangesPtr)
2422 {
2423 return bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
2424 libObjPtr, name, libOptFcPtr, libRangesPtr);
2425 }
2426 };
2427
2428 /* Functions specific to variant field classes with signed integer selector */
2429 template <>
2430 struct CommonVariantWithIntegerSelectorFieldClassSpec<
2431 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2432 final
2433 {
2434 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2435 optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept
2436 {
2437 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
2438 libObjPtr, index);
2439 }
2440
2441 static const bt_field_class_variant_with_selector_field_integer_signed_option *
2442 optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept
2443 {
2444 return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
2445 libObjPtr, name);
2446 }
2447
2448 static bt_field_class_variant_with_selector_field_integer_append_option_status
2449 appendOption(bt_field_class * const libObjPtr, const char * const name,
2450 bt_field_class * const libOptFcPtr,
2451 const bt_integer_range_set_signed * const libRangesPtr)
2452 {
2453 return bt_field_class_variant_with_selector_field_integer_signed_append_option(
2454 libObjPtr, name, libOptFcPtr, libRangesPtr);
2455 }
2456 };
2457
2458 } /* namespace internal */
2459
2460 template <typename LibObjT>
2461 class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT>
2462 {
2463 private:
2464 using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass;
2465
2466 protected:
2467 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2468 using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
2469
2470 public:
2471 using Shared = internal::SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
2472
2473 explicit CommonVariantWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2474 _ThisCommonVariantFieldClass {libObjPtr}
2475 {
2476 BT_ASSERT_DBG(this->isVariantWithSelector());
2477 }
2478
2479 template <typename OtherLibObjT>
2480 CommonVariantWithSelectorFieldClass(
2481 const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
2482 _ThisCommonVariantFieldClass {fc}
2483 {
2484 }
2485
2486 template <typename OtherLibObjT>
2487 CommonVariantWithSelectorFieldClass&
2488 operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
2489 {
2490 _ThisCommonVariantFieldClass::operator=(fc);
2491 return *this;
2492 }
2493
2494 ConstFieldPath selectorFieldPath() const noexcept
2495 {
2496 return ConstFieldPath {
2497 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
2498 this->libObjPtr())};
2499 }
2500
2501 Shared shared() const noexcept
2502 {
2503 return Shared::createWithRef(*this);
2504 }
2505 };
2506
2507 using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>;
2508 using ConstVariantWithSelectorFieldClass =
2509 CommonVariantWithSelectorFieldClass<const bt_field_class>;
2510
2511 template <typename LibObjT, typename OptionT>
2512 class CommonVariantWithIntegerSelectorFieldClass :
2513 public CommonVariantWithSelectorFieldClass<LibObjT>
2514 {
2515 private:
2516 using typename CommonVariantWithSelectorFieldClass<
2517 LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
2518 using typename CommonFieldClass<LibObjT>::_LibObjPtr;
2519 using _ThisCommonVariantWithIntegerSelectorFieldClass =
2520 CommonVariantWithIntegerSelectorFieldClass<LibObjT, OptionT>;
2521
2522 using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
2523
2524 public:
2525 using Shared =
2526 internal::SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
2527
2528 using Option = OptionT;
2529 using Iterator =
2530 CommonIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>, Option>;
2531
2532 explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
2533 _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
2534 {
2535 BT_ASSERT_DBG(this->isVariant());
2536 }
2537
2538 template <typename OtherLibObjT>
2539 CommonVariantWithIntegerSelectorFieldClass(
2540 const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept :
2541 _ThisCommonVariantWithSelectorFieldClass {fc}
2542 {
2543 }
2544
2545 template <typename OtherLibObjT>
2546 CommonVariantWithIntegerSelectorFieldClass&
2547 operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
2548 {
2549 _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
2550 return *this;
2551 }
2552
2553 Option operator[](const std::uint64_t index) const noexcept
2554 {
2555 return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
2556 }
2557
2558 nonstd::optional<Option> operator[](const char * const name) const noexcept
2559 {
2560 const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name);
2561
2562 if (libObjPtr) {
2563 return Option {libObjPtr};
2564 }
2565
2566 return nonstd::nullopt;
2567 }
2568
2569 nonstd::optional<Option> operator[](const std::string& name) const noexcept
2570 {
2571 return (*this)[name.data()];
2572 }
2573
2574 void appendOption(const char * const name, const FieldClass fc,
2575 const typename Option::RangeSet ranges)
2576 {
2577 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2578
2579 const auto status =
2580 _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr());
2581
2582 if (status ==
2583 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
2584 throw MemoryError {};
2585 }
2586 }
2587
2588 void appendOption(const nonstd::optional<std::string>& name, const FieldClass fc,
2589 const typename Option::RangeSet ranges)
2590 {
2591 this->appendOption(name ? name->data() : nullptr, fc, ranges);
2592 }
2593
2594 Iterator begin() const noexcept
2595 {
2596 return Iterator {*this, 0};
2597 }
2598
2599 Iterator end() const noexcept
2600 {
2601 return Iterator {*this, this->size()};
2602 }
2603
2604 Shared shared() const noexcept
2605 {
2606 return Shared::createWithRef(*this);
2607 }
2608 };
2609
2610 using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2611 bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2612
2613 using ConstVariantWithUnsignedIntegerSelectorFieldClass =
2614 CommonVariantWithIntegerSelectorFieldClass<
2615 const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>;
2616
2617 using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2618 bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2619
2620 using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass<
2621 const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>;
2622
2623 namespace internal {
2624
2625 struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2626 {
2627 using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass;
2628 using NonConst = VariantWithUnsignedIntegerSelectorFieldClass;
2629 };
2630
2631 template <>
2632 struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> :
2633 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2634 {
2635 };
2636
2637 template <>
2638 struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> :
2639 public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr
2640 {
2641 };
2642
2643 struct VariantWithSignedIntegerSelectorFieldClassTypeDescr
2644 {
2645 using Const = ConstVariantWithSignedIntegerSelectorFieldClass;
2646 using NonConst = VariantWithSignedIntegerSelectorFieldClass;
2647 };
2648
2649 template <>
2650 struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> :
2651 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2652 {
2653 };
2654
2655 template <>
2656 struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> :
2657 public VariantWithSignedIntegerSelectorFieldClassTypeDescr
2658 {
2659 };
2660
2661 } /* namespace internal */
2662
2663 template <typename LibObjT>
2664 CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept
2665 {
2666 BT_ASSERT_DBG(this->isBitArray());
2667 return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()};
2668 }
2669
2670 template <typename LibObjT>
2671 CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept
2672 {
2673 BT_ASSERT_DBG(this->isInteger());
2674 return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()};
2675 }
2676
2677 template <typename LibObjT>
2678 CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept
2679 {
2680 BT_ASSERT_DBG(this->isEnumeration());
2681 return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()};
2682 }
2683
2684 template <typename LibObjT>
2685 CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping>
2686 CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept
2687 {
2688 BT_ASSERT_DBG(this->isUnsignedEnumeration());
2689 return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> {
2690 this->libObjPtr()};
2691 }
2692
2693 template <typename LibObjT>
2694 CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping>
2695 CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept
2696 {
2697 BT_ASSERT_DBG(this->isSignedEnumeration());
2698 return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> {
2699 this->libObjPtr()};
2700 }
2701
2702 template <typename LibObjT>
2703 CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept
2704 {
2705 BT_ASSERT_DBG(this->isStructure());
2706 return CommonStructureFieldClass<LibObjT> {this->libObjPtr()};
2707 }
2708
2709 template <typename LibObjT>
2710 CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept
2711 {
2712 BT_ASSERT_DBG(this->isArray());
2713 return CommonArrayFieldClass<LibObjT> {this->libObjPtr()};
2714 }
2715
2716 template <typename LibObjT>
2717 CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept
2718 {
2719 BT_ASSERT_DBG(this->isStaticArray());
2720 return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()};
2721 }
2722
2723 template <typename LibObjT>
2724 CommonDynamicArrayWithLengthFieldClass<LibObjT>
2725 CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept
2726 {
2727 BT_ASSERT_DBG(this->isDynamicArrayWithLength());
2728 return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()};
2729 }
2730
2731 template <typename LibObjT>
2732 CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept
2733 {
2734 BT_ASSERT_DBG(this->isOption());
2735 return CommonOptionFieldClass<LibObjT> {this->libObjPtr()};
2736 }
2737
2738 template <typename LibObjT>
2739 CommonOptionWithSelectorFieldClass<LibObjT>
2740 CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept
2741 {
2742 BT_ASSERT_DBG(this->isOptionWithSelector());
2743 return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2744 }
2745
2746 template <typename LibObjT>
2747 CommonOptionWithBoolSelectorFieldClass<LibObjT>
2748 CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept
2749 {
2750 BT_ASSERT_DBG(this->isOptionWithBoolSelector());
2751 return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()};
2752 }
2753
2754 template <typename LibObjT>
2755 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet>
2756 CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept
2757 {
2758 BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector());
2759 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> {
2760 this->libObjPtr()};
2761 }
2762
2763 template <typename LibObjT>
2764 CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet>
2765 CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept
2766 {
2767 BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector());
2768 return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> {
2769 this->libObjPtr()};
2770 }
2771
2772 template <typename LibObjT>
2773 CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept
2774 {
2775 BT_ASSERT_DBG(this->isVariant());
2776 return CommonVariantFieldClass<LibObjT> {this->libObjPtr()};
2777 }
2778
2779 template <typename LibObjT>
2780 CommonVariantWithoutSelectorFieldClass<LibObjT>
2781 CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept
2782 {
2783 BT_ASSERT_DBG(this->isVariantWithoutSelector());
2784 return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()};
2785 }
2786
2787 template <typename LibObjT>
2788 CommonVariantWithSelectorFieldClass<LibObjT>
2789 CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept
2790 {
2791 BT_ASSERT_DBG(this->isVariantWithSelector());
2792 return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
2793 }
2794
2795 template <typename LibObjT>
2796 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2797 ConstVariantWithUnsignedIntegerSelectorFieldClassOption>
2798 CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept
2799 {
2800 BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector());
2801 return CommonVariantWithIntegerSelectorFieldClass<
2802 LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2803 }
2804
2805 template <typename LibObjT>
2806 CommonVariantWithIntegerSelectorFieldClass<LibObjT,
2807 ConstVariantWithSignedIntegerSelectorFieldClassOption>
2808 CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept
2809 {
2810 BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector());
2811 return CommonVariantWithIntegerSelectorFieldClass<
2812 LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()};
2813 }
2814
2815 } /* namespace bt2 */
2816
2817 #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */
This page took 0.083226 seconds and 3 git commands to generate.