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