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