Change naming convention for enum class enumerators
[babeltrace.git] / src / cpp-common / bt2 / value.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_VALUE_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_VALUE_HPP
9
10 #include <cstdint>
11 #include <functional>
12 #include <type_traits>
13
14 #include <babeltrace2/babeltrace.h>
15
16 #include "common/assert.h"
17 #include "common/common.h"
18 #include "cpp-common/bt2c/c-string-view.hpp"
19
20 #include "borrowed-object-iterator.hpp"
21 #include "borrowed-object.hpp"
22 #include "exc.hpp"
23 #include "internal/utils.hpp"
24 #include "optional-borrowed-object.hpp"
25 #include "raw-value-proxy.hpp"
26 #include "shared-object.hpp"
27
28 namespace bt2 {
29 namespace internal {
30
31 struct ValueRefFuncs final
32 {
33 static void get(const bt_value * const libObjPtr) noexcept
34 {
35 bt_value_get_ref(libObjPtr);
36 }
37
38 static void put(const bt_value * const libObjPtr) noexcept
39 {
40 bt_value_put_ref(libObjPtr);
41 }
42 };
43
44 } /* namespace internal */
45
46 template <typename ObjT, typename LibObjT>
47 using SharedValue = SharedObject<ObjT, LibObjT, internal::ValueRefFuncs>;
48
49 template <typename LibObjT>
50 class CommonNullValue;
51
52 template <typename LibObjT>
53 class CommonBoolValue;
54
55 template <typename LibObjT>
56 class CommonUnsignedIntegerValue;
57
58 template <typename LibObjT>
59 class CommonSignedIntegerValue;
60
61 template <typename LibObjT>
62 class CommonRealValue;
63
64 template <typename LibObjT>
65 class CommonStringValue;
66
67 template <typename LibObjT>
68 class CommonArrayValue;
69
70 template <typename LibObjT>
71 class CommonMapValue;
72
73 enum class ValueType
74 {
75 Null = BT_VALUE_TYPE_NULL,
76 Bool = BT_VALUE_TYPE_BOOL,
77 UnsignedInteger = BT_VALUE_TYPE_UNSIGNED_INTEGER,
78 SignedInteger = BT_VALUE_TYPE_SIGNED_INTEGER,
79 Real = BT_VALUE_TYPE_REAL,
80 String = BT_VALUE_TYPE_STRING,
81 Array = BT_VALUE_TYPE_ARRAY,
82 Map = BT_VALUE_TYPE_MAP,
83 };
84
85 template <typename ValueObjT>
86 class CommonValueRawValueProxy final
87 {
88 public:
89 explicit CommonValueRawValueProxy(const ValueObjT obj) : _mObj {obj}
90 {
91 }
92
93 CommonValueRawValueProxy& operator=(bool rawVal) noexcept;
94 CommonValueRawValueProxy& operator=(std::int64_t rawVal) noexcept;
95 CommonValueRawValueProxy& operator=(std::uint64_t rawVal) noexcept;
96 CommonValueRawValueProxy& operator=(double rawVal) noexcept;
97 CommonValueRawValueProxy& operator=(const char *rawVal);
98 CommonValueRawValueProxy& operator=(bt2c::CStringView rawVal);
99 operator bool() const noexcept;
100 operator std::int64_t() const noexcept;
101 operator std::uint64_t() const noexcept;
102 operator double() const noexcept;
103 operator bt2c::CStringView() const noexcept;
104
105 private:
106 ValueObjT _mObj;
107 };
108
109 template <typename LibObjT>
110 class CommonValue : public BorrowedObject<LibObjT>
111 {
112 private:
113 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
114
115 protected:
116 using _ThisCommonValue = CommonValue<LibObjT>;
117
118 public:
119 using typename BorrowedObject<LibObjT>::LibObjPtr;
120 using Shared = SharedValue<CommonValue<LibObjT>, LibObjT>;
121
122 explicit CommonValue(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
123 {
124 }
125
126 template <typename OtherLibObjT>
127 CommonValue(const CommonValue<OtherLibObjT> val) noexcept : _ThisBorrowedObject {val}
128 {
129 }
130
131 template <typename OtherLibObjT>
132 _ThisCommonValue operator=(const CommonValue<OtherLibObjT> val) noexcept
133 {
134 _ThisBorrowedObject::operator=(val);
135 return *this;
136 }
137
138 CommonValue<const bt_value> asConst() const noexcept
139 {
140 return CommonValue<const bt_value> {*this};
141 }
142
143 ValueType type() const noexcept
144 {
145 return static_cast<ValueType>(bt_value_get_type(this->libObjPtr()));
146 }
147
148 bool isNull() const noexcept
149 {
150 return this->_libTypeIs(BT_VALUE_TYPE_NULL);
151 }
152
153 bool isBool() const noexcept
154 {
155 return this->_libTypeIs(BT_VALUE_TYPE_BOOL);
156 }
157
158 bool isInteger() const noexcept
159 {
160 return this->_libTypeIs(BT_VALUE_TYPE_INTEGER);
161 }
162
163 bool isUnsignedInteger() const noexcept
164 {
165 return this->_libTypeIs(BT_VALUE_TYPE_UNSIGNED_INTEGER);
166 }
167
168 bool isSignedInteger() const noexcept
169 {
170 return this->_libTypeIs(BT_VALUE_TYPE_SIGNED_INTEGER);
171 }
172
173 bool isReal() const noexcept
174 {
175 return this->_libTypeIs(BT_VALUE_TYPE_REAL);
176 }
177
178 bool isString() const noexcept
179 {
180 return this->_libTypeIs(BT_VALUE_TYPE_STRING);
181 }
182
183 bool isArray() const noexcept
184 {
185 return this->_libTypeIs(BT_VALUE_TYPE_ARRAY);
186 }
187
188 bool isMap() const noexcept
189 {
190 return this->_libTypeIs(BT_VALUE_TYPE_MAP);
191 }
192
193 template <typename OtherLibObjT>
194 bool operator==(const CommonValue<OtherLibObjT> other) const noexcept
195 {
196 return static_cast<bool>(bt_value_is_equal(this->libObjPtr(), other.libObjPtr()));
197 }
198
199 template <typename OtherLibObjT>
200 bool operator!=(const CommonValue<OtherLibObjT> other) const noexcept
201 {
202 return !(*this == other);
203 }
204
205 CommonValueRawValueProxy<CommonValue> operator*() const noexcept
206 {
207 return CommonValueRawValueProxy<CommonValue> {*this};
208 }
209
210 std::uint64_t arrayLength() const noexcept
211 {
212 return this->asArray().length();
213 }
214
215 bool arrayIsEmpty() const noexcept
216 {
217 return this->asArray().isEmpty();
218 }
219
220 CommonValue<LibObjT> operator[](const std::uint64_t index) const noexcept
221 {
222 return this->asArray()[index];
223 }
224
225 template <typename T>
226 void append(T&& elem) const
227 {
228 this->asArray().append(std::forward<T>(elem));
229 }
230
231 CommonArrayValue<bt_value> appendEmptyArray() const;
232 CommonMapValue<bt_value> appendEmptyMap() const;
233
234 std::uint64_t mapLength() const noexcept
235 {
236 return this->asMap().length();
237 }
238
239 bool mapIsEmpty() const noexcept
240 {
241 return this->asMap().isEmpty();
242 }
243
244 template <typename KeyT>
245 OptionalBorrowedObject<CommonValue<LibObjT>> operator[](KeyT&& key) const noexcept
246 {
247 return this->asMap()[std::forward<KeyT>(key)];
248 }
249
250 template <typename KeyT>
251 bool hasEntry(KeyT&& key) const noexcept
252 {
253 return this->asMap().hasEntry(std::forward<KeyT>(key));
254 }
255
256 template <typename KeyT, typename ValT>
257 void insert(KeyT&& key, ValT&& val) const
258 {
259 this->asMap().insert(std::forward<KeyT>(key), std::forward<ValT>(val));
260 }
261
262 CommonArrayValue<bt_value> insertEmptyArray(bt2c::CStringView key) const;
263 CommonMapValue<bt_value> insertEmptyMap(bt2c::CStringView key) const;
264
265 Shared shared() const noexcept
266 {
267 return Shared::createWithRef(*this);
268 }
269
270 template <typename ValueT>
271 ValueT as() const noexcept
272 {
273 return ValueT {this->libObjPtr()};
274 }
275
276 CommonNullValue<LibObjT> asNull() const noexcept;
277 CommonBoolValue<LibObjT> asBool() const noexcept;
278 CommonSignedIntegerValue<LibObjT> asSignedInteger() const noexcept;
279 CommonUnsignedIntegerValue<LibObjT> asUnsignedInteger() const noexcept;
280 CommonRealValue<LibObjT> asReal() const noexcept;
281 CommonStringValue<LibObjT> asString() const noexcept;
282 CommonArrayValue<LibObjT> asArray() const noexcept;
283 CommonMapValue<LibObjT> asMap() const noexcept;
284
285 protected:
286 bool _libTypeIs(const bt_value_type type) const noexcept
287 {
288 return bt_value_type_is(bt_value_get_type(this->libObjPtr()), type);
289 }
290 };
291
292 using Value = CommonValue<bt_value>;
293 using ConstValue = CommonValue<const bt_value>;
294
295 template <typename ValueObjT>
296 CommonValueRawValueProxy<ValueObjT>&
297 CommonValueRawValueProxy<ValueObjT>::operator=(const bool rawVal) noexcept
298 {
299 _mObj.asBool().value(rawVal);
300 return *this;
301 }
302
303 template <typename ValueObjT>
304 CommonValueRawValueProxy<ValueObjT>&
305 CommonValueRawValueProxy<ValueObjT>::operator=(const std::int64_t rawVal) noexcept
306 {
307 _mObj.asSignedInteger().value(rawVal);
308 return *this;
309 }
310
311 template <typename ValueObjT>
312 CommonValueRawValueProxy<ValueObjT>&
313 CommonValueRawValueProxy<ValueObjT>::operator=(const std::uint64_t rawVal) noexcept
314 {
315 _mObj.asUnsignedInteger().value(rawVal);
316 return *this;
317 }
318
319 template <typename ValueObjT>
320 CommonValueRawValueProxy<ValueObjT>&
321 CommonValueRawValueProxy<ValueObjT>::operator=(const double rawVal) noexcept
322 {
323 _mObj.asReal().value(rawVal);
324 return *this;
325 }
326
327 template <typename ValueObjT>
328 CommonValueRawValueProxy<ValueObjT>&
329 CommonValueRawValueProxy<ValueObjT>::operator=(const char * const rawVal)
330 {
331 _mObj.asString().value(rawVal);
332 return *this;
333 }
334
335 template <typename ValueObjT>
336 CommonValueRawValueProxy<ValueObjT>&
337 CommonValueRawValueProxy<ValueObjT>::operator=(const bt2c::CStringView rawVal)
338 {
339 _mObj.asString().value(rawVal);
340 return *this;
341 }
342
343 template <typename ValueObjT>
344 CommonValueRawValueProxy<ValueObjT>::operator bool() const noexcept
345 {
346 return _mObj.asBool().value();
347 }
348
349 template <typename ValueObjT>
350 CommonValueRawValueProxy<ValueObjT>::operator std::int64_t() const noexcept
351 {
352 return _mObj.asSignedInteger().value();
353 }
354
355 template <typename ValueObjT>
356 CommonValueRawValueProxy<ValueObjT>::operator std::uint64_t() const noexcept
357 {
358 return _mObj.asUnsignedInteger().value();
359 }
360
361 template <typename ValueObjT>
362 CommonValueRawValueProxy<ValueObjT>::operator double() const noexcept
363 {
364 return _mObj.asReal().value();
365 }
366
367 template <typename ValueObjT>
368 CommonValueRawValueProxy<ValueObjT>::operator bt2c::CStringView() const noexcept
369 {
370 return _mObj.asString().value();
371 }
372
373 namespace internal {
374
375 struct ValueTypeDescr
376 {
377 using Const = ConstValue;
378 using NonConst = Value;
379 };
380
381 template <>
382 struct TypeDescr<Value> : public ValueTypeDescr
383 {
384 };
385
386 template <>
387 struct TypeDescr<ConstValue> : public ValueTypeDescr
388 {
389 };
390
391 } /* namespace internal */
392
393 template <typename LibObjT>
394 class CommonNullValue final : public CommonValue<LibObjT>
395 {
396 private:
397 using typename CommonValue<LibObjT>::_ThisCommonValue;
398
399 public:
400 using Shared = SharedValue<CommonNullValue<LibObjT>, LibObjT>;
401
402 CommonNullValue() noexcept : _ThisCommonValue {bt_value_null}
403 {
404 }
405
406 template <typename OtherLibObjT>
407 CommonNullValue(const CommonNullValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
408 {
409 }
410
411 template <typename OtherLibObjT>
412 CommonNullValue<LibObjT> operator=(const CommonNullValue<OtherLibObjT> val) noexcept
413 {
414 _ThisCommonValue::operator=(val);
415 return *this;
416 }
417
418 CommonNullValue<const bt_value> asConst() const noexcept
419 {
420 return CommonNullValue<const bt_value> {*this};
421 }
422
423 Shared shared() const noexcept
424 {
425 return Shared::createWithRef(*this);
426 }
427 };
428
429 using NullValue = CommonNullValue<bt_value>;
430 using ConstNullValue = CommonNullValue<const bt_value>;
431
432 namespace internal {
433
434 struct NullValueTypeDescr
435 {
436 using Const = ConstNullValue;
437 using NonConst = NullValue;
438 };
439
440 template <>
441 struct TypeDescr<NullValue> : public NullValueTypeDescr
442 {
443 };
444
445 template <>
446 struct TypeDescr<ConstNullValue> : public NullValueTypeDescr
447 {
448 };
449
450 } /* namespace internal */
451
452 template <typename LibObjT>
453 class CommonBoolValue final : public CommonValue<LibObjT>
454 {
455 private:
456 using typename CommonValue<LibObjT>::_ThisCommonValue;
457
458 public:
459 using typename CommonValue<LibObjT>::LibObjPtr;
460 using Shared = SharedValue<CommonBoolValue<LibObjT>, LibObjT>;
461 using Value = bool;
462
463 explicit CommonBoolValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
464 {
465 BT_ASSERT_DBG(this->isBool());
466 }
467
468 template <typename OtherLibObjT>
469 CommonBoolValue(const CommonBoolValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
470 {
471 }
472
473 static Shared create(const Value rawVal = false)
474 {
475 const auto libObjPtr = bt_value_bool_create_init(static_cast<bt_bool>(rawVal));
476
477 internal::validateCreatedObjPtr(libObjPtr);
478 return CommonBoolValue::Shared::createWithoutRef(libObjPtr);
479 }
480
481 template <typename OtherLibObjT>
482 CommonBoolValue<LibObjT> operator=(const CommonBoolValue<OtherLibObjT> val) noexcept
483 {
484 _ThisCommonValue::operator=(val);
485 return *this;
486 }
487
488 CommonBoolValue<const bt_value> asConst() const noexcept
489 {
490 return CommonBoolValue<const bt_value> {*this};
491 }
492
493 RawValueProxy<CommonBoolValue> operator*() const noexcept
494 {
495 return RawValueProxy<CommonBoolValue> {*this};
496 }
497
498 Value value() const noexcept
499 {
500 return static_cast<Value>(bt_value_bool_get(this->libObjPtr()));
501 }
502
503 CommonBoolValue value(const Value val) const noexcept
504 {
505 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstBoolValue`.");
506
507 bt_value_bool_set(this->libObjPtr(), static_cast<bt_bool>(val));
508 return *this;
509 }
510
511 Shared shared() const noexcept
512 {
513 return Shared::createWithRef(*this);
514 }
515 };
516
517 using BoolValue = CommonBoolValue<bt_value>;
518 using ConstBoolValue = CommonBoolValue<const bt_value>;
519
520 namespace internal {
521
522 struct BoolValueTypeDescr
523 {
524 using Const = ConstBoolValue;
525 using NonConst = BoolValue;
526 };
527
528 template <>
529 struct TypeDescr<BoolValue> : public BoolValueTypeDescr
530 {
531 };
532
533 template <>
534 struct TypeDescr<ConstBoolValue> : public BoolValueTypeDescr
535 {
536 };
537
538 } /* namespace internal */
539
540 template <typename LibObjT>
541 class CommonUnsignedIntegerValue final : public CommonValue<LibObjT>
542 {
543 private:
544 using typename CommonValue<LibObjT>::_ThisCommonValue;
545
546 public:
547 using typename CommonValue<LibObjT>::LibObjPtr;
548 using Shared = SharedValue<CommonUnsignedIntegerValue<LibObjT>, LibObjT>;
549 using Value = std::uint64_t;
550
551 explicit CommonUnsignedIntegerValue(const LibObjPtr libObjPtr) noexcept :
552 _ThisCommonValue {libObjPtr}
553 {
554 BT_ASSERT_DBG(this->isUnsignedInteger());
555 }
556
557 static Shared create(const Value rawVal = 0)
558 {
559 const auto libObjPtr = bt_value_integer_unsigned_create_init(rawVal);
560
561 internal::validateCreatedObjPtr(libObjPtr);
562 return CommonUnsignedIntegerValue::Shared::createWithoutRef(libObjPtr);
563 }
564
565 template <typename OtherLibObjT>
566 CommonUnsignedIntegerValue(const CommonUnsignedIntegerValue<OtherLibObjT> val) noexcept :
567 _ThisCommonValue {val}
568 {
569 }
570
571 template <typename OtherLibObjT>
572 CommonUnsignedIntegerValue<LibObjT>
573 operator=(const CommonUnsignedIntegerValue<OtherLibObjT> val) noexcept
574 {
575 _ThisCommonValue::operator=(val);
576 return *this;
577 }
578
579 CommonUnsignedIntegerValue<const bt_value> asConst() const noexcept
580 {
581 return CommonUnsignedIntegerValue<const bt_value> {*this};
582 }
583
584 RawValueProxy<CommonUnsignedIntegerValue> operator*() const noexcept
585 {
586 return RawValueProxy<CommonUnsignedIntegerValue> {*this};
587 }
588
589 CommonUnsignedIntegerValue value(const Value val) const noexcept
590 {
591 static_assert(!std::is_const<LibObjT>::value,
592 "Not available with `bt2::ConstUnsignedIntegerValue`.");
593
594 bt_value_integer_unsigned_set(this->libObjPtr(), val);
595 return *this;
596 }
597
598 Value value() const noexcept
599 {
600 return bt_value_integer_unsigned_get(this->libObjPtr());
601 }
602
603 Shared shared() const noexcept
604 {
605 return Shared::createWithRef(*this);
606 }
607 };
608
609 using UnsignedIntegerValue = CommonUnsignedIntegerValue<bt_value>;
610 using ConstUnsignedIntegerValue = CommonUnsignedIntegerValue<const bt_value>;
611
612 namespace internal {
613
614 struct UnsignedIntegerValueTypeDescr
615 {
616 using Const = ConstUnsignedIntegerValue;
617 using NonConst = UnsignedIntegerValue;
618 };
619
620 template <>
621 struct TypeDescr<UnsignedIntegerValue> : public UnsignedIntegerValueTypeDescr
622 {
623 };
624
625 template <>
626 struct TypeDescr<ConstUnsignedIntegerValue> : public UnsignedIntegerValueTypeDescr
627 {
628 };
629
630 } /* namespace internal */
631
632 template <typename LibObjT>
633 class CommonSignedIntegerValue final : public CommonValue<LibObjT>
634 {
635 private:
636 using typename CommonValue<LibObjT>::_ThisCommonValue;
637
638 public:
639 using typename CommonValue<LibObjT>::LibObjPtr;
640 using Shared = SharedValue<CommonSignedIntegerValue<LibObjT>, LibObjT>;
641 using Value = std::int64_t;
642
643 explicit CommonSignedIntegerValue(const LibObjPtr libObjPtr) noexcept :
644 _ThisCommonValue {libObjPtr}
645 {
646 BT_ASSERT_DBG(this->isSignedInteger());
647 }
648
649 static Shared create(const Value rawVal = 0)
650 {
651 const auto libObjPtr = bt_value_integer_signed_create_init(rawVal);
652
653 internal::validateCreatedObjPtr(libObjPtr);
654 return CommonSignedIntegerValue::Shared::createWithoutRef(libObjPtr);
655 }
656
657 template <typename OtherLibObjT>
658 CommonSignedIntegerValue(const CommonSignedIntegerValue<OtherLibObjT> val) noexcept :
659 _ThisCommonValue {val}
660 {
661 }
662
663 template <typename OtherLibObjT>
664 CommonSignedIntegerValue<LibObjT>
665 operator=(const CommonSignedIntegerValue<OtherLibObjT> val) noexcept
666 {
667 _ThisCommonValue::operator=(val);
668 return *this;
669 }
670
671 CommonSignedIntegerValue<const bt_value> asConst() const noexcept
672 {
673 return CommonSignedIntegerValue<const bt_value> {*this};
674 }
675
676 RawValueProxy<CommonSignedIntegerValue> operator*() const noexcept
677 {
678 return RawValueProxy<CommonSignedIntegerValue> {*this};
679 }
680
681 CommonSignedIntegerValue value(const Value val) const noexcept
682 {
683 static_assert(!std::is_const<LibObjT>::value,
684 "Not available with `bt2::ConstSignedIntegerValue`.");
685
686 bt_value_integer_signed_set(this->libObjPtr(), val);
687 return *this;
688 }
689
690 Value value() const noexcept
691 {
692 return bt_value_integer_signed_get(this->libObjPtr());
693 }
694
695 Shared shared() const noexcept
696 {
697 return Shared::createWithRef(*this);
698 }
699 };
700
701 using SignedIntegerValue = CommonSignedIntegerValue<bt_value>;
702 using ConstSignedIntegerValue = CommonSignedIntegerValue<const bt_value>;
703
704 namespace internal {
705
706 struct SignedIntegerValueTypeDescr
707 {
708 using Const = ConstSignedIntegerValue;
709 using NonConst = SignedIntegerValue;
710 };
711
712 template <>
713 struct TypeDescr<SignedIntegerValue> : public SignedIntegerValueTypeDescr
714 {
715 };
716
717 template <>
718 struct TypeDescr<ConstSignedIntegerValue> : public SignedIntegerValueTypeDescr
719 {
720 };
721
722 } /* namespace internal */
723
724 template <typename LibObjT>
725 class CommonRealValue final : public CommonValue<LibObjT>
726 {
727 private:
728 using typename CommonValue<LibObjT>::_ThisCommonValue;
729
730 public:
731 using typename CommonValue<LibObjT>::LibObjPtr;
732 using Shared = SharedValue<CommonRealValue<LibObjT>, LibObjT>;
733 using Value = double;
734
735 explicit CommonRealValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
736 {
737 BT_ASSERT_DBG(this->isReal());
738 }
739
740 static Shared create(const Value rawVal = 0)
741 {
742 const auto libObjPtr = bt_value_real_create_init(rawVal);
743
744 internal::validateCreatedObjPtr(libObjPtr);
745 return CommonRealValue::Shared::createWithoutRef(libObjPtr);
746 }
747
748 template <typename OtherLibObjT>
749 CommonRealValue(const CommonRealValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
750 {
751 }
752
753 template <typename OtherLibObjT>
754 CommonRealValue<LibObjT> operator=(const CommonRealValue<OtherLibObjT> val) noexcept
755 {
756 _ThisCommonValue::operator=(val);
757 return *this;
758 }
759
760 CommonRealValue<const bt_value> asConst() const noexcept
761 {
762 return CommonRealValue<const bt_value> {*this};
763 }
764
765 RawValueProxy<CommonRealValue> operator*() const noexcept
766 {
767 return RawValueProxy<CommonRealValue> {*this};
768 }
769
770 CommonRealValue value(const Value val) const noexcept
771 {
772 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstRealValue`.");
773
774 bt_value_real_set(this->libObjPtr(), val);
775 return *this;
776 }
777
778 Value value() const noexcept
779 {
780 return bt_value_real_get(this->libObjPtr());
781 }
782
783 Shared shared() const noexcept
784 {
785 return Shared::createWithRef(*this);
786 }
787 };
788
789 using RealValue = CommonRealValue<bt_value>;
790 using ConstRealValue = CommonRealValue<const bt_value>;
791
792 namespace internal {
793
794 struct RealValueTypeDescr
795 {
796 using Const = ConstRealValue;
797 using NonConst = RealValue;
798 };
799
800 template <>
801 struct TypeDescr<RealValue> : public RealValueTypeDescr
802 {
803 };
804
805 template <>
806 struct TypeDescr<ConstRealValue> : public RealValueTypeDescr
807 {
808 };
809
810 } /* namespace internal */
811
812 template <typename LibObjT>
813 class CommonStringValue final : public CommonValue<LibObjT>
814 {
815 private:
816 using typename CommonValue<LibObjT>::_ThisCommonValue;
817
818 public:
819 using typename CommonValue<LibObjT>::LibObjPtr;
820 using Shared = SharedValue<CommonStringValue<LibObjT>, LibObjT>;
821 using Value = bt2c::CStringView;
822
823 explicit CommonStringValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
824 {
825 BT_ASSERT_DBG(this->isString());
826 }
827
828 static Shared create(const bt2c::CStringView rawVal = "")
829 {
830 const auto libObjPtr = bt_value_string_create_init(rawVal);
831
832 internal::validateCreatedObjPtr(libObjPtr);
833 return CommonStringValue::Shared::createWithoutRef(libObjPtr);
834 }
835
836 template <typename OtherLibObjT>
837 CommonStringValue(const CommonStringValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
838 {
839 }
840
841 template <typename OtherLibObjT>
842 CommonStringValue<LibObjT> operator=(const CommonStringValue<OtherLibObjT> val) noexcept
843 {
844 _ThisCommonValue::operator=(val);
845 return *this;
846 }
847
848 CommonStringValue<const bt_value> asConst() const noexcept
849 {
850 return CommonStringValue<const bt_value> {*this};
851 }
852
853 RawValueProxy<CommonStringValue> operator*() const noexcept
854 {
855 return RawValueProxy<CommonStringValue> {*this};
856 }
857
858 CommonStringValue value(const Value val) const
859 {
860 static_assert(!std::is_const<LibObjT>::value,
861 "Not available with `bt2::ConstStringValue`.");
862
863 const auto status = bt_value_string_set(this->libObjPtr(), *val);
864
865 if (status == BT_VALUE_STRING_SET_STATUS_MEMORY_ERROR) {
866 throw MemoryError {};
867 }
868
869 return *this;
870 }
871
872 Value value() const noexcept
873 {
874 return bt_value_string_get(this->libObjPtr());
875 }
876
877 Shared shared() const noexcept
878 {
879 return Shared::createWithRef(*this);
880 }
881 };
882
883 using StringValue = CommonStringValue<bt_value>;
884 using ConstStringValue = CommonStringValue<const bt_value>;
885
886 namespace internal {
887
888 struct StringValueTypeDescr
889 {
890 using Const = ConstStringValue;
891 using NonConst = StringValue;
892 };
893
894 template <>
895 struct TypeDescr<StringValue> : public StringValueTypeDescr
896 {
897 };
898
899 template <>
900 struct TypeDescr<ConstStringValue> : public StringValueTypeDescr
901 {
902 };
903
904 template <typename LibObjT>
905 struct CommonArrayValueSpec;
906
907 /* Functions specific to mutable array values */
908 template <>
909 struct CommonArrayValueSpec<bt_value> final
910 {
911 static bt_value *elementByIndex(bt_value * const libValPtr, const std::uint64_t index) noexcept
912 {
913 return bt_value_array_borrow_element_by_index(libValPtr, index);
914 }
915 };
916
917 /* Functions specific to constant array values */
918 template <>
919 struct CommonArrayValueSpec<const bt_value> final
920 {
921 static const bt_value *elementByIndex(const bt_value * const libValPtr,
922 const std::uint64_t index) noexcept
923 {
924 return bt_value_array_borrow_element_by_index_const(libValPtr, index);
925 }
926 };
927
928 } /* namespace internal */
929
930 template <typename LibObjT>
931 class CommonArrayValue final : public CommonValue<LibObjT>
932 {
933 private:
934 using typename CommonValue<LibObjT>::_ThisCommonValue;
935
936 public:
937 using typename CommonValue<LibObjT>::LibObjPtr;
938 using Shared = SharedValue<CommonArrayValue<LibObjT>, LibObjT>;
939 using Iterator = BorrowedObjectIterator<CommonArrayValue<LibObjT>>;
940
941 explicit CommonArrayValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
942 {
943 BT_ASSERT_DBG(this->isArray());
944 }
945
946 static Shared create()
947 {
948 const auto libObjPtr = bt_value_array_create();
949
950 internal::validateCreatedObjPtr(libObjPtr);
951 return CommonArrayValue::Shared::createWithoutRef(libObjPtr);
952 }
953
954 template <typename OtherLibObjT>
955 CommonArrayValue(const CommonArrayValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
956 {
957 }
958
959 template <typename OtherLibObjT>
960 CommonArrayValue<LibObjT> operator=(const CommonArrayValue<OtherLibObjT> val) noexcept
961 {
962 _ThisCommonValue::operator=(val);
963 return *this;
964 }
965
966 CommonArrayValue<const bt_value> asConst() const noexcept
967 {
968 return CommonArrayValue<const bt_value> {*this};
969 }
970
971 std::uint64_t length() const noexcept
972 {
973 return bt_value_array_get_length(this->libObjPtr());
974 }
975
976 Iterator begin() const noexcept
977 {
978 return Iterator {*this, 0};
979 }
980
981 Iterator end() const noexcept
982 {
983 return Iterator {*this, this->length()};
984 }
985
986 bool isEmpty() const noexcept
987 {
988 return this->length() == 0;
989 }
990
991 CommonValue<LibObjT> operator[](const std::uint64_t index) const noexcept
992 {
993 return CommonValue<LibObjT> {
994 internal::CommonArrayValueSpec<LibObjT>::elementByIndex(this->libObjPtr(), index)};
995 }
996
997 CommonArrayValue append(const Value val) const
998 {
999 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1000
1001 const auto status = bt_value_array_append_element(this->libObjPtr(), val.libObjPtr());
1002
1003 this->_handleAppendLibStatus(status);
1004 return *this;
1005 }
1006
1007 CommonArrayValue append(const bool rawVal) const
1008 {
1009 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1010
1011 const auto status =
1012 bt_value_array_append_bool_element(this->libObjPtr(), static_cast<bt_bool>(rawVal));
1013
1014 this->_handleAppendLibStatus(status);
1015 return *this;
1016 }
1017
1018 CommonArrayValue append(const std::uint64_t rawVal) const
1019 {
1020 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1021
1022 const auto status =
1023 bt_value_array_append_unsigned_integer_element(this->libObjPtr(), rawVal);
1024
1025 this->_handleAppendLibStatus(status);
1026 return *this;
1027 }
1028
1029 CommonArrayValue append(const std::int64_t rawVal) const
1030 {
1031 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1032
1033 const auto status = bt_value_array_append_signed_integer_element(this->libObjPtr(), rawVal);
1034
1035 this->_handleAppendLibStatus(status);
1036 return *this;
1037 }
1038
1039 CommonArrayValue append(const double rawVal) const
1040 {
1041 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1042
1043 const auto status = bt_value_array_append_real_element(this->libObjPtr(), rawVal);
1044
1045 this->_handleAppendLibStatus(status);
1046 return *this;
1047 }
1048
1049 CommonArrayValue append(const char * const rawVal) const
1050 {
1051 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1052
1053 const auto status = bt_value_array_append_string_element(this->libObjPtr(), rawVal);
1054
1055 this->_handleAppendLibStatus(status);
1056 return *this;
1057 }
1058
1059 CommonArrayValue append(const bt2c::CStringView rawVal) const
1060 {
1061 return this->append(rawVal.data());
1062 }
1063
1064 CommonArrayValue<bt_value> appendEmptyArray() const;
1065 CommonMapValue<bt_value> appendEmptyMap() const;
1066
1067 void operator+=(const Value val) const
1068 {
1069 this->append(val);
1070 }
1071
1072 void operator+=(const bool rawVal) const
1073 {
1074 this->append(rawVal);
1075 }
1076
1077 void operator+=(const std::uint64_t rawVal) const
1078 {
1079 this->append(rawVal);
1080 }
1081
1082 void operator+=(const std::int64_t rawVal) const
1083 {
1084 this->append(rawVal);
1085 }
1086
1087 void operator+=(const double rawVal) const
1088 {
1089 this->append(rawVal);
1090 }
1091
1092 void operator+=(const char * const rawVal) const
1093 {
1094 this->append(rawVal);
1095 }
1096
1097 void operator+=(const bt2c::CStringView rawVal) const
1098 {
1099 this->append(rawVal);
1100 }
1101
1102 Shared shared() const noexcept
1103 {
1104 return Shared::createWithRef(*this);
1105 }
1106
1107 private:
1108 void _handleAppendLibStatus(const bt_value_array_append_element_status status) const
1109 {
1110 if (status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_MEMORY_ERROR) {
1111 throw MemoryError {};
1112 }
1113 }
1114 };
1115
1116 using ArrayValue = CommonArrayValue<bt_value>;
1117 using ConstArrayValue = CommonArrayValue<const bt_value>;
1118
1119 namespace internal {
1120
1121 struct ArrayValueTypeDescr
1122 {
1123 using Const = ConstArrayValue;
1124 using NonConst = ArrayValue;
1125 };
1126
1127 template <>
1128 struct TypeDescr<ArrayValue> : public ArrayValueTypeDescr
1129 {
1130 };
1131
1132 template <>
1133 struct TypeDescr<ConstArrayValue> : public ArrayValueTypeDescr
1134 {
1135 };
1136
1137 /*
1138 * Type of a user function passed to `CommonMapValue<ObjT>::forEach()`.
1139 *
1140 * First argument is the entry's key, second is its value.
1141 */
1142 template <typename ObjT>
1143 using CommonMapValueForEachUserFunc = std::function<void(bt2c::CStringView, ObjT)>;
1144
1145 /*
1146 * Template of a function to be passed to bt_value_map_foreach_entry()
1147 * for bt_value_map_foreach_entry_const() which calls a user function.
1148 *
1149 * `userData` is casted to a `const` pointer to
1150 * `CommonMapValueForEachUserFunc<ObjT>` (the user function to call).
1151 *
1152 * This function catches any exception which the user function throws
1153 * and returns the `ErrorStatus` value. If there's no exception, this
1154 * function returns the `OkStatus` value.
1155 */
1156 template <typename ObjT, typename LibObjT, typename LibStatusT, int OkStatus, int ErrorStatus>
1157 LibStatusT mapValueForEachLibFunc(const char * const key, LibObjT * const libObjPtr,
1158 void * const userData)
1159 {
1160 const auto& userFunc = *reinterpret_cast<const CommonMapValueForEachUserFunc<ObjT> *>(userData);
1161
1162 try {
1163 userFunc(key, ObjT {libObjPtr});
1164 } catch (...) {
1165 return static_cast<LibStatusT>(ErrorStatus);
1166 }
1167
1168 return static_cast<LibStatusT>(OkStatus);
1169 }
1170
1171 template <typename LibObjT>
1172 struct CommonMapValueSpec;
1173
1174 /* Functions specific to mutable map values */
1175 template <>
1176 struct CommonMapValueSpec<bt_value> final
1177 {
1178 static bt_value *entryByKey(bt_value * const libValPtr, const char * const key) noexcept
1179 {
1180 return bt_value_map_borrow_entry_value(libValPtr, key);
1181 }
1182
1183 static void forEach(bt_value * const libValPtr,
1184 const CommonMapValueForEachUserFunc<Value>& func)
1185 {
1186 const auto status = bt_value_map_foreach_entry(
1187 libValPtr,
1188 mapValueForEachLibFunc<Value, bt_value, bt_value_map_foreach_entry_func_status,
1189 BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK,
1190 BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR>,
1191 const_cast<void *>(reinterpret_cast<const void *>(&func)));
1192
1193 switch (status) {
1194 case BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK:
1195 return;
1196 case BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR:
1197 case BT_VALUE_MAP_FOREACH_ENTRY_STATUS_ERROR:
1198 throw Error {};
1199 default:
1200 bt_common_abort();
1201 }
1202 }
1203 };
1204
1205 /* Functions specific to constant map values */
1206 template <>
1207 struct CommonMapValueSpec<const bt_value> final
1208 {
1209 static const bt_value *entryByKey(const bt_value * const libValPtr,
1210 const char * const key) noexcept
1211 {
1212 return bt_value_map_borrow_entry_value_const(libValPtr, key);
1213 }
1214
1215 static void forEach(const bt_value * const libValPtr,
1216 const CommonMapValueForEachUserFunc<ConstValue>& func)
1217 {
1218 const auto status = bt_value_map_foreach_entry_const(
1219 libValPtr,
1220 mapValueForEachLibFunc<ConstValue, const bt_value,
1221 bt_value_map_foreach_entry_const_func_status,
1222 BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK,
1223 BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_ERROR>,
1224 const_cast<void *>(reinterpret_cast<const void *>(&func)));
1225
1226 switch (status) {
1227 case BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK:
1228 return;
1229 case BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_USER_ERROR:
1230 case BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_ERROR:
1231 throw Error {};
1232 default:
1233 bt_common_abort();
1234 }
1235 }
1236 };
1237
1238 } /* namespace internal */
1239
1240 template <typename LibObjT>
1241 class CommonMapValue final : public CommonValue<LibObjT>
1242 {
1243 private:
1244 using typename CommonValue<LibObjT>::_ThisCommonValue;
1245
1246 public:
1247 using typename CommonValue<LibObjT>::LibObjPtr;
1248 using Shared = SharedValue<CommonMapValue<LibObjT>, LibObjT>;
1249
1250 explicit CommonMapValue(const LibObjPtr libObjPtr) noexcept : _ThisCommonValue {libObjPtr}
1251 {
1252 BT_ASSERT_DBG(this->isMap());
1253 }
1254
1255 static Shared create()
1256 {
1257 const auto libObjPtr = bt_value_map_create();
1258
1259 internal::validateCreatedObjPtr(libObjPtr);
1260 return CommonMapValue::Shared::createWithoutRef(libObjPtr);
1261 }
1262
1263 template <typename OtherLibObjT>
1264 CommonMapValue(const CommonMapValue<OtherLibObjT> val) noexcept : _ThisCommonValue {val}
1265 {
1266 }
1267
1268 template <typename OtherLibObjT>
1269 CommonMapValue<LibObjT> operator=(const CommonMapValue<OtherLibObjT> val) noexcept
1270 {
1271 _ThisCommonValue::operator=(val);
1272 return *this;
1273 }
1274
1275 CommonMapValue<const bt_value> asConst() const noexcept
1276 {
1277 return CommonMapValue<const bt_value> {*this};
1278 }
1279
1280 std::uint64_t length() const noexcept
1281 {
1282 return bt_value_map_get_size(this->libObjPtr());
1283 }
1284
1285 bool isEmpty() const noexcept
1286 {
1287 return this->length() == 0;
1288 }
1289
1290 OptionalBorrowedObject<CommonValue<LibObjT>>
1291 operator[](const bt2c::CStringView key) const noexcept
1292 {
1293 return internal::CommonMapValueSpec<LibObjT>::entryByKey(this->libObjPtr(), key);
1294 }
1295
1296 bool hasEntry(const bt2c::CStringView key) const noexcept
1297 {
1298 return static_cast<bool>(bt_value_map_has_entry(this->libObjPtr(), key));
1299 }
1300
1301 CommonMapValue insert(const bt2c::CStringView key, const Value val) const
1302 {
1303 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1304
1305 const auto status = bt_value_map_insert_entry(this->libObjPtr(), key, val.libObjPtr());
1306
1307 this->_handleInsertLibStatus(status);
1308 return *this;
1309 }
1310
1311 CommonMapValue insert(const bt2c::CStringView key, const bool rawVal) const
1312 {
1313 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1314
1315 const auto status =
1316 bt_value_map_insert_bool_entry(this->libObjPtr(), key, static_cast<bt_bool>(rawVal));
1317
1318 this->_handleInsertLibStatus(status);
1319 return *this;
1320 }
1321
1322 CommonMapValue insert(const bt2c::CStringView key, const std::uint64_t rawVal) const
1323 {
1324 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1325
1326 const auto status =
1327 bt_value_map_insert_unsigned_integer_entry(this->libObjPtr(), key, rawVal);
1328
1329 this->_handleInsertLibStatus(status);
1330 return *this;
1331 }
1332
1333 CommonMapValue insert(const bt2c::CStringView key, const std::int64_t rawVal) const
1334 {
1335 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1336
1337 const auto status =
1338 bt_value_map_insert_signed_integer_entry(this->libObjPtr(), key, rawVal);
1339
1340 this->_handleInsertLibStatus(status);
1341 return *this;
1342 }
1343
1344 CommonMapValue insert(const bt2c::CStringView key, const double rawVal) const
1345 {
1346 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1347
1348 const auto status = bt_value_map_insert_real_entry(this->libObjPtr(), key, rawVal);
1349
1350 this->_handleInsertLibStatus(status);
1351 return *this;
1352 }
1353
1354 CommonMapValue insert(const bt2c::CStringView key, const char *rawVal) const
1355 {
1356 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1357
1358 const auto status = bt_value_map_insert_string_entry(this->libObjPtr(), key, rawVal);
1359
1360 this->_handleInsertLibStatus(status);
1361 return *this;
1362 }
1363
1364 CommonMapValue insert(const bt2c::CStringView key, const bt2c::CStringView rawVal) const
1365 {
1366 return this->insert(key, rawVal.data());
1367 }
1368
1369 CommonArrayValue<bt_value> insertEmptyArray(bt2c::CStringView key) const;
1370 CommonMapValue<bt_value> insertEmptyMap(bt2c::CStringView key) const;
1371
1372 CommonMapValue
1373 forEach(const internal::CommonMapValueForEachUserFunc<CommonValue<LibObjT>>& func) const
1374 {
1375 internal::CommonMapValueSpec<LibObjT>::forEach(this->libObjPtr(), func);
1376 return *this;
1377 }
1378
1379 Shared shared() const noexcept
1380 {
1381 return Shared::createWithRef(*this);
1382 }
1383
1384 private:
1385 void _handleInsertLibStatus(const bt_value_map_insert_entry_status status) const
1386 {
1387 if (status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_MEMORY_ERROR) {
1388 throw MemoryError {};
1389 }
1390 }
1391 };
1392
1393 using MapValue = CommonMapValue<bt_value>;
1394 using ConstMapValue = CommonMapValue<const bt_value>;
1395
1396 namespace internal {
1397
1398 struct MapValueTypeDescr
1399 {
1400 using Const = ConstMapValue;
1401 using NonConst = MapValue;
1402 };
1403
1404 template <>
1405 struct TypeDescr<MapValue> : public MapValueTypeDescr
1406 {
1407 };
1408
1409 template <>
1410 struct TypeDescr<ConstMapValue> : public MapValueTypeDescr
1411 {
1412 };
1413
1414 } /* namespace internal */
1415
1416 template <typename LibObjT>
1417 ArrayValue CommonValue<LibObjT>::appendEmptyArray() const
1418 {
1419 return this->asArray().appendEmptyArray();
1420 }
1421
1422 template <typename LibObjT>
1423 MapValue CommonValue<LibObjT>::appendEmptyMap() const
1424 {
1425 return this->asArray().appendEmptyMap();
1426 }
1427
1428 template <typename LibObjT>
1429 ArrayValue CommonValue<LibObjT>::insertEmptyArray(const bt2c::CStringView key) const
1430 {
1431 return this->asMap().insertEmptyArray(key);
1432 }
1433
1434 template <typename LibObjT>
1435 MapValue CommonValue<LibObjT>::insertEmptyMap(const bt2c::CStringView key) const
1436 {
1437 return this->asMap().insertEmptyMap(key);
1438 }
1439
1440 template <typename LibObjT>
1441 CommonNullValue<LibObjT> CommonValue<LibObjT>::asNull() const noexcept
1442 {
1443 BT_ASSERT_DBG(this->isNull());
1444 return CommonNullValue<LibObjT> {};
1445 }
1446
1447 template <typename LibObjT>
1448 CommonBoolValue<LibObjT> CommonValue<LibObjT>::asBool() const noexcept
1449 {
1450 return CommonBoolValue<LibObjT> {this->libObjPtr()};
1451 }
1452
1453 template <typename LibObjT>
1454 CommonSignedIntegerValue<LibObjT> CommonValue<LibObjT>::asSignedInteger() const noexcept
1455 {
1456 return CommonSignedIntegerValue<LibObjT> {this->libObjPtr()};
1457 }
1458
1459 template <typename LibObjT>
1460 CommonUnsignedIntegerValue<LibObjT> CommonValue<LibObjT>::asUnsignedInteger() const noexcept
1461 {
1462 return CommonUnsignedIntegerValue<LibObjT> {this->libObjPtr()};
1463 }
1464
1465 template <typename LibObjT>
1466 CommonRealValue<LibObjT> CommonValue<LibObjT>::asReal() const noexcept
1467 {
1468 return CommonRealValue<LibObjT> {this->libObjPtr()};
1469 }
1470
1471 template <typename LibObjT>
1472 CommonStringValue<LibObjT> CommonValue<LibObjT>::asString() const noexcept
1473 {
1474 return CommonStringValue<LibObjT> {this->libObjPtr()};
1475 }
1476
1477 template <typename LibObjT>
1478 CommonArrayValue<LibObjT> CommonValue<LibObjT>::asArray() const noexcept
1479 {
1480 return CommonArrayValue<LibObjT> {this->libObjPtr()};
1481 }
1482
1483 template <typename LibObjT>
1484 CommonMapValue<LibObjT> CommonValue<LibObjT>::asMap() const noexcept
1485 {
1486 return CommonMapValue<LibObjT> {this->libObjPtr()};
1487 }
1488
1489 template <typename LibObjT>
1490 ArrayValue CommonArrayValue<LibObjT>::appendEmptyArray() const
1491 {
1492 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1493
1494 bt_value *libElemPtr;
1495 const auto status = bt_value_array_append_empty_array_element(this->libObjPtr(), &libElemPtr);
1496
1497 this->_handleAppendLibStatus(status);
1498 return ArrayValue {libElemPtr};
1499 }
1500
1501 template <typename LibObjT>
1502 MapValue CommonArrayValue<LibObjT>::appendEmptyMap() const
1503 {
1504 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstArrayValue`.");
1505
1506 bt_value *libElemPtr;
1507 const auto status = bt_value_array_append_empty_map_element(this->libObjPtr(), &libElemPtr);
1508
1509 this->_handleAppendLibStatus(status);
1510 return MapValue {libElemPtr};
1511 }
1512
1513 template <typename LibObjT>
1514 ArrayValue CommonMapValue<LibObjT>::insertEmptyArray(const bt2c::CStringView key) const
1515 {
1516 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1517
1518 bt_value *libEntryPtr;
1519 const auto status = bt_value_map_insert_empty_array_entry(this->libObjPtr(), key, &libEntryPtr);
1520
1521 this->_handleInsertLibStatus(status);
1522 return ArrayValue {libEntryPtr};
1523 }
1524
1525 template <typename LibObjT>
1526 MapValue CommonMapValue<LibObjT>::insertEmptyMap(const bt2c::CStringView key) const
1527 {
1528 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstMapValue`.");
1529
1530 bt_value *libEntryPtr;
1531 const auto status = bt_value_map_insert_empty_map_entry(this->libObjPtr(), key, &libEntryPtr);
1532
1533 this->_handleInsertLibStatus(status);
1534 return MapValue {libEntryPtr};
1535 }
1536
1537 inline BoolValue::Shared createValue(const bool rawVal)
1538 {
1539 return BoolValue::create(rawVal);
1540 }
1541
1542 inline UnsignedIntegerValue::Shared createValue(const std::uint64_t rawVal)
1543 {
1544 return UnsignedIntegerValue::create(rawVal);
1545 }
1546
1547 inline SignedIntegerValue::Shared createValue(const std::int64_t rawVal)
1548 {
1549 return SignedIntegerValue::create(rawVal);
1550 }
1551
1552 inline RealValue::Shared createValue(const double rawVal)
1553 {
1554 return RealValue::create(rawVal);
1555 }
1556
1557 inline StringValue::Shared createValue(const char * const rawVal)
1558 {
1559 return StringValue::create(rawVal);
1560 }
1561
1562 inline StringValue::Shared createValue(const bt2c::CStringView rawVal)
1563 {
1564 return StringValue::create(rawVal);
1565 }
1566
1567 } /* namespace bt2 */
1568
1569 #endif /* BABELTRACE_CPP_COMMON_BT2_VALUE_HPP */
This page took 0.062093 seconds and 4 git commands to generate.