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