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