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