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