dd17945fa6c1e6a9f74f3265d03cb81e84f7d4d0
[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 using CommonUnsignedIntegerField<LibObjT>::operator=;
653
654 Class cls() noexcept
655 {
656 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
657 }
658
659 EnumerationFieldClassMappingLabels labels() const
660 {
661 bt_field_class_enumeration_mapping_label_array labelArray;
662 std::uint64_t count;
663 const auto status = bt_field_enumeration_unsigned_get_mapping_labels(this->libObjPtr(),
664 &labelArray, &count);
665
666 if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
667 throw MemoryError {};
668 }
669
670 return EnumerationFieldClassMappingLabels {labelArray, count};
671 }
672 };
673
674 using UnsignedEnumerationField = CommonUnsignedEnumerationField<bt_field>;
675 using ConstUnsignedEnumerationField = CommonUnsignedEnumerationField<const bt_field>;
676
677 namespace internal {
678
679 struct UnsignedEnumerationFieldTypeDescr
680 {
681 using Const = ConstUnsignedEnumerationField;
682 using NonConst = UnsignedEnumerationField;
683 };
684
685 template <>
686 struct TypeDescr<UnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr
687 {
688 };
689
690 template <>
691 struct TypeDescr<ConstUnsignedEnumerationField> : public UnsignedEnumerationFieldTypeDescr
692 {
693 };
694
695 } /* namespace internal */
696
697 template <typename LibObjT>
698 class CommonSignedEnumerationField final : public CommonSignedIntegerField<LibObjT>
699 {
700 private:
701 using typename CommonSignedIntegerField<LibObjT>::_ThisCommonSignedIntegerField;
702 using typename CommonField<LibObjT>::_LibObjPtr;
703
704 public:
705 using Class =
706 typename std::conditional<std::is_const<LibObjT>::value, ConstSignedEnumerationFieldClass,
707 SignedEnumerationFieldClass>::type;
708
709 explicit CommonSignedEnumerationField(const _LibObjPtr libObjPtr) noexcept :
710 _ThisCommonSignedIntegerField {libObjPtr}
711 {
712 BT_ASSERT_DBG(this->isSignedEnumeration());
713 }
714
715 template <typename OtherLibObjT>
716 CommonSignedEnumerationField(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept :
717 _ThisCommonSignedIntegerField {val}
718 {
719 }
720
721 template <typename OtherLibObjT>
722 CommonSignedEnumerationField<LibObjT>&
723 operator=(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept
724 {
725 _ThisCommonSignedIntegerField::operator=(val);
726 return *this;
727 }
728
729 using CommonSignedIntegerField<LibObjT>::operator=;
730
731 ConstSignedEnumerationFieldClass cls() const noexcept
732 {
733 return ConstSignedEnumerationFieldClass {
734 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
735 }
736
737 Class cls() noexcept
738 {
739 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
740 }
741
742 EnumerationFieldClassMappingLabels labels() const
743 {
744 bt_field_class_enumeration_mapping_label_array labelArray;
745 std::uint64_t count;
746 const auto status =
747 bt_field_enumeration_signed_get_mapping_labels(this->libObjPtr(), &labelArray, &count);
748
749 if (status == BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR) {
750 throw MemoryError {};
751 }
752
753 return EnumerationFieldClassMappingLabels {labelArray, count};
754 }
755 };
756
757 using SignedEnumerationField = CommonSignedEnumerationField<bt_field>;
758 using ConstSignedEnumerationField = CommonSignedEnumerationField<const bt_field>;
759
760 namespace internal {
761
762 struct SignedEnumerationFieldTypeDescr
763 {
764 using Const = ConstSignedEnumerationField;
765 using NonConst = SignedEnumerationField;
766 };
767
768 template <>
769 struct TypeDescr<SignedEnumerationField> : public SignedEnumerationFieldTypeDescr
770 {
771 };
772
773 template <>
774 struct TypeDescr<ConstSignedEnumerationField> : public SignedEnumerationFieldTypeDescr
775 {
776 };
777
778 } /* namespace internal */
779
780 template <typename LibObjT>
781 class CommonSinglePrecisionRealField final : public CommonField<LibObjT>
782 {
783 private:
784 using typename CommonField<LibObjT>::_LibObjPtr;
785 using typename CommonField<LibObjT>::_ThisCommonField;
786
787 public:
788 using Value = float;
789
790 explicit CommonSinglePrecisionRealField(const _LibObjPtr libObjPtr) noexcept :
791 _ThisCommonField {libObjPtr}
792 {
793 BT_ASSERT_DBG(this->isSinglePrecisionReal());
794 }
795
796 template <typename OtherLibObjT>
797 CommonSinglePrecisionRealField(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
798 :
799 _ThisCommonField {val}
800 {
801 }
802
803 template <typename OtherLibObjT>
804 CommonSinglePrecisionRealField<LibObjT>&
805 operator=(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
806 {
807 _ThisCommonField::operator=(val);
808 return *this;
809 }
810
811 CommonSinglePrecisionRealField<LibObjT>& operator=(const Value val) noexcept
812 {
813 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
814
815 bt_field_real_single_precision_set_value(this->libObjPtr(), val);
816 return *this;
817 }
818
819 Value value() const noexcept
820 {
821 return bt_field_real_single_precision_get_value(this->libObjPtr());
822 }
823
824 operator Value() const noexcept
825 {
826 return this->value();
827 }
828 };
829
830 using SinglePrecisionRealField = CommonSinglePrecisionRealField<bt_field>;
831 using ConstSinglePrecisionRealField = CommonSinglePrecisionRealField<const bt_field>;
832
833 namespace internal {
834
835 struct SinglePrecisionRealFieldTypeDescr
836 {
837 using Const = ConstSinglePrecisionRealField;
838 using NonConst = SinglePrecisionRealField;
839 };
840
841 template <>
842 struct TypeDescr<SinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr
843 {
844 };
845
846 template <>
847 struct TypeDescr<ConstSinglePrecisionRealField> : public SinglePrecisionRealFieldTypeDescr
848 {
849 };
850
851 } /* namespace internal */
852
853 template <typename LibObjT>
854 class CommonDoublePrecisionRealField final : public CommonField<LibObjT>
855 {
856 private:
857 using typename CommonField<LibObjT>::_LibObjPtr;
858 using typename CommonField<LibObjT>::_ThisCommonField;
859
860 public:
861 using Value = double;
862
863 explicit CommonDoublePrecisionRealField(const _LibObjPtr libObjPtr) noexcept :
864 _ThisCommonField {libObjPtr}
865 {
866 BT_ASSERT_DBG(this->isDoublePrecisionReal());
867 }
868
869 template <typename OtherLibObjT>
870 CommonDoublePrecisionRealField(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
871 :
872 _ThisCommonField {val}
873 {
874 }
875
876 template <typename OtherLibObjT>
877 CommonDoublePrecisionRealField<LibObjT>&
878 operator=(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
879 {
880 _ThisCommonField::operator=(val);
881 return *this;
882 }
883
884 CommonDoublePrecisionRealField<LibObjT>& operator=(const Value val) noexcept
885 {
886 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
887
888 bt_field_real_double_precision_set_value(this->libObjPtr(), val);
889 return *this;
890 }
891
892 Value value() const noexcept
893 {
894 return bt_field_real_double_precision_get_value(this->libObjPtr());
895 }
896
897 operator Value() const noexcept
898 {
899 return this->value();
900 }
901 };
902
903 using DoublePrecisionRealField = CommonDoublePrecisionRealField<bt_field>;
904 using ConstDoublePrecisionRealField = CommonDoublePrecisionRealField<const bt_field>;
905
906 namespace internal {
907
908 struct DoublePrecisionRealFieldTypeDescr
909 {
910 using Const = ConstDoublePrecisionRealField;
911 using NonConst = DoublePrecisionRealField;
912 };
913
914 template <>
915 struct TypeDescr<DoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr
916 {
917 };
918
919 template <>
920 struct TypeDescr<ConstDoublePrecisionRealField> : public DoublePrecisionRealFieldTypeDescr
921 {
922 };
923
924 } /* namespace internal */
925
926 template <typename LibObjT>
927 class CommonStringField final : public CommonField<LibObjT>
928 {
929 private:
930 using typename CommonField<LibObjT>::_LibObjPtr;
931 using typename CommonField<LibObjT>::_ThisCommonField;
932
933 public:
934 explicit CommonStringField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
935 {
936 BT_ASSERT_DBG(this->isString());
937 }
938
939 template <typename OtherLibObjT>
940 CommonStringField(const CommonStringField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
941 {
942 }
943
944 template <typename OtherLibObjT>
945 CommonStringField<LibObjT>& operator=(const CommonStringField<OtherLibObjT> val) noexcept
946 {
947 _ThisCommonField::operator=(val);
948 return *this;
949 }
950
951 CommonStringField<LibObjT>& operator=(const char * const val)
952 {
953 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
954
955 const auto status = bt_field_string_set_value(this->libObjPtr(), val);
956
957 if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
958 throw MemoryError {};
959 }
960
961 return *this;
962 }
963
964 CommonStringField<LibObjT>& operator=(const std::string& val)
965 {
966 return *this = val.data();
967 }
968
969 void append(const char * const begin, const std::uint64_t len)
970 {
971 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
972
973 const auto status = bt_field_string_append_with_length(this->libObjPtr(), begin, len);
974
975 if (status == BT_FIELD_STRING_APPEND_STATUS_MEMORY_ERROR) {
976 throw MemoryError {};
977 }
978 }
979
980 void append(const std::string& val)
981 {
982 this->append(val.data(), val.size());
983 }
984
985 void clear() noexcept
986 {
987 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
988
989 bt_field_string_clear(this->libObjPtr());
990 }
991
992 bpstd::string_view value() const noexcept
993 {
994 return bt_field_string_get_value(this->libObjPtr());
995 }
996 };
997
998 using StringField = CommonStringField<bt_field>;
999 using ConstStringField = CommonStringField<const bt_field>;
1000
1001 namespace internal {
1002
1003 struct StringFieldTypeDescr
1004 {
1005 using Const = ConstStringField;
1006 using NonConst = StringField;
1007 };
1008
1009 template <>
1010 struct TypeDescr<StringField> : public StringFieldTypeDescr
1011 {
1012 };
1013
1014 template <>
1015 struct TypeDescr<ConstStringField> : public StringFieldTypeDescr
1016 {
1017 };
1018
1019 template <typename LibObjT>
1020 struct CommonStructureFieldSpec;
1021
1022 /* Functions specific to mutable structure fields */
1023 template <>
1024 struct CommonStructureFieldSpec<bt_field> final
1025 {
1026 static bt_field *memberFieldByIndex(bt_field * const libObjPtr,
1027 const std::uint64_t index) noexcept
1028 {
1029 return bt_field_structure_borrow_member_field_by_index(libObjPtr, index);
1030 }
1031
1032 static bt_field *memberFieldByName(bt_field * const libObjPtr, const char * const name) noexcept
1033 {
1034 return bt_field_structure_borrow_member_field_by_name(libObjPtr, name);
1035 }
1036 };
1037
1038 /* Functions specific to constant structure fields */
1039 template <>
1040 struct CommonStructureFieldSpec<const bt_field> final
1041 {
1042 static const bt_field *memberFieldByIndex(const bt_field * const libObjPtr,
1043 const std::uint64_t index) noexcept
1044 {
1045 return bt_field_structure_borrow_member_field_by_index_const(libObjPtr, index);
1046 }
1047
1048 static const bt_field *memberFieldByName(const bt_field * const libObjPtr,
1049 const char * const name) noexcept
1050 {
1051 return bt_field_structure_borrow_member_field_by_name_const(libObjPtr, name);
1052 }
1053 };
1054
1055 } /* namespace internal */
1056
1057 template <typename LibObjT>
1058 class CommonStructureField final : public CommonField<LibObjT>
1059 {
1060 private:
1061 using typename CommonField<LibObjT>::_LibObjPtr;
1062 using typename CommonField<LibObjT>::_ThisCommonField;
1063 using _Spec = internal::CommonStructureFieldSpec<LibObjT>;
1064
1065 public:
1066 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1067 StructureFieldClass>::type;
1068
1069 explicit CommonStructureField(const _LibObjPtr libObjPtr) noexcept :
1070 _ThisCommonField {libObjPtr}
1071 {
1072 BT_ASSERT_DBG(this->isStructure());
1073 }
1074
1075 template <typename OtherLibObjT>
1076 CommonStructureField(const CommonStructureField<OtherLibObjT> val) noexcept :
1077 _ThisCommonField {val}
1078 {
1079 }
1080
1081 template <typename OtherLibObjT>
1082 CommonStructureField<LibObjT>& operator=(const CommonStructureField<OtherLibObjT> val) noexcept
1083 {
1084 _ThisCommonField::operator=(val);
1085 return *this;
1086 }
1087
1088 ConstStructureFieldClass cls() const noexcept
1089 {
1090 return ConstStructureFieldClass {
1091 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1092 }
1093
1094 Class cls() noexcept
1095 {
1096 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1097 }
1098
1099 std::uint64_t size() const noexcept
1100 {
1101 return this->cls().size();
1102 }
1103
1104 ConstField operator[](const std::uint64_t index) const noexcept
1105 {
1106 return ConstField {internal::CommonStructureFieldSpec<const bt_field>::memberFieldByIndex(
1107 this->libObjPtr(), index)};
1108 }
1109
1110 CommonField<LibObjT> operator[](const std::uint64_t index) noexcept
1111 {
1112 return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
1113 }
1114
1115 nonstd::optional<ConstField> operator[](const char * const name) const noexcept
1116 {
1117 const auto libObjPtr =
1118 internal::CommonStructureFieldSpec<const bt_field>::memberFieldByName(this->libObjPtr(),
1119 name);
1120
1121 if (libObjPtr) {
1122 return ConstField {libObjPtr};
1123 }
1124
1125 return nonstd::nullopt;
1126 }
1127
1128 nonstd::optional<ConstField> operator[](const std::string& name) const noexcept
1129 {
1130 return (*this)[name.data()];
1131 }
1132
1133 nonstd::optional<CommonField<LibObjT>> operator[](const char * const name) noexcept
1134 {
1135 const auto libObjPtr = _Spec::memberFieldByName(this->libObjPtr(), name);
1136
1137 if (libObjPtr) {
1138 return CommonField<LibObjT> {libObjPtr};
1139 }
1140
1141 return nonstd::nullopt;
1142 }
1143
1144 nonstd::optional<CommonField<LibObjT>> operator[](const std::string& name) noexcept
1145 {
1146 return (*this)[name.data()];
1147 }
1148 };
1149
1150 using StructureField = CommonStructureField<bt_field>;
1151 using ConstStructureField = CommonStructureField<const bt_field>;
1152
1153 namespace internal {
1154
1155 struct StructureFieldTypeDescr
1156 {
1157 using Const = ConstStructureField;
1158 using NonConst = StructureField;
1159 };
1160
1161 template <>
1162 struct TypeDescr<StructureField> : public StructureFieldTypeDescr
1163 {
1164 };
1165
1166 template <>
1167 struct TypeDescr<ConstStructureField> : public StructureFieldTypeDescr
1168 {
1169 };
1170
1171 template <typename LibObjT>
1172 struct CommonArrayFieldSpec;
1173
1174 /* Functions specific to mutable array fields */
1175 template <>
1176 struct CommonArrayFieldSpec<bt_field> final
1177 {
1178 static bt_field *elementFieldByIndex(bt_field * const libObjPtr,
1179 const std::uint64_t index) noexcept
1180 {
1181 return bt_field_array_borrow_element_field_by_index(libObjPtr, index);
1182 }
1183 };
1184
1185 /* Functions specific to constant array fields */
1186 template <>
1187 struct CommonArrayFieldSpec<const bt_field> final
1188 {
1189 static const bt_field *elementFieldByIndex(const bt_field * const libObjPtr,
1190 const std::uint64_t index) noexcept
1191 {
1192 return bt_field_array_borrow_element_field_by_index_const(libObjPtr, index);
1193 }
1194 };
1195
1196 } /* namespace internal */
1197
1198 template <typename LibObjT>
1199 class CommonArrayField : public CommonField<LibObjT>
1200 {
1201 private:
1202 using typename CommonField<LibObjT>::_ThisCommonField;
1203 using _Spec = internal::CommonArrayFieldSpec<LibObjT>;
1204
1205 protected:
1206 using typename CommonField<LibObjT>::_LibObjPtr;
1207 using _ThisCommonArrayField = CommonArrayField<LibObjT>;
1208
1209 public:
1210 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstArrayFieldClass,
1211 ArrayFieldClass>::type;
1212
1213 explicit CommonArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
1214 {
1215 BT_ASSERT_DBG(this->isArray());
1216 }
1217
1218 template <typename OtherLibObjT>
1219 CommonArrayField(const CommonArrayField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
1220 {
1221 }
1222
1223 template <typename OtherLibObjT>
1224 _ThisCommonArrayField& operator=(const CommonArrayField<OtherLibObjT> val) noexcept
1225 {
1226 _ThisCommonField::operator=(val);
1227 return *this;
1228 }
1229
1230 ConstArrayFieldClass cls() const noexcept
1231 {
1232 return ConstArrayFieldClass {
1233 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1234 }
1235
1236 Class cls() noexcept
1237 {
1238 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1239 }
1240
1241 std::uint64_t length() const noexcept
1242 {
1243 return bt_field_array_get_length(this->libObjPtr());
1244 }
1245
1246 ConstField operator[](const std::uint64_t index) const noexcept
1247 {
1248 return ConstField {internal::CommonArrayFieldSpec<const bt_field>::elementFieldByIndex(
1249 this->libObjPtr(), index)};
1250 }
1251
1252 CommonField<LibObjT> operator[](const std::uint64_t index) noexcept
1253 {
1254 return CommonField<LibObjT> {_Spec::elementFieldByIndex(this->libObjPtr(), index)};
1255 }
1256 };
1257
1258 using ArrayField = CommonArrayField<bt_field>;
1259 using ConstArrayField = CommonArrayField<const bt_field>;
1260
1261 namespace internal {
1262
1263 struct ArrayFieldTypeDescr
1264 {
1265 using Const = ConstArrayField;
1266 using NonConst = ArrayField;
1267 };
1268
1269 template <>
1270 struct TypeDescr<ArrayField> : public ArrayFieldTypeDescr
1271 {
1272 };
1273
1274 template <>
1275 struct TypeDescr<ConstArrayField> : public ArrayFieldTypeDescr
1276 {
1277 };
1278
1279 } /* namespace internal */
1280
1281 template <typename LibObjT>
1282 class CommonDynamicArrayField : public CommonArrayField<LibObjT>
1283 {
1284 private:
1285 using typename CommonField<LibObjT>::_LibObjPtr;
1286 using typename CommonArrayField<LibObjT>::_ThisCommonArrayField;
1287
1288 public:
1289 explicit CommonDynamicArrayField(const _LibObjPtr libObjPtr) noexcept :
1290 _ThisCommonArrayField {libObjPtr}
1291 {
1292 BT_ASSERT_DBG(this->isDynamicArray());
1293 }
1294
1295 template <typename OtherLibObjT>
1296 CommonDynamicArrayField(const CommonDynamicArrayField<OtherLibObjT> val) noexcept :
1297 _ThisCommonArrayField {val}
1298 {
1299 }
1300
1301 template <typename OtherLibObjT>
1302 CommonDynamicArrayField<LibObjT>&
1303 operator=(const CommonDynamicArrayField<OtherLibObjT> val) noexcept
1304 {
1305 _ThisCommonArrayField::operator=(val);
1306 return *this;
1307 }
1308
1309 std::uint64_t length() const noexcept
1310 {
1311 return _ThisCommonArrayField::length();
1312 }
1313
1314 void length(const std::uint64_t length)
1315 {
1316 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1317
1318 const auto status = bt_field_array_dynamic_set_length(this->libObjPtr(), length);
1319
1320 if (status == BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_MEMORY_ERROR) {
1321 throw MemoryError {};
1322 }
1323 }
1324 };
1325
1326 using DynamicArrayField = CommonDynamicArrayField<bt_field>;
1327 using ConstDynamicArrayField = CommonDynamicArrayField<const bt_field>;
1328
1329 namespace internal {
1330
1331 struct DynamicArrayFieldTypeDescr
1332 {
1333 using Const = ConstDynamicArrayField;
1334 using NonConst = DynamicArrayField;
1335 };
1336
1337 template <>
1338 struct TypeDescr<DynamicArrayField> : public DynamicArrayFieldTypeDescr
1339 {
1340 };
1341
1342 template <>
1343 struct TypeDescr<ConstDynamicArrayField> : public DynamicArrayFieldTypeDescr
1344 {
1345 };
1346
1347 template <typename LibObjT>
1348 struct CommonOptionFieldSpec;
1349
1350 /* Functions specific to mutable option fields */
1351 template <>
1352 struct CommonOptionFieldSpec<bt_field> final
1353 {
1354 static bt_field *field(bt_field * const libObjPtr) noexcept
1355 {
1356 return bt_field_option_borrow_field(libObjPtr);
1357 }
1358 };
1359
1360 /* Functions specific to constant option fields */
1361 template <>
1362 struct CommonOptionFieldSpec<const bt_field> final
1363 {
1364 static const bt_field *field(const bt_field * const libObjPtr) noexcept
1365 {
1366 return bt_field_option_borrow_field_const(libObjPtr);
1367 }
1368 };
1369
1370 } /* namespace internal */
1371
1372 template <typename LibObjT>
1373 class CommonOptionField : public CommonField<LibObjT>
1374 {
1375 private:
1376 using typename CommonField<LibObjT>::_LibObjPtr;
1377 using typename CommonField<LibObjT>::_ThisCommonField;
1378 using _Spec = internal::CommonOptionFieldSpec<LibObjT>;
1379
1380 public:
1381 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstOptionFieldClass,
1382 OptionFieldClass>::type;
1383
1384 explicit CommonOptionField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
1385 {
1386 BT_ASSERT_DBG(this->isOption());
1387 }
1388
1389 template <typename OtherLibObjT>
1390 CommonOptionField(const CommonOptionField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
1391 {
1392 }
1393
1394 template <typename OtherLibObjT>
1395 CommonOptionField<LibObjT>& operator=(const CommonOptionField<OtherLibObjT> val) noexcept
1396 {
1397 _ThisCommonField::operator=(val);
1398 return *this;
1399 }
1400
1401 ConstOptionFieldClass cls() const noexcept
1402 {
1403 return ConstOptionFieldClass {
1404 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1405 }
1406
1407 Class cls() noexcept
1408 {
1409 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1410 }
1411
1412 void hasField(const bool hasField) noexcept
1413 {
1414 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1415
1416 bt_field_option_set_has_field(this->libObjPtr(), static_cast<bt_bool>(hasField));
1417 }
1418
1419 bool hasField() const noexcept
1420 {
1421 return this->field().has_value();
1422 }
1423
1424 nonstd::optional<ConstField> field() const noexcept
1425 {
1426 const auto libObjPtr =
1427 internal::CommonOptionFieldSpec<const bt_field>::field(this->libObjPtr());
1428
1429 if (libObjPtr) {
1430 return ConstField {libObjPtr};
1431 }
1432
1433 return nonstd::nullopt;
1434 }
1435
1436 nonstd::optional<CommonField<LibObjT>> field() noexcept
1437 {
1438 const auto libObjPtr = _Spec::field(this->libObjPtr());
1439
1440 if (libObjPtr) {
1441 return CommonField<LibObjT> {libObjPtr};
1442 }
1443
1444 return nonstd::nullopt;
1445 }
1446 };
1447
1448 using OptionField = CommonOptionField<bt_field>;
1449 using ConstOptionField = CommonOptionField<const bt_field>;
1450
1451 namespace internal {
1452
1453 struct OptionFieldTypeDescr
1454 {
1455 using Const = ConstOptionField;
1456 using NonConst = OptionField;
1457 };
1458
1459 template <>
1460 struct TypeDescr<OptionField> : public OptionFieldTypeDescr
1461 {
1462 };
1463
1464 template <>
1465 struct TypeDescr<ConstOptionField> : public OptionFieldTypeDescr
1466 {
1467 };
1468
1469 template <typename LibObjT>
1470 struct CommonVariantFieldSpec;
1471
1472 /* Functions specific to mutable variant fields */
1473 template <>
1474 struct CommonVariantFieldSpec<bt_field> final
1475 {
1476 static bt_field *selectedOptionField(bt_field * const libObjPtr) noexcept
1477 {
1478 return bt_field_variant_borrow_selected_option_field(libObjPtr);
1479 }
1480 };
1481
1482 /* Functions specific to constant variant fields */
1483 template <>
1484 struct CommonVariantFieldSpec<const bt_field> final
1485 {
1486 static const bt_field *selectedOptionField(const bt_field * const libObjPtr) noexcept
1487 {
1488 return bt_field_variant_borrow_selected_option_field_const(libObjPtr);
1489 }
1490 };
1491
1492 } /* namespace internal */
1493
1494 template <typename LibObjT>
1495 class CommonVariantField : public CommonField<LibObjT>
1496 {
1497 private:
1498 using typename CommonField<LibObjT>::_LibObjPtr;
1499 using typename CommonField<LibObjT>::_ThisCommonField;
1500 using _Spec = internal::CommonVariantFieldSpec<LibObjT>;
1501
1502 public:
1503 using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClass,
1504 VariantFieldClass>::type;
1505
1506 explicit CommonVariantField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
1507 {
1508 BT_ASSERT_DBG(this->isVariant());
1509 }
1510
1511 template <typename OtherLibObjT>
1512 CommonVariantField(const CommonVariantField<OtherLibObjT> val) noexcept : _ThisCommonField {val}
1513 {
1514 }
1515
1516 template <typename OtherLibObjT>
1517 CommonVariantField<LibObjT>& operator=(const CommonVariantField<OtherLibObjT> val) noexcept
1518 {
1519 _ThisCommonField::operator=(val);
1520 return *this;
1521 }
1522
1523 ConstVariantFieldClass cls() const noexcept
1524 {
1525 return ConstVariantFieldClass {
1526 internal::CommonFieldSpec<const bt_field>::cls(this->libObjPtr())};
1527 }
1528
1529 Class cls() noexcept
1530 {
1531 return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
1532 }
1533
1534 void selectOption(const std::uint64_t index) noexcept
1535 {
1536 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1537
1538 static_cast<void>(bt_field_variant_select_option_by_index(this->libObjPtr(), index));
1539 }
1540
1541 ConstField selectedOptionField() const noexcept
1542 {
1543 return ConstField {internal::CommonVariantFieldSpec<const bt_field>::selectedOptionField(
1544 this->libObjPtr())};
1545 }
1546
1547 CommonField<LibObjT> selectedOptionField() noexcept
1548 {
1549 return CommonField<LibObjT> {_Spec::selectedOptionField(this->libObjPtr())};
1550 }
1551
1552 std::uint64_t selectedOptionIndex() const noexcept
1553 {
1554 return bt_field_variant_get_selected_option_index(this->libObjPtr());
1555 }
1556 };
1557
1558 using VariantField = CommonVariantField<bt_field>;
1559 using ConstVariantField = CommonVariantField<const bt_field>;
1560
1561 namespace internal {
1562
1563 struct VariantFieldTypeDescr
1564 {
1565 using Const = ConstVariantField;
1566 using NonConst = VariantField;
1567 };
1568
1569 template <>
1570 struct TypeDescr<VariantField> : public VariantFieldTypeDescr
1571 {
1572 };
1573
1574 template <>
1575 struct TypeDescr<ConstVariantField> : public VariantFieldTypeDescr
1576 {
1577 };
1578
1579 } /* namespace internal */
1580
1581 template <typename LibObjT>
1582 CommonBoolField<LibObjT> CommonField<LibObjT>::asBool() const noexcept
1583 {
1584 BT_ASSERT_DBG(this->isBool());
1585 return CommonBoolField<LibObjT> {this->libObjPtr()};
1586 }
1587
1588 template <typename LibObjT>
1589 CommonBitArrayField<LibObjT> CommonField<LibObjT>::asBitArray() const noexcept
1590 {
1591 BT_ASSERT_DBG(this->isBitArray());
1592 return CommonBitArrayField<LibObjT> {this->libObjPtr()};
1593 }
1594
1595 template <typename LibObjT>
1596 CommonUnsignedIntegerField<LibObjT> CommonField<LibObjT>::asUnsignedInteger() const noexcept
1597 {
1598 BT_ASSERT_DBG(this->isUnsignedInteger());
1599 return CommonUnsignedIntegerField<LibObjT> {this->libObjPtr()};
1600 }
1601
1602 template <typename LibObjT>
1603 CommonSignedIntegerField<LibObjT> CommonField<LibObjT>::asSignedInteger() const noexcept
1604 {
1605 BT_ASSERT_DBG(this->isSignedInteger());
1606 return CommonSignedIntegerField<LibObjT> {this->libObjPtr()};
1607 }
1608
1609 template <typename LibObjT>
1610 CommonUnsignedEnumerationField<LibObjT> CommonField<LibObjT>::asUnsignedEnumeration() const noexcept
1611 {
1612 BT_ASSERT_DBG(this->isUnsignedEnumeration());
1613 return CommonUnsignedEnumerationField<LibObjT> {this->libObjPtr()};
1614 }
1615
1616 template <typename LibObjT>
1617 CommonSignedEnumerationField<LibObjT> CommonField<LibObjT>::asSignedEnumeration() const noexcept
1618 {
1619 BT_ASSERT_DBG(this->isSignedEnumeration());
1620 return CommonSignedEnumerationField<LibObjT> {this->libObjPtr()};
1621 }
1622
1623 template <typename LibObjT>
1624 CommonSinglePrecisionRealField<LibObjT> CommonField<LibObjT>::asSinglePrecisionReal() const noexcept
1625 {
1626 BT_ASSERT_DBG(this->isSinglePrecisionReal());
1627 return CommonSinglePrecisionRealField<LibObjT> {this->libObjPtr()};
1628 }
1629
1630 template <typename LibObjT>
1631 CommonDoublePrecisionRealField<LibObjT> CommonField<LibObjT>::asDoublePrecisionReal() const noexcept
1632 {
1633 BT_ASSERT_DBG(this->isDoublePrecisionReal());
1634 return CommonDoublePrecisionRealField<LibObjT> {this->libObjPtr()};
1635 }
1636
1637 template <typename LibObjT>
1638 CommonStringField<LibObjT> CommonField<LibObjT>::asString() const noexcept
1639 {
1640 BT_ASSERT_DBG(this->isString());
1641 return CommonStringField<LibObjT> {this->libObjPtr()};
1642 }
1643
1644 template <typename LibObjT>
1645 CommonStructureField<LibObjT> CommonField<LibObjT>::asStructure() const noexcept
1646 {
1647 BT_ASSERT_DBG(this->isStructure());
1648 return CommonStructureField<LibObjT> {this->libObjPtr()};
1649 }
1650
1651 template <typename LibObjT>
1652 CommonArrayField<LibObjT> CommonField<LibObjT>::asArray() const noexcept
1653 {
1654 BT_ASSERT_DBG(this->isArray());
1655 return CommonArrayField<LibObjT> {this->libObjPtr()};
1656 }
1657
1658 template <typename LibObjT>
1659 CommonDynamicArrayField<LibObjT> CommonField<LibObjT>::asDynamicArray() const noexcept
1660 {
1661 BT_ASSERT_DBG(this->isDynamicArray());
1662 return CommonDynamicArrayField<LibObjT> {this->libObjPtr()};
1663 }
1664
1665 template <typename LibObjT>
1666 CommonOptionField<LibObjT> CommonField<LibObjT>::asOption() const noexcept
1667 {
1668 BT_ASSERT_DBG(this->isOption());
1669 return CommonOptionField<LibObjT> {this->libObjPtr()};
1670 }
1671
1672 template <typename LibObjT>
1673 CommonVariantField<LibObjT> CommonField<LibObjT>::asVariant() const noexcept
1674 {
1675 BT_ASSERT_DBG(this->isVariant());
1676 return CommonVariantField<LibObjT> {this->libObjPtr()};
1677 }
1678
1679 } /* namespace bt2 */
1680
1681 #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_HPP */
This page took 0.063699 seconds and 3 git commands to generate.