Fix: field.hpp: various typos
[babeltrace.git] / src / cpp-common / bt2 / field.hpp
1 /*
2 * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_FIELD_HPP
9
10 #include <type_traits>
11 #include <cstdint>
12 #include <babeltrace2/babeltrace.h>
13
14 #include "common/assert.h"
15 #include "internal/borrowed-obj.hpp"
16 #include "internal/utils.hpp"
17 #include "cpp-common/optional.hpp"
18 #include "cpp-common/string_view.hpp"
19 #include "field-class.hpp"
20
21 namespace bt2 {
22
23 template <typename LibObjT>
24 class CommonBoolField;
25
26 template <typename LibObjT>
27 class CommonBitArrayField;
28
29 template <typename LibObjT>
30 class CommonUnsignedIntegerField;
31
32 template <typename LibObjT>
33 class CommonSignedIntegerField;
34
35 template <typename LibObjT>
36 class CommonUnsignedEnumerationField;
37
38 template <typename LibObjT>
39 class CommonSignedEnumerationField;
40
41 template <typename LibObjT>
42 class CommonSinglePrecisionRealField;
43
44 template <typename LibObjT>
45 class CommonDoublePrecisionRealField;
46
47 template <typename LibObjT>
48 class CommonStringField;
49
50 template <typename LibObjT>
51 class CommonStructureField;
52
53 template <typename LibObjT>
54 class CommonArrayField;
55
56 template <typename LibObjT>
57 class CommonDynamicArrayField;
58
59 template <typename LibObjT>
60 class CommonOptionField;
61
62 template <typename LibObjT>
63 class CommonVariantField;
64
65 namespace internal {
66
67 template <typename LibObjT>
68 struct CommonFieldSpec;
69
70 /* Functions specific to mutable fields */
71 template <>
72 struct CommonFieldSpec<bt_field> final
73 {
74 static bt_field_class *cls(bt_field * const libObjPtr) noexcept
75 {
76 return bt_field_borrow_class(libObjPtr);
77 }
78 };
79
80 /* Functions specific to constant fields */
81 template <>
82 struct CommonFieldSpec<const bt_field> final
83 {
84 static const bt_field_class *cls(const bt_field * const libObjPtr) noexcept
85 {
86 return bt_field_borrow_class_const(libObjPtr);
87 }
88 };
89
90 } /* namespace internal */
91
92 template <typename LibObjT>
93 class CommonField : public internal::BorrowedObj<LibObjT>
94 {
95 private:
96 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
97
98 protected:
99 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
100 using _ThisCommonField = CommonField<LibObjT>;
101
102 public:
103 using Class =
104 typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
105
106 explicit CommonField(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
107 {
108 }
109
110 template <typename OtherLibObjT>
111 CommonField(const CommonField<OtherLibObjT> val) noexcept : _ThisBorrowedObj {val}
112 {
113 }
114
115 template <typename OtherLibObjT>
116 _ThisCommonField& operator=(const CommonField<OtherLibObjT> val) noexcept
117 {
118 _ThisBorrowedObj::operator=(val);
119 return *this;
120 }
121
122 FieldClassType classType() const noexcept
123 {
124 return static_cast<FieldClassType>(bt_field_get_class_type(this->libObjPtr()));
125 }
126
127 ConstFieldClass cls() const noexcept
128 {
129 return ConstFieldClass {internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
130 }
131
132 Class cls() noexcept
133 {
134 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
135 }
136
137 bool isBool() const noexcept
138 {
139 return this->cls().isBool();
140 }
141
142 bool isBitArray() const noexcept
143 {
144 return this->cls().isBitArray();
145 }
146
147 bool isUnsignedInteger() const noexcept
148 {
149 return this->cls().isUnsignedInteger();
150 }
151
152 bool isSignedInteger() const noexcept
153 {
154 return this->cls().isSignedInteger();
155 }
156
157 bool isUnsignedEnumeration() const noexcept
158 {
159 return this->cls().isUnsignedEnumeration();
160 }
161
162 bool isSignedEnumeration() const noexcept
163 {
164 return this->cls().isSignedEnumeration();
165 }
166
167 bool isSinglePrecisionReal() const noexcept
168 {
169 return this->cls().isSinglePrecisionReal();
170 }
171
172 bool isDoublePrecisionReal() const noexcept
173 {
174 return this->cls().isDoublePrecisionReal();
175 }
176
177 bool isString() const noexcept
178 {
179 return this->cls().isString();
180 }
181
182 bool isStructure() const noexcept
183 {
184 return this->cls().isStructure();
185 }
186
187 bool isArray() const noexcept
188 {
189 return this->cls().isArray();
190 }
191
192 bool isDynamicArray() const noexcept
193 {
194 return this->cls().isDynamicArray();
195 }
196
197 bool isOption() const noexcept
198 {
199 return this->cls().isOption();
200 }
201
202 bool isVariant() const noexcept
203 {
204 return this->cls().isVariant();
205 }
206
207 template <typename FieldT>
208 FieldT as() const noexcept
209 {
210 return FieldT {this->libObjPtr()};
211 }
212
213 CommonBoolField<LibObjT> asBool() const noexcept;
214 CommonBitArrayField<LibObjT> asBitArray() const noexcept;
215 CommonUnsignedIntegerField<LibObjT> asUnsignedInteger() const noexcept;
216 CommonSignedIntegerField<LibObjT> asSignedInteger() const noexcept;
217 CommonUnsignedEnumerationField<LibObjT> asUnsignedEnumeration() const noexcept;
218 CommonSignedEnumerationField<LibObjT> asSignedEnumeration() const noexcept;
219 CommonSinglePrecisionRealField<LibObjT> asSinglePrecisionReal() const noexcept;
220 CommonDoublePrecisionRealField<LibObjT> asDoublePrecisionReal() const noexcept;
221 CommonStringField<LibObjT> asString() const noexcept;
222 CommonStructureField<LibObjT> asStructure() const noexcept;
223 CommonArrayField<LibObjT> asArray() const noexcept;
224 CommonDynamicArrayField<LibObjT> asDynamicArray() const noexcept;
225 CommonOptionField<LibObjT> asOption() const noexcept;
226 CommonVariantField<LibObjT> asVariant() const noexcept;
227 };
228
229 using Field = CommonField<bt_field>;
230 using ConstField = CommonField<const bt_field>;
231
232 namespace internal {
233
234 struct FieldTypeDescr
235 {
236 using Const = ConstField;
237 using NonConst = Field;
238 };
239
240 template <>
241 struct TypeDescr<Field> : public FieldTypeDescr
242 {
243 };
244
245 template <>
246 struct TypeDescr<ConstField> : public FieldTypeDescr
247 {
248 };
249
250 } /* namespace internal */
251
252 template <typename LibObjT>
253 class CommonBoolField final : public CommonField<LibObjT>
254 {
255 private:
256 using typename CommonField<LibObjT>::_LibObjPtr;
257 using typename CommonField<LibObjT>::_ThisCommonField;
258
259 public:
260 using Value = bool;
261
262 explicit CommonBoolField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
263 {
264 BT_ASSERT_DBG(this->isBool());
265 }
266
267 template <typename OtherLibObjT>
268 CommonBoolField(const CommonBoolField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
269 {
270 }
271
272 template <typename OtherLibObjT>
273 CommonBoolField<LibObjT>& operator=(const CommonBoolField<OtherLibObjT> val) noexcept
274 {
275 _ThisCommonField::operator=(val);
276 return *this;
277 }
278
279 CommonBoolField<LibObjT>& operator=(const Value val) noexcept
280 {
281 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
282
283 bt_field_bool_set_value(this->libObjPtr(), static_cast<bt_bool>(val));
284 return *this;
285 }
286
287 Value value() const noexcept
288 {
289 return static_cast<Value>(bt_field_bool_get_value(this->libObjPtr()));
290 }
291
292 operator Value() const noexcept
293 {
294 return this->value();
295 }
296 };
297
298 using BoolField = CommonBoolField<bt_field>;
299 using ConstBoolField = CommonBoolField<const bt_field>;
300
301 namespace internal {
302
303 struct BoolFieldTypeDescr
304 {
305 using Const = ConstBoolField;
306 using NonConst = BoolField;
307 };
308
309 template <>
310 struct TypeDescr<BoolField> : public BoolFieldTypeDescr
311 {
312 };
313
314 template <>
315 struct TypeDescr<ConstBoolField> : public BoolFieldTypeDescr
316 {
317 };
318
319 } /* namespace internal */
320
321 template <typename LibObjT>
322 class CommonBitArrayField final : public CommonField<LibObjT>
323 {
324 private:
325 using typename CommonField<LibObjT>::_LibObjPtr;
326 using typename CommonField<LibObjT>::_ThisCommonField;
327
328 public:
329 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstBitArrayFieldClass,
330 BitArrayFieldClass>::type;
331
332 explicit CommonBitArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
333 {
334 BT_ASSERT_DBG(this->isBitArray());
335 }
336
337 template <typename OtherLibObjT>
338 CommonBitArrayField(const CommonBitArrayField<OtherLibObjT> val) noexcept :
339 _ThisCommonField {val}
340 {
341 }
342
343 template <typename OtherLibObjT>
344 CommonBitArrayField<LibObjT>& operator=(const CommonBitArrayField<OtherLibObjT> val) noexcept
345 {
346 _ThisCommonField::operator=(val);
347 return *this;
348 }
349
350 ConstBitArrayFieldClass cls() const noexcept
351 {
352 return ConstBitArrayFieldClass {
353 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
354 }
355
356 Class cls() noexcept
357 {
358 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
359 }
360
361 CommonBitArrayField<LibObjT>& operator=(const std::uint64_t bits) noexcept
362 {
363 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
364
365 bt_field_bit_array_set_value_as_integer(this->libObjPtr(), bits);
366 return *this;
367 }
368
369 std::uint64_t valueAsInteger() const noexcept
370 {
371 return bt_field_bit_array_get_value_as_integer(this->libObjPtr());
372 }
373
374 bool bitValue(const std::uint64_t index) const noexcept
375 {
376 BT_ASSERT_DBG(index < this->cls().length());
377 return static_cast<bool>(this->valueAsInteger() & (1ULL << index));
378 }
379 };
380
381 using BitArrayField = CommonBitArrayField<bt_field>;
382 using ConstBitArrayField = CommonBitArrayField<const bt_field>;
383
384 namespace internal {
385
386 struct BitArrayFieldTypeDescr
387 {
388 using Const = ConstBitArrayField;
389 using NonConst = BitArrayField;
390 };
391
392 template <>
393 struct TypeDescr<BitArrayField> : public BitArrayFieldTypeDescr
394 {
395 };
396
397 template <>
398 struct TypeDescr<ConstBitArrayField> : public BitArrayFieldTypeDescr
399 {
400 };
401
402 } /* namespace internal */
403
404 template <typename LibObjT>
405 class CommonUnsignedIntegerField : public CommonField<LibObjT>
406 {
407 private:
408 using typename CommonField<LibObjT>::_ThisCommonField;
409
410 protected:
411 using typename CommonField<LibObjT>::_LibObjPtr;
412 using _ThisCommonUnsignedIntegerField = CommonUnsignedIntegerField<LibObjT>;
413
414 public:
415 using Value = std::uint64_t;
416
417 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstIntegerFieldClass,
418 IntegerFieldClass>::type;
419
420 explicit CommonUnsignedIntegerField(const _LibObjPtr libObjPtr) noexcept :
421 _ThisCommonField {libObjPtr}
422 {
423 BT_ASSERT_DBG(this->isUnsignedInteger());
424 }
425
426 template <typename OtherLibObjT>
427 CommonUnsignedIntegerField(const CommonUnsignedIntegerField<OtherLibObjT> val) noexcept :
428 _ThisCommonField {val}
429 {
430 }
431
432 template <typename OtherLibObjT>
433 _ThisCommonUnsignedIntegerField&
434 operator=(const CommonUnsignedIntegerField<OtherLibObjT> val) noexcept
435 {
436 _ThisCommonField::operator=(val);
437 return *this;
438 }
439
440 ConstIntegerFieldClass cls() const noexcept
441 {
442 return ConstIntegerFieldClass {
443 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
444 }
445
446 Class cls() noexcept
447 {
448 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
449 }
450
451 CommonUnsignedIntegerField<LibObjT>& operator=(const Value val) noexcept
452 {
453 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
454
455 bt_field_integer_unsigned_set_value(this->libObjPtr(), val);
456 return *this;
457 }
458
459 Value value() const noexcept
460 {
461 return bt_field_integer_unsigned_get_value(this->libObjPtr());
462 }
463
464 operator Value() const noexcept
465 {
466 return this->value();
467 }
468 };
469
470 using UnsignedIntegerField = CommonUnsignedIntegerField<bt_field>;
471 using ConstUnsignedIntegerField = CommonUnsignedIntegerField<const bt_field>;
472
473 namespace internal {
474
475 struct UnsignedIntegerFieldTypeDescr
476 {
477 using Const = ConstUnsignedIntegerField;
478 using NonConst = UnsignedIntegerField;
479 };
480
481 template <>
482 struct TypeDescr<UnsignedIntegerField> : public UnsignedIntegerFieldTypeDescr
483 {
484 };
485
486 template <>
487 struct TypeDescr<ConstUnsignedIntegerField> : public UnsignedIntegerFieldTypeDescr
488 {
489 };
490
491 } /* namespace internal */
492
493 template <typename LibObjT>
494 class CommonSignedIntegerField : public CommonField<LibObjT>
495 {
496 private:
497 using typename CommonField<LibObjT>::_ThisCommonField;
498
499 protected:
500 using typename CommonField<LibObjT>::_LibObjPtr;
501 using _ThisCommonSignedIntegerField = CommonSignedIntegerField<LibObjT>;
502
503 public:
504 using Value = std::int64_t;
505
506 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstIntegerFieldClass,
507 IntegerFieldClass>::type;
508
509 explicit CommonSignedIntegerField(const _LibObjPtr libObjPtr) noexcept :
510 _ThisCommonField {libObjPtr}
511 {
512 BT_ASSERT_DBG(this->isSignedInteger());
513 }
514
515 template <typename OtherLibObjT>
516 CommonSignedIntegerField(const CommonSignedIntegerField<OtherLibObjT> val) noexcept :
517 _ThisCommonField {val}
518 {
519 }
520
521 template <typename OtherLibObjT>
522 _ThisCommonSignedIntegerField&
523 operator=(const CommonSignedIntegerField<OtherLibObjT> val) noexcept
524 {
525 _ThisCommonField::operator=(val);
526 return *this;
527 }
528
529 ConstIntegerFieldClass cls() const noexcept
530 {
531 return ConstIntegerFieldClass {
532 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
533 }
534
535 Class cls() noexcept
536 {
537 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
538 }
539
540 CommonSignedIntegerField<LibObjT>& operator=(const Value val) noexcept
541 {
542 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
543
544 bt_field_integer_signed_set_value(this->libObjPtr(), val);
545 return *this;
546 }
547
548 Value value() const noexcept
549 {
550 return bt_field_integer_signed_get_value(this->libObjPtr());
551 }
552
553 operator Value() const noexcept
554 {
555 return this->value();
556 }
557 };
558
559 using SignedIntegerField = CommonSignedIntegerField<bt_field>;
560 using ConstSignedIntegerField = CommonSignedIntegerField<const bt_field>;
561
562 namespace internal {
563
564 struct SignedIntegerFieldTypeDescr
565 {
566 using Const = ConstSignedIntegerField;
567 using NonConst = SignedIntegerField;
568 };
569
570 template <>
571 struct TypeDescr<SignedIntegerField> : public SignedIntegerFieldTypeDescr
572 {
573 };
574
575 template <>
576 struct TypeDescr<ConstSignedIntegerField> : public SignedIntegerFieldTypeDescr
577 {
578 };
579
580 } /* namespace internal */
581
582 class EnumerationFieldClassMappingLabels
583 {
584 public:
585 explicit EnumerationFieldClassMappingLabels(
586 const bt_field_class_enumeration_mapping_label_array labels, const std::uint64_t size) :
587 _mLabels {labels},
588 _mSize {size}
589 {
590 }
591
592 EnumerationFieldClassMappingLabels(const EnumerationFieldClassMappingLabels&) noexcept =
593 default;
594
595 EnumerationFieldClassMappingLabels&
596 operator=(const EnumerationFieldClassMappingLabels&) noexcept = default;
597
598 std::uint64_t size() const noexcept
599 {
600 return _mSize;
601 }
602
603 bpstd::string_view operator[](const std::uint64_t index) const noexcept
604 {
605 return _mLabels[index];
606 }
607
608 private:
609 bt_field_class_enumeration_mapping_label_array _mLabels;
610 std::uint64_t _mSize;
611 };
612
613 template <typename LibObjT>
614 class CommonUnsignedEnumerationField final : public CommonUnsignedIntegerField<LibObjT>
615 {
616 private:
617 using typename CommonUnsignedIntegerField<LibObjT>::_ThisCommonUnsignedIntegerField;
618 using typename CommonField<LibObjT>::_LibObjPtr;
619
620 public:
621 using Class =
622 typename std::conditional<std::is_const<LibObjT>::value, ConstUnsignedEnumerationFieldClass,
623 UnsignedEnumerationFieldClass>::type;
624
625 explicit CommonUnsignedEnumerationField(const _LibObjPtr libObjPtr) noexcept :
626 _ThisCommonUnsignedIntegerField {libObjPtr}
627 {
628 BT_ASSERT_DBG(this->isUnsignedEnumeration());
629 }
630
631 template <typename OtherLibObjT>
632 CommonUnsignedEnumerationField(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept
633 :
634 _ThisCommonUnsignedIntegerField {val}
635 {
636 }
637
638 template <typename OtherLibObjT>
639 CommonUnsignedEnumerationField<LibObjT>&
640 operator=(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept
641 {
642 _ThisCommonUnsignedIntegerField::operator=(val);
643 return *this;
644 }
645
646 ConstUnsignedEnumerationFieldClass cls() const noexcept
647 {
648 return ConstUnsignedEnumerationFieldClass {
649 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
650 }
651
652 Class cls() noexcept
653 {
654 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
655 }
656
657 EnumerationFieldClassMappingLabels labels() const
658 {
659 bt_field_class_enumeration_mapping_label_array labelArray;
660 std::uint64_t count;
661 const auto status = bt_field_enumeration_unsigned_get_mapping_labels(this->libObjPtr(),
662 &labelArray, &count);
663
664 if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
665 throw MemoryError {};
666 }
667
668 return EnumerationFieldClassMappingLabels {labelArray, count};
669 }
670 };
671
672 using UnsignedEnumerationField = CommonUnsignedEnumerationField<bt_field>;
673 using ConstUnsignedEnumerationField = CommonUnsignedEnumerationField<const bt_field>;
674
675 namespace internal {
676
677 struct UnsignedEnumerationFieldTypeDescr
678 {
679 using Const = ConstUnsignedEnumerationField;
680 using NonConst = UnsignedEnumerationField;
681 };
682
683 template <>
684 struct TypeDescr<UnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr
685 {
686 };
687
688 template <>
689 struct TypeDescr<ConstUnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr
690 {
691 };
692
693 } /* namespace internal */
694
695 template <typename LibObjT>
696 class CommonSignedEnumerationField final : public CommonSignedIntegerField<LibObjT>
697 {
698 private:
699 using typename CommonSignedIntegerField<LibObjT>::_ThisCommonSignedIntegerField;
700 using typename CommonField<LibObjT>::_LibObjPtr;
701
702 public:
703 using Class =
704 typename std::conditional<std::is_const<LibObjT>::value, ConstSignedEnumerationFieldClass,
705 SignedEnumerationFieldClass>::type;
706
707 explicit CommonSignedEnumerationField(const _LibObjPtr libObjPtr) noexcept :
708 _ThisCommonSignedIntegerField {libObjPtr}
709 {
710 BT_ASSERT_DBG(this->isSignedEnumeration());
711 }
712
713 template <typename OtherLibObjT>
714 CommonSignedEnumerationField(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept :
715 _ThisCommonSignedIntegerField {val}
716 {
717 }
718
719 template <typename OtherLibObjT>
720 CommonSignedEnumerationField<LibObjT>&
721 operator=(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept
722 {
723 _ThisCommonSignedIntegerField::operator=(val);
724 return *this;
725 }
726
727 ConstSignedEnumerationFieldClass cls() const noexcept
728 {
729 return ConstSignedEnumerationFieldClass {
730 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
731 }
732
733 Class cls() noexcept
734 {
735 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
736 }
737
738 EnumerationFieldClassMappingLabels labels() const
739 {
740 bt_field_class_enumeration_mapping_label_array labelArray;
741 std::uint64_t count;
742 const auto status =
743 bt_field_enumeration_signed_get_mapping_labels(this->libObjPtr(), &labelArray, &count);
744
745 if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
746 throw MemoryError {};
747 }
748
749 return EnumerationFieldClassMappingLabels {labelArray, count};
750 }
751 };
752
753 using SignedEnumerationField = CommonSignedEnumerationField<bt_field>;
754 using ConstSignedEnumerationField = CommonSignedEnumerationField<const bt_field>;
755
756 namespace internal {
757
758 struct SignedEnumerationFieldTypeDescr
759 {
760 using Const = ConstSignedEnumerationField;
761 using NonConst = SignedEnumerationField;
762 };
763
764 template <>
765 struct TypeDescr<SignedEnumerationField> : public SignedEnumerationFieldTypeDescr
766 {
767 };
768
769 template <>
770 struct TypeDescr<ConstSignedEnumerationField> : public SignedEnumerationFieldTypeDescr
771 {
772 };
773
774 } /* namespace internal */
775
776 template <typename LibObjT>
777 class CommonSinglePrecisionRealField final : public CommonField<LibObjT>
778 {
779 private:
780 using typename CommonField<LibObjT>::_LibObjPtr;
781 using typename CommonField<LibObjT>::_ThisCommonField;
782
783 public:
784 using Value = float;
785
786 explicit CommonSinglePrecisionRealField(const _LibObjPtr libObjPtr) noexcept :
787 _ThisCommonField {libObjPtr}
788 {
789 BT_ASSERT_DBG(this->isSinglePrecisionReal());
790 }
791
792 template <typename OtherLibObjT>
793 CommonSinglePrecisionRealField(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
794 :
795 _ThisCommonField {val}
796 {
797 }
798
799 template <typename OtherLibObjT>
800 CommonSinglePrecisionRealField<LibObjT>&
801 operator=(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
802 {
803 _ThisCommonField::operator=(val);
804 return *this;
805 }
806
807 CommonSinglePrecisionRealField<LibObjT>& operator=(const Value val) noexcept
808 {
809 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
810
811 bt_field_real_single_precision_set_value(this->libObjPtr(), val);
812 return *this;
813 }
814
815 Value value() const noexcept
816 {
817 return bt_field_real_single_precision_get_value(this->libObjPtr());
818 }
819
820 operator Value() const noexcept
821 {
822 return this->value();
823 }
824 };
825
826 using SinglePrecisionRealField = CommonSinglePrecisionRealField<bt_field>;
827 using ConstSinglePrecisionRealField = CommonSinglePrecisionRealField<const bt_field>;
828
829 namespace internal {
830
831 struct SinglePrecisionRealFieldTypeDescr
832 {
833 using Const = ConstSinglePrecisionRealField;
834 using NonConst = SinglePrecisionRealField;
835 };
836
837 template <>
838 struct TypeDescr<SinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr
839 {
840 };
841
842 template <>
843 struct TypeDescr<ConstSinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr
844 {
845 };
846
847 } /* namespace internal */
848
849 template <typename LibObjT>
850 class CommonDoublePrecisionRealField final : public CommonField<LibObjT>
851 {
852 private:
853 using typename CommonField<LibObjT>::_LibObjPtr;
854 using typename CommonField<LibObjT>::_ThisCommonField;
855
856 public:
857 using Value = double;
858
859 explicit CommonDoublePrecisionRealField(const _LibObjPtr libObjPtr) noexcept :
860 _ThisCommonField {libObjPtr}
861 {
862 BT_ASSERT_DBG(this->isDoublePrecisionReal());
863 }
864
865 template <typename OtherLibObjT>
866 CommonDoublePrecisionRealField(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
867 :
868 _ThisCommonField {val}
869 {
870 }
871
872 template <typename OtherLibObjT>
873 CommonDoublePrecisionRealField<LibObjT>&
874 operator=(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
875 {
876 _ThisCommonField::operator=(val);
877 return *this;
878 }
879
880 CommonDoublePrecisionRealField<LibObjT>& operator=(const Value val) noexcept
881 {
882 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
883
884 bt_field_real_double_precision_set_value(this->libObjPtr(), val);
885 return *this;
886 }
887
888 Value value() const noexcept
889 {
890 return bt_field_real_double_precision_get_value(this->libObjPtr());
891 }
892
893 operator Value() const noexcept
894 {
895 return this->value();
896 }
897 };
898
899 using DoublePrecisionRealField = CommonDoublePrecisionRealField<bt_field>;
900 using ConstDoublePrecisionRealField = CommonDoublePrecisionRealField<const bt_field>;
901
902 namespace internal {
903
904 struct DoublePrecisionRealFieldTypeDescr
905 {
906 using Const = ConstDoublePrecisionRealField;
907 using NonConst = DoublePrecisionRealField;
908 };
909
910 template <>
911 struct TypeDescr<DoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr
912 {
913 };
914
915 template <>
916 struct TypeDescr<ConstDoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr
917 {
918 };
919
920 } /* namespace internal */
921
922 template <typename LibObjT>
923 class CommonStringField final : public CommonField<LibObjT>
924 {
925 private:
926 using typename CommonField<LibObjT>::_LibObjPtr;
927 using typename CommonField<LibObjT>::_ThisCommonField;
928
929 public:
930 explicit CommonStringField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
931 {
932 BT_ASSERT_DBG(this->isString());
933 }
934
935 template <typename OtherLibObjT>
936 CommonStringField(const CommonStringField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
937 {
938 }
939
940 template <typename OtherLibObjT>
941 CommonStringField<LibObjT>& operator=(const CommonStringField<OtherLibObjT> val) noexcept
942 {
943 _ThisCommonField::operator=(val);
944 return *this;
945 }
946
947 CommonStringField<LibObjT>& operator=(const char * const val)
948 {
949 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
950
951 const auto status = bt_field_string_set_value(this->libObjPtr(), val);
952
953 if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
954 throw MemoryError {};
955 }
956
957 return *this;
958 }
959
960 CommonStringField<LibObjT>& operator=(const std::string& val)
961 {
962 return *this = val.data();
963 }
964
965 void clear() noexcept
966 {
967 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
968
969 bt_field_string_clear(this->libObjPtr());
970 }
971
972 bpstd::string_view value() const noexcept
973 {
974 return bt_field_string_get_value(this->libObjPtr());
975 }
976 };
977
978 using StringField = CommonStringField<bt_field>;
979 using ConstStringField = CommonStringField<const bt_field>;
980
981 namespace internal {
982
983 struct StringFieldTypeDescr
984 {
985 using Const = ConstStringField;
986 using NonConst = StringField;
987 };
988
989 template <>
990 struct TypeDescr<StringField> : public StringFieldTypeDescr
991 {
992 };
993
994 template <>
995 struct TypeDescr<ConstStringField> : public StringFieldTypeDescr
996 {
997 };
998
999 template <typename LibObjT>
1000 struct CommonStructureFieldSpec;
1001
1002 /* Functions specific to mutable structure fields */
1003 template <>
1004 struct CommonStructureFieldSpec<bt_field> final
1005 {
1006 static bt_field *memberFieldByIndex(bt_field * const libObjPtr,
1007 const std::uint64_t index) noexcept
1008 {
1009 return bt_field_structure_borrow_member_field_by_index(libObjPtr, index);
1010 }
1011
1012 static bt_field *memberFieldByName(bt_field * const libObjPtr, const char * const name) noexcept
1013 {
1014 return bt_field_structure_borrow_member_field_by_name(libObjPtr, name);
1015 }
1016 };
1017
1018 /* Functions specific to constant structure fields */
1019 template <>
1020 struct CommonStructureFieldSpec<const bt_field> final
1021 {
1022 static const bt_field *memberFieldByIndex(const bt_field * const libObjPtr,
1023 const std::uint64_t index) noexcept
1024 {
1025 return bt_field_structure_borrow_member_field_by_index_const(libObjPtr, index);
1026 }
1027
1028 static const bt_field *memberFieldByName(const bt_field * const libObjPtr,
1029 const char * const name) noexcept
1030 {
1031 return bt_field_structure_borrow_member_field_by_name_const(libObjPtr, name);
1032 }
1033 };
1034
1035 } /* namespace internal */
1036
1037 template <typename LibObjT>
1038 class CommonStructureField final : public CommonField<LibObjT>
1039 {
1040 private:
1041 using typename CommonField<LibObjT>::_LibObjPtr;
1042 using typename CommonField<LibObjT>::_ThisCommonField;
1043 using _Spec = internal::CommonStructureFieldSpec<LibObjT>;
1044
1045 public:
1046 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1047 StructureFieldClass>::type;
1048
1049 explicit CommonStructureField(const _LibObjPtr libObjPtr) noexcept :
1050 _ThisCommonField {libObjPtr}
1051 {
1052 BT_ASSERT_DBG(this->isStructure());
1053 }
1054
1055 template <typename OtherLibObjT>
1056 CommonStructureField(const CommonStructureField<OtherLibObjT> val) noexcept :
1057 _ThisCommonField {val}
1058 {
1059 }
1060
1061 template <typename OtherLibObjT>
1062 CommonStructureField<LibObjT>& operator=(const CommonStructureField<OtherLibObjT> val) noexcept
1063 {
1064 _ThisCommonField::operator=(val);
1065 return *this;
1066 }
1067
1068 ConstStructureFieldClass cls() const noexcept
1069 {
1070 return ConstStructureFieldClass {
1071 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1072 }
1073
1074 Class cls() noexcept
1075 {
1076 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1077 }
1078
1079 std::uint64_t size() const noexcept
1080 {
1081 return this->cls().size();
1082 }
1083
1084 ConstField operator[](const std::uint64_t index) const noexcept
1085 {
1086 return ConstField {internal::CommonStructureFieldSpec<const bt_field>::memberFieldByIndex(
1087 this->libObjPtr(), index)};
1088 }
1089
1090 CommonField<LibObjT> operator[](const std::uint64_t index) noexcept
1091 {
1092 return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
1093 }
1094
1095 nonstd::optional<ConstField> operator[](const char * const name) const noexcept
1096 {
1097 const auto libObjPtr =
1098 internal::CommonStructureFieldSpec<const bt_field>::memberFieldByName(this->libObjPtr(),
1099 name);
1100
1101 if (libObjPtr) {
1102 return ConstField {libObjPtr};
1103 }
1104
1105 return nonstd::nullopt;
1106 }
1107
1108 nonstd::optional<ConstField> operator[](const std::string& name) const noexcept
1109 {
1110 return (*this)[name.data()];
1111 }
1112
1113 nonstd::optional<CommonField<LibObjT>> operator[](const char * const name) noexcept
1114 {
1115 const auto libObjPtr = _Spec::memberFieldByName(this->libObjPtr(), name);
1116
1117 if (libObjPtr) {
1118 return CommonField<LibObjT> {libObjPtr};
1119 }
1120
1121 return nonstd::nullopt;
1122 }
1123
1124 nonstd::optional<CommonField<LibObjT>> operator[](const std::string& name) noexcept
1125 {
1126 return (*this)[name.data()];
1127 }
1128 };
1129
1130 using StructureField = CommonStructureField<bt_field>;
1131 using ConstStructureField = CommonStructureField<const bt_field>;
1132
1133 namespace internal {
1134
1135 struct StructureFieldTypeDescr
1136 {
1137 using Const = ConstStructureField;
1138 using NonConst = StructureField;
1139 };
1140
1141 template <>
1142 struct TypeDescr<StructureField> : public StructureFieldTypeDescr
1143 {
1144 };
1145
1146 template <>
1147 struct TypeDescr<ConstStructureField> : public StructureFieldTypeDescr
1148 {
1149 };
1150
1151 template <typename LibObjT>
1152 struct CommonArrayFieldSpec;
1153
1154 /* Functions specific to mutable array fields */
1155 template <>
1156 struct CommonArrayFieldSpec<bt_field> final
1157 {
1158 static bt_field *elementFieldByIndex(bt_field * const libObjPtr,
1159 const std::uint64_t index) noexcept
1160 {
1161 return bt_field_array_borrow_element_field_by_index(libObjPtr, index);
1162 }
1163 };
1164
1165 /* Functions specific to constant array fields */
1166 template <>
1167 struct CommonArrayFieldSpec<const bt_field> final
1168 {
1169 static const bt_field *elementFieldByIndex(const bt_field * const libObjPtr,
1170 const std::uint64_t index) noexcept
1171 {
1172 return bt_field_array_borrow_element_field_by_index_const(libObjPtr, index);
1173 }
1174 };
1175
1176 } /* namespace internal */
1177
1178 template <typename LibObjT>
1179 class CommonArrayField : public CommonField<LibObjT>
1180 {
1181 private:
1182 using typename CommonField<LibObjT>::_ThisCommonField;
1183 using _Spec = internal::CommonArrayFieldSpec<LibObjT>;
1184
1185 protected:
1186 using typename CommonField<LibObjT>::_LibObjPtr;
1187 using _ThisCommonArrayField = CommonArrayField<LibObjT>;
1188
1189 public:
1190 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstArrayFieldClass,
1191 ArrayFieldClass>::type;
1192
1193 explicit CommonArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
1194 {
1195 BT_ASSERT_DBG(this->isArray());
1196 }
1197
1198 template <typename OtherLibObjT>
1199 CommonArrayField(const CommonArrayField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
1200 {
1201 }
1202
1203 template <typename OtherLibObjT>
1204 _ThisCommonArrayField& operator=(const CommonArrayField<OtherLibObjT> val) noexcept
1205 {
1206 _ThisCommonField::operator=(val);
1207 return *this;
1208 }
1209
1210 ConstArrayFieldClass cls() const noexcept
1211 {
1212 return ConstArrayFieldClass {
1213 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1214 }
1215
1216 Class cls() noexcept
1217 {
1218 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1219 }
1220
1221 std::uint64_t length() const noexcept
1222 {
1223 return bt_field_array_get_length(this->libObjPtr());
1224 }
1225
1226 ConstField operator[](const std::uint64_t index) const noexcept
1227 {
1228 return ConstField {internal::CommonArrayFieldSpec<const bt_field>::elementFieldByIndex(
1229 this->libObjPtr(), index)};
1230 }
1231
1232 CommonField<LibObjT> operator[](const std::uint64_t index) noexcept
1233 {
1234 return CommonField<LibObjT> {_Spec::elementFieldByIndex(this->libObjPtr(), index)};
1235 }
1236 };
1237
1238 using ArrayField = CommonArrayField<bt_field>;
1239 using ConstArrayField = CommonArrayField<const bt_field>;
1240
1241 namespace internal {
1242
1243 struct ArrayFieldTypeDescr
1244 {
1245 using Const = ConstArrayField;
1246 using NonConst = ArrayField;
1247 };
1248
1249 template <>
1250 struct TypeDescr<ArrayField> : public ArrayFieldTypeDescr
1251 {
1252 };
1253
1254 template <>
1255 struct TypeDescr<ConstArrayField> : public ArrayFieldTypeDescr
1256 {
1257 };
1258
1259 } /* namespace internal */
1260
1261 template <typename LibObjT>
1262 class CommonDynamicArrayField : public CommonArrayField<LibObjT>
1263 {
1264 private:
1265 using typename CommonField<LibObjT>::_LibObjPtr;
1266 using typename CommonArrayField<LibObjT>::_ThisCommonArrayField;
1267
1268 public:
1269 explicit CommonDynamicArrayField(const _LibObjPtr libObjPtr) noexcept :
1270 _ThisCommonArrayField {libObjPtr}
1271 {
1272 BT_ASSERT_DBG(this->isDynamicArray());
1273 }
1274
1275 template <typename OtherLibObjT>
1276 CommonDynamicArrayField(const CommonDynamicArrayField<OtherLibObjT> val) noexcept :
1277 _ThisCommonArrayField {val}
1278 {
1279 }
1280
1281 template <typename OtherLibObjT>
1282 CommonDynamicArrayField<LibObjT>&
1283 operator=(const CommonDynamicArrayField<OtherLibObjT> val) noexcept
1284 {
1285 _ThisCommonArrayField::operator=(val);
1286 return *this;
1287 }
1288
1289 std::uint64_t length() const noexcept
1290 {
1291 return _ThisCommonArrayField::length();
1292 }
1293
1294 void length(const std::uint64_t length)
1295 {
1296 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1297
1298 const auto status = bt_field_array_dynamic_set_length(this->libObjPtr(), length);
1299
1300 if (status == BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR) {
1301 throw MemoryError {};
1302 }
1303 }
1304 };
1305
1306 using DynamicArrayField = CommonDynamicArrayField<bt_field>;
1307 using ConstDynamicArrayField = CommonDynamicArrayField<const bt_field>;
1308
1309 namespace internal {
1310
1311 struct DynamicArrayFieldTypeDescr
1312 {
1313 using Const = ConstDynamicArrayField;
1314 using NonConst = DynamicArrayField;
1315 };
1316
1317 template <>
1318 struct TypeDescr<DynamicArrayField> : public DynamicArrayFieldTypeDescr
1319 {
1320 };
1321
1322 template <>
1323 struct TypeDescr<ConstDynamicArrayField> : public DynamicArrayFieldTypeDescr
1324 {
1325 };
1326
1327 template <typename LibObjT>
1328 struct CommonOptionFieldSpec;
1329
1330 /* Functions specific to mutable option fields */
1331 template <>
1332 struct CommonOptionFieldSpec<bt_field> final
1333 {
1334 static bt_field *field(bt_field * const libObjPtr) noexcept
1335 {
1336 return bt_field_option_borrow_field(libObjPtr);
1337 }
1338 };
1339
1340 /* Functions specific to constant option fields */
1341 template <>
1342 struct CommonOptionFieldSpec<const bt_field> final
1343 {
1344 static const bt_field *field(const bt_field * const libObjPtr) noexcept
1345 {
1346 return bt_field_option_borrow_field_const(libObjPtr);
1347 }
1348 };
1349
1350 } /* namespace internal */
1351
1352 template <typename LibObjT>
1353 class CommonOptionField : public CommonField<LibObjT>
1354 {
1355 private:
1356 using typename CommonField<LibObjT>::_LibObjPtr;
1357 using typename CommonField<LibObjT>::_ThisCommonField;
1358 using _Spec = internal::CommonOptionFieldSpec<LibObjT>;
1359
1360 public:
1361 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstOptionFieldClass,
1362 OptionFieldClass>::type;
1363
1364 explicit CommonOptionField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
1365 {
1366 BT_ASSERT_DBG(this->isOption());
1367 }
1368
1369 template <typename OtherLibObjT>
1370 CommonOptionField(const CommonOptionField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
1371 {
1372 }
1373
1374 template <typename OtherLibObjT>
1375 CommonOptionField<LibObjT>& operator=(const CommonOptionField<OtherLibObjT> val) noexcept
1376 {
1377 _ThisCommonField::operator=(val);
1378 return *this;
1379 }
1380
1381 ConstOptionFieldClass cls() const noexcept
1382 {
1383 return ConstOptionFieldClass {
1384 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1385 }
1386
1387 Class cls() noexcept
1388 {
1389 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1390 }
1391
1392 void hasField(const bool hasField) noexcept
1393 {
1394 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1395
1396 bt_field_option_set_has_field(this->libObjPtr(), static_cast<bt_bool>(hasField));
1397 }
1398
1399 bool hasField() const noexcept
1400 {
1401 return this->field();
1402 }
1403
1404 nonstd::optional<ConstField> field() const noexcept
1405 {
1406 const auto libObjPtr =
1407 internal::CommonOptionFieldSpec<const bt_field>::field(this->libObjPtr());
1408
1409 if (libObjPtr) {
1410 return ConstField {libObjPtr};
1411 }
1412
1413 return nonstd::nullopt;
1414 }
1415
1416 nonstd::optional<CommonField<LibObjT>> field() noexcept
1417 {
1418 const auto libObjPtr = _Spec::field(this->libObjPtr());
1419
1420 if (libObjPtr) {
1421 return CommonField<LibObjT> {libObjPtr};
1422 }
1423
1424 return nonstd::nullopt;
1425 }
1426 };
1427
1428 using OptionField = CommonOptionField<bt_field>;
1429 using ConstOptionField = CommonOptionField<const bt_field>;
1430
1431 namespace internal {
1432
1433 struct OptionFieldTypeDescr
1434 {
1435 using Const = ConstOptionField;
1436 using NonConst = OptionField;
1437 };
1438
1439 template <>
1440 struct TypeDescr<OptionField> : public OptionFieldTypeDescr
1441 {
1442 };
1443
1444 template <>
1445 struct TypeDescr<ConstOptionField> : public OptionFieldTypeDescr
1446 {
1447 };
1448
1449 template <typename LibObjT>
1450 struct CommonVariantFieldSpec;
1451
1452 /* Functions specific to mutable variant fields */
1453 template <>
1454 struct CommonVariantFieldSpec<bt_field> final
1455 {
1456 static bt_field *selectedOptionField(bt_field * const libObjPtr) noexcept
1457 {
1458 return bt_field_variant_borrow_selected_option_field(libObjPtr);
1459 }
1460 };
1461
1462 /* Functions specific to constant variant fields */
1463 template <>
1464 struct CommonVariantFieldSpec<const bt_field> final
1465 {
1466 static const bt_field *selectedOptionField(const bt_field * const libObjPtr) noexcept
1467 {
1468 return bt_field_variant_borrow_selected_option_field_const(libObjPtr);
1469 }
1470 };
1471
1472 } /* namespace internal */
1473
1474 template <typename LibObjT>
1475 class CommonVariantField : public CommonField<LibObjT>
1476 {
1477 private:
1478 using typename CommonField<LibObjT>::_LibObjPtr;
1479 using typename CommonField<LibObjT>::_ThisCommonField;
1480 using _Spec = internal::CommonVariantFieldSpec<LibObjT>;
1481
1482 public:
1483 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClass,
1484 VariantFieldClass>::type;
1485
1486 explicit CommonVariantField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
1487 {
1488 BT_ASSERT_DBG(this->isVariant());
1489 }
1490
1491 template <typename OtherLibObjT>
1492 CommonVariantField(const CommonVariantField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
1493 {
1494 }
1495
1496 template <typename OtherLibObjT>
1497 CommonVariantField<LibObjT>& operator=(const CommonVariantField<OtherLibObjT> val) noexcept
1498 {
1499 _ThisCommonField::operator=(val);
1500 return *this;
1501 }
1502
1503 ConstVariantFieldClass cls() const noexcept
1504 {
1505 return ConstVariantFieldClass {
1506 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1507 }
1508
1509 Class cls() noexcept
1510 {
1511 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1512 }
1513
1514 void selectOption(const std::uint64_t index) noexcept
1515 {
1516 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1517
1518 static_cast<void>(bt_field_variant_select_option_by_index(this->libObjPtr(), index));
1519 }
1520
1521 ConstField selectedOptionField() const noexcept
1522 {
1523 return ConstField {internal::CommonVariantFieldSpec<const bt_field>::selectedOptionField(
1524 this->libObjPtr())};
1525 }
1526
1527 CommonField<LibObjT> selectedOptionField() noexcept
1528 {
1529 return CommonField<LibObjT> {_Spec::selectedOptionField(this->libObjPtr())};
1530 }
1531
1532 std::uint64_t selectedOptionIndex() const noexcept
1533 {
1534 return bt_field_variant_get_selected_option_index(this->libObjPtr());
1535 }
1536 };
1537
1538 using VariantField = CommonVariantField<bt_field>;
1539 using ConstVariantField = CommonVariantField<const bt_field>;
1540
1541 namespace internal {
1542
1543 struct VariantFieldTypeDescr
1544 {
1545 using Const = ConstVariantField;
1546 using NonConst = VariantField;
1547 };
1548
1549 template <>
1550 struct TypeDescr<VariantField> : public VariantFieldTypeDescr
1551 {
1552 };
1553
1554 template <>
1555 struct TypeDescr<ConstVariantField> : public VariantFieldTypeDescr
1556 {
1557 };
1558
1559 } /* namespace internal */
1560
1561 template <typename LibObjT>
1562 CommonBoolField<LibObjT> CommonField<LibObjT>::asBool() const noexcept
1563 {
1564 BT_ASSERT_DBG(this->isBool());
1565 return CommonBoolField<LibObjT> {this->libObjPtr()};
1566 }
1567
1568 template <typename LibObjT>
1569 CommonBitArrayField<LibObjT> CommonField<LibObjT>::asBitArray() const noexcept
1570 {
1571 BT_ASSERT_DBG(this->isBitArray());
1572 return CommonBitArrayField<LibObjT> {this->libObjPtr()};
1573 }
1574
1575 template <typename LibObjT>
1576 CommonUnsignedIntegerField<LibObjT> CommonField<LibObjT>::asUnsignedInteger() const noexcept
1577 {
1578 BT_ASSERT_DBG(this->isUnsignedInteger());
1579 return CommonUnsignedIntegerField<LibObjT> {this->libObjPtr()};
1580 }
1581
1582 template <typename LibObjT>
1583 CommonSignedIntegerField<LibObjT> CommonField<LibObjT>::asSignedInteger() const noexcept
1584 {
1585 BT_ASSERT_DBG(this->isSignedInteger());
1586 return CommonSignedIntegerField<LibObjT> {this->libObjPtr()};
1587 }
1588
1589 template <typename LibObjT>
1590 CommonUnsignedEnumerationField<LibObjT> CommonField<LibObjT>::asUnsignedEnumeration() const noexcept
1591 {
1592 BT_ASSERT_DBG(this->isUnsignedEnumeration());
1593 return CommonUnsignedEnumerationField<LibObjT> {this->libObjPtr()};
1594 }
1595
1596 template <typename LibObjT>
1597 CommonSignedEnumerationField<LibObjT> CommonField<LibObjT>::asSignedEnumeration() const noexcept
1598 {
1599 BT_ASSERT_DBG(this->isSignedEnumeration());
1600 return CommonSignedEnumerationField<LibObjT> {this->libObjPtr()};
1601 }
1602
1603 template <typename LibObjT>
1604 CommonSinglePrecisionRealField<LibObjT> CommonField<LibObjT>::asSinglePrecisionReal() const noexcept
1605 {
1606 BT_ASSERT_DBG(this->isSinglePrecisionReal());
1607 return CommonSinglePrecisionRealField<LibObjT> {this->libObjPtr()};
1608 }
1609
1610 template <typename LibObjT>
1611 CommonDoublePrecisionRealField<LibObjT> CommonField<LibObjT>::asDoublePrecisionReal() const noexcept
1612 {
1613 BT_ASSERT_DBG(this->isDoublePrecisionReal());
1614 return CommonDoublePrecisionRealField<LibObjT> {this->libObjPtr()};
1615 }
1616
1617 template <typename LibObjT>
1618 CommonStringField<LibObjT> CommonField<LibObjT>::asString() const noexcept
1619 {
1620 BT_ASSERT_DBG(this->isString());
1621 return CommonStringField<LibObjT> {this->libObjPtr()};
1622 }
1623
1624 template <typename LibObjT>
1625 CommonStructureField<LibObjT> CommonField<LibObjT>::asStructure() const noexcept
1626 {
1627 BT_ASSERT_DBG(this->isStructure());
1628 return CommonStructureField<LibObjT> {this->libObjPtr()};
1629 }
1630
1631 template <typename LibObjT>
1632 CommonArrayField<LibObjT> CommonField<LibObjT>::asArray() const noexcept
1633 {
1634 BT_ASSERT_DBG(this->isArray());
1635 return CommonArrayField<LibObjT> {this->libObjPtr()};
1636 }
1637
1638 template <typename LibObjT>
1639 CommonDynamicArrayField<LibObjT> CommonField<LibObjT>::asDynamicArray() const noexcept
1640 {
1641 BT_ASSERT_DBG(this->isDynamicArray());
1642 return CommonDynamicArrayField<LibObjT> {this->libObjPtr()};
1643 }
1644
1645 template <typename LibObjT>
1646 CommonOptionField<LibObjT> CommonField<LibObjT>::asOption() const noexcept
1647 {
1648 BT_ASSERT_DBG(this->isOption());
1649 return CommonOptionField<LibObjT> {this->libObjPtr()};
1650 }
1651
1652 template <typename LibObjT>
1653 CommonVariantField<LibObjT> CommonField<LibObjT>::asVariant() const noexcept
1654 {
1655 BT_ASSERT_DBG(this->isVariant());
1656 return CommonVariantField<LibObjT> {this->libObjPtr()};
1657 }
1658
1659 } /* namespace bt2 */
1660
1661 #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_HPP */
This page took 0.063824 seconds and 4 git commands to generate.