Sort includes in C++ files
[babeltrace.git] / src / cpp-common / bt2 / trace-ir.hpp
1 /*
2 * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
9
10 #include <cstdint>
11 #include <type_traits>
12
13 #include <babeltrace2/babeltrace.h>
14
15 #include "cpp-common/optional.hpp"
16 #include "cpp-common/string_view.hpp"
17
18 #include "clock-class.hpp"
19 #include "clock-snapshot.hpp"
20 #include "field-class.hpp"
21 #include "field.hpp"
22 #include "internal/borrowed-obj.hpp"
23 #include "internal/utils.hpp"
24 #include "value.hpp"
25
26 namespace bt2 {
27
28 template <typename LibObjT>
29 class CommonEvent;
30
31 template <typename LibObjT>
32 class CommonPacket;
33
34 template <typename LibObjT>
35 class CommonStream;
36
37 template <typename LibObjT>
38 class CommonTrace;
39
40 template <typename LibObjT>
41 class CommonEventClass;
42
43 template <typename LibObjT>
44 class CommonStreamClass;
45
46 template <typename LibObjT>
47 class CommonTraceClass;
48
49 namespace internal {
50
51 template <typename LibObjT>
52 struct CommonEventSpec;
53
54 /* Functions specific to mutable events */
55 template <>
56 struct CommonEventSpec<bt_event> final
57 {
58 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
59 {
60 return bt_event_borrow_class(libObjPtr);
61 }
62
63 static bt_stream *stream(bt_event * const libObjPtr) noexcept
64 {
65 return bt_event_borrow_stream(libObjPtr);
66 }
67
68 static bt_packet *packet(bt_event * const libObjPtr) noexcept
69 {
70 return bt_event_borrow_packet(libObjPtr);
71 }
72
73 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
74 {
75 return bt_event_borrow_payload_field(libObjPtr);
76 }
77
78 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
79 {
80 return bt_event_borrow_specific_context_field(libObjPtr);
81 }
82
83 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
84 {
85 return bt_event_borrow_common_context_field(libObjPtr);
86 }
87 };
88
89 /* Functions specific to constant events */
90 template <>
91 struct CommonEventSpec<const bt_event> final
92 {
93 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
94 {
95 return bt_event_borrow_class_const(libObjPtr);
96 }
97
98 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
99 {
100 return bt_event_borrow_stream_const(libObjPtr);
101 }
102
103 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
104 {
105 return bt_event_borrow_packet_const(libObjPtr);
106 }
107
108 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
109 {
110 return bt_event_borrow_payload_field_const(libObjPtr);
111 }
112
113 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
114 {
115 return bt_event_borrow_specific_context_field_const(libObjPtr);
116 }
117
118 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
119 {
120 return bt_event_borrow_common_context_field_const(libObjPtr);
121 }
122 };
123
124 } /* namespace internal */
125
126 template <typename LibObjT>
127 class CommonEvent final : public internal::BorrowedObj<LibObjT>
128 {
129 private:
130 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
131 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
132 using _ConstSpec = internal::CommonEventSpec<const bt_event>;
133 using _Spec = internal::CommonEventSpec<LibObjT>;
134
135 using _Packet =
136 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
137 CommonPacket<bt_packet>>::type;
138
139 using _Stream =
140 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
141 CommonStream<bt_stream>>::type;
142
143 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
144 ConstStructureField, StructureField>::type;
145
146 public:
147 using Class = typename std::conditional<std::is_const<LibObjT>::value,
148 CommonEventClass<const bt_event_class>,
149 CommonEventClass<bt_event_class>>::type;
150
151 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
152 {
153 }
154
155 template <typename OtherLibObjT>
156 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObj {event}
157 {
158 }
159
160 template <typename OtherLibObjT>
161 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
162 {
163 _ThisBorrowedObj::operator=(event);
164 return *this;
165 }
166
167 CommonEventClass<const bt_event_class> cls() const noexcept;
168 Class cls() noexcept;
169 CommonStream<const bt_stream> stream() const noexcept;
170 _Stream stream() noexcept;
171 nonstd::optional<CommonPacket<const bt_packet>> packet() const noexcept;
172 nonstd::optional<_Packet> packet() noexcept;
173
174 nonstd::optional<ConstStructureField> payloadField() const noexcept
175 {
176 const auto libObjPtr = _ConstSpec::payloadField(this->libObjPtr());
177
178 if (libObjPtr) {
179 return ConstStructureField {libObjPtr};
180 }
181
182 return nonstd::nullopt;
183 }
184
185 nonstd::optional<_StructureField> payloadField() noexcept
186 {
187 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
188
189 if (libObjPtr) {
190 return _StructureField {libObjPtr};
191 }
192
193 return nonstd::nullopt;
194 }
195
196 nonstd::optional<ConstStructureField> specificContextField() const noexcept
197 {
198 const auto libObjPtr = _ConstSpec::specificContextField(this->libObjPtr());
199
200 if (libObjPtr) {
201 return ConstStructureField {libObjPtr};
202 }
203
204 return nonstd::nullopt;
205 }
206
207 nonstd::optional<_StructureField> specificContextField() noexcept
208 {
209 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
210
211 if (libObjPtr) {
212 return _StructureField {libObjPtr};
213 }
214
215 return nonstd::nullopt;
216 }
217
218 nonstd::optional<ConstStructureField> commonContextField() const noexcept
219 {
220 const auto libObjPtr = _ConstSpec::commonContextField(this->libObjPtr());
221
222 if (libObjPtr) {
223 return ConstStructureField {libObjPtr};
224 }
225
226 return nonstd::nullopt;
227 }
228
229 nonstd::optional<_StructureField> commonContextField() noexcept
230 {
231 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
232
233 if (libObjPtr) {
234 return _StructureField {libObjPtr};
235 }
236
237 return nonstd::nullopt;
238 }
239 };
240
241 using Event = CommonEvent<bt_event>;
242 using ConstEvent = CommonEvent<const bt_event>;
243
244 namespace internal {
245
246 struct EventTypeDescr
247 {
248 using Const = ConstEvent;
249 using NonConst = Event;
250 };
251
252 template <>
253 struct TypeDescr<Event> : public EventTypeDescr
254 {
255 };
256
257 template <>
258 struct TypeDescr<ConstEvent> : public EventTypeDescr
259 {
260 };
261
262 struct PacketRefFuncs final
263 {
264 static void get(const bt_packet * const libObjPtr)
265 {
266 bt_packet_get_ref(libObjPtr);
267 }
268
269 static void put(const bt_packet * const libObjPtr)
270 {
271 bt_packet_put_ref(libObjPtr);
272 }
273 };
274
275 template <typename LibObjT>
276 struct CommonPacketSpec;
277
278 /* Functions specific to mutable packets */
279 template <>
280 struct CommonPacketSpec<bt_packet> final
281 {
282 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
283 {
284 return bt_packet_borrow_stream(libObjPtr);
285 }
286
287 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
288 {
289 return bt_packet_borrow_context_field(libObjPtr);
290 }
291 };
292
293 /* Functions specific to constant packets */
294 template <>
295 struct CommonPacketSpec<const bt_packet> final
296 {
297 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
298 {
299 return bt_packet_borrow_stream_const(libObjPtr);
300 }
301
302 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
303 {
304 return bt_packet_borrow_context_field_const(libObjPtr);
305 }
306 };
307
308 } /* namespace internal */
309
310 template <typename LibObjT>
311 class CommonPacket final : public internal::BorrowedObj<LibObjT>
312 {
313 private:
314 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
315 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
316 using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
317 using _Spec = internal::CommonPacketSpec<LibObjT>;
318 using _ThisCommonPacket = CommonPacket<LibObjT>;
319
320 using _Stream =
321 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
322 CommonStream<bt_stream>>::type;
323
324 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
325 ConstStructureField, StructureField>::type;
326
327 public:
328 using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
329
330 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
331 {
332 }
333
334 template <typename OtherLibObjT>
335 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObj {packet}
336 {
337 }
338
339 template <typename OtherLibObjT>
340 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
341 {
342 _ThisBorrowedObj::operator=(packet);
343 return *this;
344 }
345
346 CommonStream<const bt_stream> stream() const noexcept;
347 _Stream stream() noexcept;
348
349 nonstd::optional<ConstStructureField> contextField() const noexcept
350 {
351 const auto libObjPtr = _ConstSpec::contextField(this->libObjPtr());
352
353 if (libObjPtr) {
354 return ConstStructureField {libObjPtr};
355 }
356
357 return nonstd::nullopt;
358 }
359
360 nonstd::optional<_StructureField> contextField() noexcept
361 {
362 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
363
364 if (libObjPtr) {
365 return _StructureField {libObjPtr};
366 }
367
368 return nonstd::nullopt;
369 }
370
371 Shared shared() const noexcept
372 {
373 return Shared::createWithRef(*this);
374 }
375 };
376
377 using Packet = CommonPacket<bt_packet>;
378 using ConstPacket = CommonPacket<const bt_packet>;
379
380 namespace internal {
381
382 struct PacketTypeDescr
383 {
384 using Const = ConstPacket;
385 using NonConst = Packet;
386 };
387
388 template <>
389 struct TypeDescr<Packet> : public PacketTypeDescr
390 {
391 };
392
393 template <>
394 struct TypeDescr<ConstPacket> : public PacketTypeDescr
395 {
396 };
397
398 } /* namespace internal */
399
400 template <typename LibObjT>
401 nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
402 {
403 const auto libObjPtr = _ConstSpec::packet(this->libObjPtr());
404
405 if (libObjPtr) {
406 return ConstPacket {libObjPtr};
407 }
408
409 return nonstd::nullopt;
410 }
411
412 template <typename LibObjT>
413 nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept
414 {
415 const auto libObjPtr = _Spec::packet(this->libObjPtr());
416
417 if (libObjPtr) {
418 return _Packet {libObjPtr};
419 }
420
421 return nonstd::nullopt;
422 }
423
424 namespace internal {
425
426 struct StreamRefFuncs final
427 {
428 static void get(const bt_stream * const libObjPtr)
429 {
430 bt_stream_get_ref(libObjPtr);
431 }
432
433 static void put(const bt_stream * const libObjPtr)
434 {
435 bt_stream_put_ref(libObjPtr);
436 }
437 };
438
439 template <typename LibObjT>
440 struct CommonStreamSpec;
441
442 /* Functions specific to mutable streams */
443 template <>
444 struct CommonStreamSpec<bt_stream> final
445 {
446 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
447 {
448 return bt_stream_borrow_class(libObjPtr);
449 }
450
451 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
452 {
453 return bt_stream_borrow_trace(libObjPtr);
454 }
455
456 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
457 {
458 return bt_stream_borrow_user_attributes(libObjPtr);
459 }
460 };
461
462 /* Functions specific to constant streams */
463 template <>
464 struct CommonStreamSpec<const bt_stream> final
465 {
466 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
467 {
468 return bt_stream_borrow_class_const(libObjPtr);
469 }
470
471 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
472 {
473 return bt_stream_borrow_trace_const(libObjPtr);
474 }
475
476 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
477 {
478 return bt_stream_borrow_user_attributes_const(libObjPtr);
479 }
480 };
481
482 } /* namespace internal */
483
484 template <typename LibObjT>
485 class CommonStream final : public internal::BorrowedObj<LibObjT>
486 {
487 private:
488 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
489 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
490 using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
491 using _Spec = internal::CommonStreamSpec<LibObjT>;
492 using _ThisCommonStream = CommonStream<LibObjT>;
493
494 using _Trace =
495 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
496 CommonTrace<bt_trace>>::type;
497
498 public:
499 using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
500
501 using Class = typename std::conditional<std::is_const<LibObjT>::value,
502 CommonStreamClass<const bt_stream_class>,
503 CommonStreamClass<bt_stream_class>>::type;
504
505 using UserAttributes =
506 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
507
508 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
509 {
510 }
511
512 template <typename OtherLibObjT>
513 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObj {stream}
514 {
515 }
516
517 template <typename OtherLibObjT>
518 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
519 {
520 _ThisBorrowedObj::operator=(stream);
521 return *this;
522 }
523
524 Packet::Shared createPacket()
525 {
526 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
527
528 const auto libObjPtr = bt_packet_create(this->libObjPtr());
529
530 internal::validateCreatedObjPtr(libObjPtr);
531 return Packet::Shared::createWithoutRef(libObjPtr);
532 }
533
534 CommonStreamClass<const bt_stream_class> cls() const noexcept;
535 Class cls() noexcept;
536 CommonTrace<const bt_trace> trace() const noexcept;
537 _Trace trace() noexcept;
538
539 std::uint64_t id() const noexcept
540 {
541 return bt_stream_get_id(this->libObjPtr());
542 }
543
544 void name(const char * const name)
545 {
546 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
547
548 const auto status = bt_stream_set_name(this->libObjPtr(), name);
549
550 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
551 throw MemoryError {};
552 }
553 }
554
555 void name(const std::string& name)
556 {
557 this->name(name.data());
558 }
559
560 nonstd::optional<bpstd::string_view> name() const noexcept
561 {
562 const auto name = bt_stream_get_name(this->libObjPtr());
563
564 if (name) {
565 return name;
566 }
567
568 return nonstd::nullopt;
569 }
570
571 template <typename LibValT>
572 void userAttributes(const CommonMapValue<LibValT> userAttrs)
573 {
574 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
575
576 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
577 }
578
579 ConstMapValue userAttributes() const noexcept
580 {
581 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
582 }
583
584 UserAttributes userAttributes() noexcept
585 {
586 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
587 }
588
589 Shared shared() const noexcept
590 {
591 return Shared::createWithRef(*this);
592 }
593 };
594
595 using Stream = CommonStream<bt_stream>;
596 using ConstStream = CommonStream<const bt_stream>;
597
598 namespace internal {
599
600 struct StreamTypeDescr
601 {
602 using Const = ConstStream;
603 using NonConst = Stream;
604 };
605
606 template <>
607 struct TypeDescr<Stream> : public StreamTypeDescr
608 {
609 };
610
611 template <>
612 struct TypeDescr<ConstStream> : public StreamTypeDescr
613 {
614 };
615
616 } /* namespace internal */
617
618 template <typename LibObjT>
619 ConstStream CommonEvent<LibObjT>::stream() const noexcept
620 {
621 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
622 }
623
624 template <typename LibObjT>
625 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept
626 {
627 return _Stream {_Spec::stream(this->libObjPtr())};
628 }
629
630 template <typename LibObjT>
631 ConstStream CommonPacket<LibObjT>::stream() const noexcept
632 {
633 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
634 }
635
636 template <typename LibObjT>
637 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept
638 {
639 return _Stream {_Spec::stream(this->libObjPtr())};
640 }
641
642 namespace internal {
643
644 struct TraceRefFuncs final
645 {
646 static void get(const bt_trace * const libObjPtr)
647 {
648 bt_trace_get_ref(libObjPtr);
649 }
650
651 static void put(const bt_trace * const libObjPtr)
652 {
653 bt_trace_put_ref(libObjPtr);
654 }
655 };
656
657 template <typename LibObjT>
658 struct CommonTraceSpec;
659
660 /* Functions specific to mutable traces */
661 template <>
662 struct CommonTraceSpec<bt_trace> final
663 {
664 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
665 {
666 return bt_trace_borrow_class(libObjPtr);
667 }
668
669 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
670 {
671 return bt_trace_borrow_stream_by_index(libObjPtr, index);
672 }
673
674 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
675 {
676 return bt_trace_borrow_stream_by_id(libObjPtr, id);
677 }
678
679 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
680 {
681 return bt_trace_borrow_user_attributes(libObjPtr);
682 }
683 };
684
685 /* Functions specific to constant traces */
686 template <>
687 struct CommonTraceSpec<const bt_trace> final
688 {
689 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
690 {
691 return bt_trace_borrow_class_const(libObjPtr);
692 }
693
694 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
695 const std::uint64_t index) noexcept
696 {
697 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
698 }
699
700 static const bt_stream *streamById(const bt_trace * const libObjPtr,
701 const std::uint64_t id) noexcept
702 {
703 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
704 }
705
706 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
707 {
708 return bt_trace_borrow_user_attributes_const(libObjPtr);
709 }
710 };
711
712 } /* namespace internal */
713
714 template <typename LibObjT>
715 class CommonTrace final : public internal::BorrowedObj<LibObjT>
716 {
717 /* Allow instantiate() to call `trace.libObjPtr()` */
718 friend class CommonStreamClass<bt_stream_class>;
719
720 private:
721 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
722 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
723 using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
724 using _Spec = internal::CommonTraceSpec<LibObjT>;
725 using _ThisCommonTrace = CommonTrace<LibObjT>;
726
727 using _Stream =
728 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
729 CommonStream<bt_stream>>::type;
730
731 public:
732 using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
733
734 using Class = typename std::conditional<std::is_const<LibObjT>::value,
735 CommonTraceClass<const bt_trace_class>,
736 CommonTraceClass<bt_trace_class>>::type;
737
738 using UserAttributes =
739 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
740
741 struct ConstEnvironmentEntry
742 {
743 bpstd::string_view name;
744 ConstValue value;
745 };
746
747 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
748 {
749 }
750
751 template <typename OtherLibObjT>
752 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObj {trace}
753 {
754 }
755
756 template <typename OtherLibObjT>
757 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
758 {
759 _ThisBorrowedObj::operator=(trace);
760 return *this;
761 }
762
763 CommonTraceClass<const bt_trace_class> cls() const noexcept;
764 Class cls() noexcept;
765
766 void name(const char * const name)
767 {
768 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
769
770 const auto status = bt_trace_set_name(this->libObjPtr(), name);
771
772 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
773 throw MemoryError {};
774 }
775 }
776
777 void name(const std::string& name)
778 {
779 this->name(name.data());
780 }
781
782 nonstd::optional<bpstd::string_view> name() const noexcept
783 {
784 const auto name = bt_trace_get_name(this->libObjPtr());
785
786 if (name) {
787 return name;
788 }
789
790 return nonstd::nullopt;
791 }
792
793 void uuid(const bt2_common::UuidView& uuid) noexcept
794 {
795 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
796 }
797
798 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
799 {
800 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
801
802 if (uuid) {
803 return bt2_common::UuidView {uuid};
804 }
805
806 return nonstd::nullopt;
807 }
808
809 std::uint64_t size() const noexcept
810 {
811 return bt_trace_get_stream_count(this->libObjPtr());
812 }
813
814 ConstStream operator[](const std::uint64_t index) const noexcept
815 {
816 return ConstStream {_ConstSpec::streamByIndex(this->libObjPtr(), index)};
817 }
818
819 _Stream operator[](const std::uint64_t index) noexcept
820 {
821 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
822 }
823
824 nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept
825 {
826 const auto libObjPtr = _ConstSpec::streamById(this->libObjPtr(), id);
827
828 if (libObjPtr) {
829 return ConstStream {libObjPtr};
830 }
831
832 return nonstd::nullopt;
833 }
834
835 nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept
836 {
837 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
838
839 if (libObjPtr) {
840 return _Stream {libObjPtr};
841 }
842
843 return nonstd::nullopt;
844 }
845
846 void environmentEntry(const char * const name, const std::int64_t val)
847 {
848 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
849
850 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
851
852 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
853 throw MemoryError {};
854 }
855 }
856
857 void environmentEntry(const std::string& name, const std::int64_t val)
858 {
859 this->environmentEntry(name.data(), val);
860 }
861
862 void environmentEntry(const char * const name, const char * const val)
863 {
864 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
865
866 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
867
868 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
869 throw MemoryError {};
870 }
871 }
872
873 void environmentEntry(const std::string& name, const char * const val)
874 {
875 this->environmentEntry(name.data(), val);
876 }
877
878 void environmentEntry(const char * const name, const std::string& val)
879 {
880 this->environmentEntry(name, val.data());
881 }
882
883 void environmentEntry(const std::string& name, const std::string& val)
884 {
885 this->environmentEntry(name.data(), val.data());
886 }
887
888 std::uint64_t environmentSize() const noexcept
889 {
890 return bt_trace_get_environment_entry_count(this->libObjPtr());
891 }
892
893 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
894 {
895 const char *name;
896 const bt_value *libObjPtr;
897
898 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
899 &libObjPtr);
900 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
901 }
902
903 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
904 {
905 const auto libObjPtr =
906 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
907
908 if (libObjPtr) {
909 return ConstValue {libObjPtr};
910 }
911
912 return nonstd::nullopt;
913 }
914
915 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
916 {
917 return this->environmentEntry(name.data());
918 }
919
920 template <typename LibValT>
921 void userAttributes(const CommonMapValue<LibValT> userAttrs)
922 {
923 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
924
925 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
926 }
927
928 ConstMapValue userAttributes() const noexcept
929 {
930 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
931 }
932
933 UserAttributes userAttributes() noexcept
934 {
935 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
936 }
937
938 Shared shared() const noexcept
939 {
940 return Shared::createWithRef(*this);
941 }
942 };
943
944 using Trace = CommonTrace<bt_trace>;
945 using ConstTrace = CommonTrace<const bt_trace>;
946
947 namespace internal {
948
949 struct TraceTypeDescr
950 {
951 using Const = ConstTrace;
952 using NonConst = Trace;
953 };
954
955 template <>
956 struct TypeDescr<Trace> : public TraceTypeDescr
957 {
958 };
959
960 template <>
961 struct TypeDescr<ConstTrace> : public TraceTypeDescr
962 {
963 };
964
965 } /* namespace internal */
966
967 template <typename LibObjT>
968 ConstTrace CommonStream<LibObjT>::trace() const noexcept
969 {
970 return ConstTrace {_ConstSpec::trace(this->libObjPtr())};
971 }
972
973 template <typename LibObjT>
974 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept
975 {
976 return _Trace {_Spec::trace(this->libObjPtr())};
977 }
978
979 namespace internal {
980
981 struct EventClassRefFuncs final
982 {
983 static void get(const bt_event_class * const libObjPtr)
984 {
985 bt_event_class_get_ref(libObjPtr);
986 }
987
988 static void put(const bt_event_class * const libObjPtr)
989 {
990 bt_event_class_put_ref(libObjPtr);
991 }
992 };
993
994 template <typename LibObjT>
995 struct CommonEventClassSpec;
996
997 /* Functions specific to mutable event classes */
998 template <>
999 struct CommonEventClassSpec<bt_event_class> final
1000 {
1001 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
1002 {
1003 return bt_event_class_borrow_stream_class(libObjPtr);
1004 }
1005
1006 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
1007 {
1008 return bt_event_class_borrow_payload_field_class(libObjPtr);
1009 }
1010
1011 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
1012 {
1013 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
1014 }
1015
1016 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
1017 {
1018 return bt_event_class_borrow_user_attributes(libObjPtr);
1019 }
1020 };
1021
1022 /* Functions specific to constant event classes */
1023 template <>
1024 struct CommonEventClassSpec<const bt_event_class> final
1025 {
1026 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
1027 {
1028 return bt_event_class_borrow_stream_class_const(libObjPtr);
1029 }
1030
1031 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
1032 {
1033 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
1034 }
1035
1036 static const bt_field_class *
1037 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
1038 {
1039 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
1040 }
1041
1042 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
1043 {
1044 return bt_event_class_borrow_user_attributes_const(libObjPtr);
1045 }
1046 };
1047
1048 } /* namespace internal */
1049
1050 template <typename LibObjT>
1051 class CommonEventClass final : public internal::BorrowedObj<LibObjT>
1052 {
1053 private:
1054 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1055 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1056 using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
1057 using _Spec = internal::CommonEventClassSpec<LibObjT>;
1058 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
1059
1060 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1061 CommonStreamClass<const bt_stream_class>,
1062 CommonStreamClass<bt_stream_class>>::type;
1063
1064 using _StructureFieldClass =
1065 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1066 StructureFieldClass>::type;
1067
1068 public:
1069 using Shared =
1070 internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
1071
1072 using UserAttributes =
1073 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1074
1075 enum class LogLevel
1076 {
1077 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
1078 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
1079 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
1080 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
1081 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
1082 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
1083 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
1084 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
1085 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
1086 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
1087 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
1088 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
1089 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
1090 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
1091 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
1092 };
1093
1094 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1095 {
1096 }
1097
1098 template <typename OtherLibObjT>
1099 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
1100 _ThisBorrowedObj {eventClass}
1101 {
1102 }
1103
1104 template <typename OtherLibObjT>
1105 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
1106 {
1107 _ThisBorrowedObj::operator=(eventClass);
1108 return *this;
1109 }
1110
1111 CommonStreamClass<const bt_stream_class> streamClass() const noexcept;
1112 _StreamClass streamClass() noexcept;
1113
1114 std::uint64_t id() const noexcept
1115 {
1116 return bt_event_class_get_id(this->libObjPtr());
1117 }
1118
1119 void name(const char * const name)
1120 {
1121 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1122
1123 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1124
1125 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1126 throw MemoryError {};
1127 }
1128 }
1129
1130 void name(const std::string& name)
1131 {
1132 this->name(name.data());
1133 }
1134
1135 nonstd::optional<bpstd::string_view> name() const noexcept
1136 {
1137 const auto name = bt_event_class_get_name(this->libObjPtr());
1138
1139 if (name) {
1140 return name;
1141 }
1142
1143 return nonstd::nullopt;
1144 }
1145
1146 void logLevel(const LogLevel logLevel) noexcept
1147 {
1148 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1149
1150 bt_event_class_set_log_level(this->libObjPtr(),
1151 static_cast<bt_event_class_log_level>(logLevel));
1152 }
1153
1154 nonstd::optional<LogLevel> logLevel() const noexcept
1155 {
1156 bt_event_class_log_level libLogLevel;
1157 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1158
1159 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1160 return static_cast<LogLevel>(libLogLevel);
1161 }
1162
1163 return nonstd::nullopt;
1164 }
1165
1166 void emfUri(const char * const emfUri)
1167 {
1168 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1169
1170 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1171
1172 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1173 throw MemoryError {};
1174 }
1175 }
1176
1177 void emfUri(const std::string& emfUri)
1178 {
1179 this->emfUri(emfUri.data());
1180 }
1181
1182 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1183 {
1184 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1185
1186 if (emfUri) {
1187 return emfUri;
1188 }
1189
1190 return nonstd::nullopt;
1191 }
1192
1193 void payloadFieldClass(const StructureFieldClass fc)
1194 {
1195 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1196
1197 const auto status =
1198 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1199
1200 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1201 throw MemoryError {};
1202 }
1203 }
1204
1205 nonstd::optional<ConstStructureFieldClass> payloadFieldClass() const noexcept
1206 {
1207 const auto libObjPtr = _ConstSpec::payloadFieldClass(this->libObjPtr());
1208
1209 if (libObjPtr) {
1210 return ConstStructureFieldClass {libObjPtr};
1211 }
1212
1213 return nonstd::nullopt;
1214 }
1215
1216 nonstd::optional<_StructureFieldClass> payloadFieldClass() noexcept
1217 {
1218 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1219
1220 if (libObjPtr) {
1221 return _StructureFieldClass {libObjPtr};
1222 }
1223
1224 return nonstd::nullopt;
1225 }
1226
1227 void specificContextFieldClass(const StructureFieldClass fc)
1228 {
1229 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1230
1231 const auto status =
1232 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1233
1234 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1235 throw MemoryError {};
1236 }
1237 }
1238
1239 nonstd::optional<ConstStructureFieldClass> specificContextFieldClass() const noexcept
1240 {
1241 const auto libObjPtr = _ConstSpec::specificContextFieldClass(this->libObjPtr());
1242
1243 if (libObjPtr) {
1244 return ConstStructureFieldClass {libObjPtr};
1245 }
1246
1247 return nonstd::nullopt;
1248 }
1249
1250 nonstd::optional<_StructureFieldClass> specificContextFieldClass() noexcept
1251 {
1252 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1253
1254 if (libObjPtr) {
1255 return _StructureFieldClass {libObjPtr};
1256 }
1257
1258 return nonstd::nullopt;
1259 }
1260
1261 template <typename LibValT>
1262 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1263 {
1264 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1265
1266 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1267 }
1268
1269 ConstMapValue userAttributes() const noexcept
1270 {
1271 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1272 }
1273
1274 UserAttributes userAttributes() noexcept
1275 {
1276 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1277 }
1278
1279 Shared shared() const noexcept
1280 {
1281 return Shared::createWithRef(*this);
1282 }
1283 };
1284
1285 using EventClass = CommonEventClass<bt_event_class>;
1286 using ConstEventClass = CommonEventClass<const bt_event_class>;
1287
1288 namespace internal {
1289
1290 struct EventClassTypeDescr
1291 {
1292 using Const = ConstEventClass;
1293 using NonConst = EventClass;
1294 };
1295
1296 template <>
1297 struct TypeDescr<EventClass> : public EventClassTypeDescr
1298 {
1299 };
1300
1301 template <>
1302 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1303 {
1304 };
1305
1306 } /* namespace internal */
1307
1308 template <typename LibObjT>
1309 ConstEventClass CommonEvent<LibObjT>::cls() const noexcept
1310 {
1311 return ConstEventClass {_ConstSpec::cls(this->libObjPtr())};
1312 }
1313
1314 template <typename LibObjT>
1315 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() noexcept
1316 {
1317 return Class {_Spec::cls(this->libObjPtr())};
1318 }
1319
1320 namespace internal {
1321
1322 struct StreamClassRefFuncs final
1323 {
1324 static void get(const bt_stream_class * const libObjPtr)
1325 {
1326 bt_stream_class_get_ref(libObjPtr);
1327 }
1328
1329 static void put(const bt_stream_class * const libObjPtr)
1330 {
1331 bt_stream_class_put_ref(libObjPtr);
1332 }
1333 };
1334
1335 template <typename LibObjT>
1336 struct CommonStreamClassSpec;
1337
1338 /* Functions specific to mutable stream classes */
1339 template <>
1340 struct CommonStreamClassSpec<bt_stream_class> final
1341 {
1342 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1343 {
1344 return bt_stream_class_borrow_trace_class(libObjPtr);
1345 }
1346
1347 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1348 const std::uint64_t index) noexcept
1349 {
1350 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1351 }
1352
1353 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1354 const std::uint64_t id) noexcept
1355 {
1356 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1357 }
1358
1359 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1360 {
1361 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1362 }
1363
1364 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1365 {
1366 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1367 }
1368
1369 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1370 {
1371 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1372 }
1373
1374 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1375 {
1376 return bt_stream_class_borrow_user_attributes(libObjPtr);
1377 }
1378 };
1379
1380 /* Functions specific to constant stream classes */
1381 template <>
1382 struct CommonStreamClassSpec<const bt_stream_class> final
1383 {
1384 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1385 {
1386 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1387 }
1388
1389 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1390 const std::uint64_t index) noexcept
1391 {
1392 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1393 }
1394
1395 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1396 const std::uint64_t id) noexcept
1397 {
1398 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1399 }
1400
1401 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1402 {
1403 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1404 }
1405
1406 static const bt_field_class *
1407 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1408 {
1409 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1410 }
1411
1412 static const bt_field_class *
1413 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1414 {
1415 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1416 }
1417
1418 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1419 {
1420 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1421 }
1422 };
1423
1424 } /* namespace internal */
1425
1426 template <typename LibObjT>
1427 class CommonStreamClass final : public internal::BorrowedObj<LibObjT>
1428 {
1429 private:
1430 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1431 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1432 using _ConstSpec = internal::CommonStreamClassSpec<const bt_stream_class>;
1433 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1434 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1435
1436 using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
1437 CommonTraceClass<const bt_trace_class>,
1438 CommonTraceClass<bt_trace_class>>::type;
1439
1440 using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
1441 CommonEventClass<const bt_event_class>,
1442 CommonEventClass<bt_event_class>>::type;
1443
1444 using _StructureFieldClass =
1445 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1446 StructureFieldClass>::type;
1447
1448 using _ClockClass =
1449 typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
1450
1451 public:
1452 using Shared =
1453 internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1454
1455 using UserAttributes =
1456 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1457
1458 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1459 {
1460 }
1461
1462 template <typename OtherLibObjT>
1463 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1464 _ThisBorrowedObj {streamClass}
1465 {
1466 }
1467
1468 template <typename OtherLibObjT>
1469 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1470 {
1471 _ThisBorrowedObj::operator=(streamClass);
1472 return *this;
1473 }
1474
1475 Stream::Shared instantiate(const Trace trace)
1476 {
1477 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1478
1479 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1480
1481 internal::validateCreatedObjPtr(libObjPtr);
1482 return Stream::Shared::createWithoutRef(libObjPtr);
1483 }
1484
1485 Stream::Shared instantiate(const Trace trace, const std::uint64_t id)
1486 {
1487 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1488
1489 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1490
1491 internal::validateCreatedObjPtr(libObjPtr);
1492 return Stream::Shared::createWithoutRef(libObjPtr);
1493 }
1494
1495 EventClass::Shared createEventClass()
1496 {
1497 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1498
1499 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1500
1501 internal::validateCreatedObjPtr(libObjPtr);
1502 return EventClass::Shared::createWithoutRef(libObjPtr);
1503 }
1504
1505 EventClass::Shared createEventClass(const std::uint64_t id)
1506 {
1507 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1508
1509 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1510
1511 internal::validateCreatedObjPtr(libObjPtr);
1512 return EventClass::Shared::createWithoutRef(libObjPtr);
1513 }
1514
1515 CommonTraceClass<const bt_trace_class> traceClass() const noexcept;
1516 _TraceClass traceClass() noexcept;
1517
1518 std::uint64_t id() const noexcept
1519 {
1520 return bt_stream_class_get_id(this->libObjPtr());
1521 }
1522
1523 void name(const char * const name)
1524 {
1525 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1526
1527 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1528
1529 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1530 throw MemoryError {};
1531 }
1532 }
1533
1534 void name(const std::string& name)
1535 {
1536 this->name(name.data());
1537 }
1538
1539 nonstd::optional<bpstd::string_view> name() const noexcept
1540 {
1541 const auto name = bt_stream_class_get_name(this->libObjPtr());
1542
1543 if (name) {
1544 return name;
1545 }
1546
1547 return nonstd::nullopt;
1548 }
1549
1550 void assignsAutomaticEventClassId(const bool val) noexcept
1551 {
1552 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1553
1554 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1555 static_cast<bt_bool>(val));
1556 }
1557
1558 bool assignsAutomaticEventClassId() const noexcept
1559 {
1560 return static_cast<bool>(
1561 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1562 }
1563
1564 void assignsAutomaticStreamId(const bool val) noexcept
1565 {
1566 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1567
1568 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1569 static_cast<bt_bool>(val));
1570 }
1571
1572 bool assignsAutomaticStreamId() const noexcept
1573 {
1574 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1575 }
1576
1577 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1578 const bool withEndDefaultClkSnapshot) noexcept
1579 {
1580 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1581
1582 bt_stream_class_set_supports_packets(this->libObjPtr(),
1583 static_cast<bt_bool>(supportsPackets),
1584 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1585 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1586 }
1587
1588 bool supportsPackets() const noexcept
1589 {
1590 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1591 }
1592
1593 bool packetsHaveBeginningClockSnapshot() const noexcept
1594 {
1595 return static_cast<bool>(
1596 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1597 }
1598
1599 bool packetsHaveEndClockSnapshot() const noexcept
1600 {
1601 return static_cast<bool>(
1602 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1603 }
1604
1605 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1606 const bool withDefaultClkSnapshots) noexcept
1607 {
1608 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1609
1610 bt_stream_class_set_supports_discarded_events(
1611 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1612 static_cast<bt_bool>(withDefaultClkSnapshots));
1613 }
1614
1615 bool supportsDiscardedEvents() const noexcept
1616 {
1617 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1618 }
1619
1620 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1621 {
1622 return static_cast<bool>(
1623 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1624 }
1625
1626 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1627 const bool withDefaultClkSnapshots) noexcept
1628 {
1629 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1630
1631 bt_stream_class_set_supports_discarded_packets(
1632 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1633 static_cast<bt_bool>(withDefaultClkSnapshots));
1634 }
1635
1636 bool supportsDiscardedPackets() const noexcept
1637 {
1638 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1639 }
1640
1641 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1642 {
1643 return static_cast<bool>(
1644 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1645 }
1646
1647 void defaultClockClass(const ClockClass clkCls)
1648 {
1649 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1650
1651 const auto status =
1652 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1653
1654 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1655 }
1656
1657 nonstd::optional<ConstClockClass> defaultClockClass() const noexcept
1658 {
1659 const auto libObjPtr = _ConstSpec::defaultClockClass(this->libObjPtr());
1660
1661 if (libObjPtr) {
1662 return ConstClockClass {libObjPtr};
1663 }
1664
1665 return nonstd::nullopt;
1666 }
1667
1668 nonstd::optional<_ClockClass> defaultClockClass() noexcept
1669 {
1670 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1671
1672 if (libObjPtr) {
1673 return _ClockClass {libObjPtr};
1674 }
1675
1676 return nonstd::nullopt;
1677 }
1678
1679 std::uint64_t size() const noexcept
1680 {
1681 return bt_stream_class_get_event_class_count(this->libObjPtr());
1682 }
1683
1684 ConstEventClass operator[](const std::uint64_t index) const noexcept
1685 {
1686 return ConstEventClass {_ConstSpec::eventClassByIndex(this->libObjPtr(), index)};
1687 }
1688
1689 _EventClass operator[](const std::uint64_t index) noexcept
1690 {
1691 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1692 }
1693
1694 nonstd::optional<ConstEventClass> eventClassById(const std::uint64_t id) const noexcept
1695 {
1696 const auto libObjPtr = _ConstSpec::eventClassById(this->libObjPtr(), id);
1697
1698 if (libObjPtr) {
1699 return ConstEventClass {libObjPtr};
1700 }
1701
1702 return nonstd::nullopt;
1703 }
1704
1705 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) noexcept
1706 {
1707 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1708
1709 if (libObjPtr) {
1710 return _EventClass {libObjPtr};
1711 }
1712
1713 return nonstd::nullopt;
1714 }
1715
1716 void packetContextFieldClass(const StructureFieldClass fc)
1717 {
1718 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1719
1720 const auto status =
1721 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1722
1723 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1724 throw MemoryError {};
1725 }
1726 }
1727
1728 nonstd::optional<ConstStructureFieldClass> packetContextFieldClass() const noexcept
1729 {
1730 const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->libObjPtr());
1731
1732 if (libObjPtr) {
1733 return ConstStructureFieldClass {libObjPtr};
1734 }
1735
1736 return nonstd::nullopt;
1737 }
1738
1739 nonstd::optional<_StructureFieldClass> packetContextFieldClass() noexcept
1740 {
1741 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1742
1743 if (libObjPtr) {
1744 return _StructureFieldClass {libObjPtr};
1745 }
1746
1747 return nonstd::nullopt;
1748 }
1749
1750 void eventCommonContextFieldClass(const StructureFieldClass fc)
1751 {
1752 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1753
1754 const auto status =
1755 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1756
1757 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1758 throw MemoryError {};
1759 }
1760 }
1761
1762 nonstd::optional<ConstStructureFieldClass> eventCommonContextFieldClass() const noexcept
1763 {
1764 const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->libObjPtr());
1765
1766 if (libObjPtr) {
1767 return ConstStructureFieldClass {libObjPtr};
1768 }
1769
1770 return nonstd::nullopt;
1771 }
1772
1773 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() noexcept
1774 {
1775 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1776
1777 if (libObjPtr) {
1778 return _StructureFieldClass {libObjPtr};
1779 }
1780
1781 return nonstd::nullopt;
1782 }
1783
1784 template <typename LibValT>
1785 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1786 {
1787 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1788
1789 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1790 }
1791
1792 ConstMapValue userAttributes() const noexcept
1793 {
1794 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1795 }
1796
1797 UserAttributes userAttributes() noexcept
1798 {
1799 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1800 }
1801
1802 Shared shared() const noexcept
1803 {
1804 return Shared::createWithRef(*this);
1805 }
1806 };
1807
1808 using StreamClass = CommonStreamClass<bt_stream_class>;
1809 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1810
1811 namespace internal {
1812
1813 struct StreamClassTypeDescr
1814 {
1815 using Const = ConstStreamClass;
1816 using NonConst = StreamClass;
1817 };
1818
1819 template <>
1820 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1821 {
1822 };
1823
1824 template <>
1825 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1826 {
1827 };
1828
1829 } /* namespace internal */
1830
1831 template <typename LibObjT>
1832 ConstStreamClass CommonEventClass<LibObjT>::streamClass() const noexcept
1833 {
1834 return ConstStreamClass {_ConstSpec::streamClass(this->libObjPtr())};
1835 }
1836
1837 template <typename LibObjT>
1838 typename CommonEventClass<LibObjT>::_StreamClass CommonEventClass<LibObjT>::streamClass() noexcept
1839 {
1840 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1841 }
1842
1843 template <typename LibObjT>
1844 ConstStreamClass CommonStream<LibObjT>::cls() const noexcept
1845 {
1846 return ConstStreamClass {_ConstSpec::cls(this->libObjPtr())};
1847 }
1848
1849 template <typename LibObjT>
1850 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() noexcept
1851 {
1852 return Class {_Spec::cls(this->libObjPtr())};
1853 }
1854
1855 namespace internal {
1856
1857 struct TraceClassRefFuncs final
1858 {
1859 static void get(const bt_trace_class * const libObjPtr)
1860 {
1861 bt_trace_class_get_ref(libObjPtr);
1862 }
1863
1864 static void put(const bt_trace_class * const libObjPtr)
1865 {
1866 bt_trace_class_put_ref(libObjPtr);
1867 }
1868 };
1869
1870 template <typename LibObjT>
1871 struct CommonTraceClassSpec;
1872
1873 /* Functions specific to mutable stream classes */
1874 template <>
1875 struct CommonTraceClassSpec<bt_trace_class> final
1876 {
1877 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1878 const std::uint64_t index) noexcept
1879 {
1880 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1881 }
1882
1883 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1884 const std::uint64_t id) noexcept
1885 {
1886 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1887 }
1888
1889 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1890 {
1891 return bt_trace_class_borrow_user_attributes(libObjPtr);
1892 }
1893 };
1894
1895 /* Functions specific to constant stream classes */
1896 template <>
1897 struct CommonTraceClassSpec<const bt_trace_class> final
1898 {
1899 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1900 const std::uint64_t index) noexcept
1901 {
1902 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1903 }
1904
1905 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1906 const std::uint64_t id) noexcept
1907 {
1908 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1909 }
1910
1911 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1912 {
1913 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1914 }
1915 };
1916
1917 } /* namespace internal */
1918
1919 template <typename LibObjT>
1920 class CommonTraceClass final : public internal::BorrowedObj<LibObjT>
1921 {
1922 private:
1923 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1924 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1925 using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>;
1926 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1927 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1928
1929 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1930 CommonStreamClass<const bt_stream_class>,
1931 CommonStreamClass<bt_stream_class>>::type;
1932
1933 public:
1934 using Shared =
1935 internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1936
1937 using UserAttributes =
1938 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1939
1940 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1941 {
1942 }
1943
1944 template <typename OtherLibObjT>
1945 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1946 _ThisBorrowedObj {traceClass}
1947 {
1948 }
1949
1950 template <typename OtherLibObjT>
1951 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1952 {
1953 _ThisBorrowedObj::operator=(traceClass);
1954 return *this;
1955 }
1956
1957 Trace::Shared instantiate()
1958 {
1959 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1960
1961 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1962
1963 internal::validateCreatedObjPtr(libObjPtr);
1964 return Trace::Shared::createWithoutRef(libObjPtr);
1965 }
1966
1967 StreamClass::Shared createStreamClass()
1968 {
1969 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1970
1971 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1972
1973 internal::validateCreatedObjPtr(libObjPtr);
1974 return StreamClass::Shared::createWithoutRef(libObjPtr);
1975 }
1976
1977 StreamClass::Shared createStreamClass(const std::uint64_t id)
1978 {
1979 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1980
1981 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1982
1983 internal::validateCreatedObjPtr(libObjPtr);
1984 return StreamClass::Shared::createWithoutRef(libObjPtr);
1985 }
1986
1987 FieldClass::Shared createBoolFieldClass()
1988 {
1989 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1990
1991 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1992
1993 internal::validateCreatedObjPtr(libObjPtr);
1994 return FieldClass::Shared::createWithoutRef(libObjPtr);
1995 }
1996
1997 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length)
1998 {
1999 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2000
2001 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
2002
2003 internal::validateCreatedObjPtr(libObjPtr);
2004 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2005 }
2006
2007 IntegerFieldClass::Shared createUnsignedIntegerFieldClass()
2008 {
2009 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2010
2011 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
2012
2013 internal::validateCreatedObjPtr(libObjPtr);
2014 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2015 }
2016
2017 IntegerFieldClass::Shared createSignedIntegerFieldClass()
2018 {
2019 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2020
2021 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
2022
2023 internal::validateCreatedObjPtr(libObjPtr);
2024 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2025 }
2026
2027 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass()
2028 {
2029 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2030
2031 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
2032
2033 internal::validateCreatedObjPtr(libObjPtr);
2034 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2035 }
2036
2037 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass()
2038 {
2039 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2040
2041 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
2042
2043 internal::validateCreatedObjPtr(libObjPtr);
2044 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2045 }
2046
2047 FieldClass::Shared createSinglePrecisionRealFieldClass()
2048 {
2049 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2050
2051 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
2052
2053 internal::validateCreatedObjPtr(libObjPtr);
2054 return FieldClass::Shared::createWithoutRef(libObjPtr);
2055 }
2056
2057 FieldClass::Shared createDoublePrecisionRealFieldClass()
2058 {
2059 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2060
2061 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
2062
2063 internal::validateCreatedObjPtr(libObjPtr);
2064 return FieldClass::Shared::createWithoutRef(libObjPtr);
2065 }
2066
2067 FieldClass::Shared createStringFieldClass()
2068 {
2069 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2070
2071 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
2072
2073 internal::validateCreatedObjPtr(libObjPtr);
2074 return FieldClass::Shared::createWithoutRef(libObjPtr);
2075 }
2076
2077 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
2078 const std::uint64_t length)
2079 {
2080 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2081
2082 const auto libObjPtr = bt_field_class_array_static_create(
2083 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
2084
2085 internal::validateCreatedObjPtr(libObjPtr);
2086 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2087 }
2088
2089 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass)
2090 {
2091 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2092
2093 const auto libObjPtr = bt_field_class_array_dynamic_create(
2094 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
2095
2096 internal::validateCreatedObjPtr(libObjPtr);
2097 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2098 }
2099
2100 DynamicArrayWithLengthFieldClass::Shared
2101 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
2102 const IntegerFieldClass lengthFieldClass)
2103 {
2104 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2105
2106 const auto libObjPtr = bt_field_class_array_dynamic_create(
2107 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
2108
2109 internal::validateCreatedObjPtr(libObjPtr);
2110 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
2111 }
2112
2113 StructureFieldClass::Shared createStructureFieldClass()
2114 {
2115 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2116
2117 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
2118
2119 internal::validateCreatedObjPtr(libObjPtr);
2120 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
2121 }
2122
2123 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass)
2124 {
2125 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2126
2127 const auto libObjPtr = bt_field_class_option_without_selector_create(
2128 this->libObjPtr(), optionalFieldClass.libObjPtr());
2129
2130 internal::validateCreatedObjPtr(libObjPtr);
2131 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
2132 }
2133
2134 OptionWithBoolSelectorFieldClass::Shared
2135 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
2136 const FieldClass selectorFieldClass)
2137 {
2138 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2139
2140 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
2141 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
2142
2143 internal::validateCreatedObjPtr(libObjPtr);
2144 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2145 }
2146
2147 OptionWithUnsignedIntegerSelectorFieldClass::Shared
2148 createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2149 const IntegerFieldClass selectorFieldClass,
2150 const ConstUnsignedIntegerRangeSet ranges)
2151 {
2152 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2153
2154 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
2155 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2156 ranges.libObjPtr());
2157
2158 internal::validateCreatedObjPtr(libObjPtr);
2159 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2160 }
2161
2162 OptionWithSignedIntegerSelectorFieldClass::Shared
2163 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2164 const IntegerFieldClass selectorFieldClass,
2165 const ConstSignedIntegerRangeSet ranges)
2166 {
2167 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2168
2169 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
2170 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2171 ranges.libObjPtr());
2172
2173 internal::validateCreatedObjPtr(libObjPtr);
2174 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2175 }
2176
2177 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass()
2178 {
2179 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2180
2181 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
2182
2183 internal::validateCreatedObjPtr(libObjPtr);
2184 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2185 }
2186
2187 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2188 createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2189 {
2190 return this->_createVariantWithIntegerSelectorFieldClass<
2191 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
2192 }
2193
2194 VariantWithSignedIntegerSelectorFieldClass::Shared
2195 createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2196 {
2197 return this->_createVariantWithIntegerSelectorFieldClass<
2198 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
2199 }
2200
2201 void assignsAutomaticStreamClassId(const bool val) noexcept
2202 {
2203 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2204
2205 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
2206 static_cast<bt_bool>(val));
2207 }
2208
2209 bool assignsAutomaticStreamClassId() const noexcept
2210 {
2211 return static_cast<bool>(
2212 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2213 }
2214
2215 std::uint64_t size() const noexcept
2216 {
2217 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2218 }
2219
2220 ConstStreamClass operator[](const std::uint64_t index) const noexcept
2221 {
2222 return ConstStreamClass {_ConstSpec::streamClassByIndex(this->libObjPtr(), index)};
2223 }
2224
2225 _StreamClass operator[](const std::uint64_t index) noexcept
2226 {
2227 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2228 }
2229
2230 nonstd::optional<ConstStreamClass> streamClassById(const std::uint64_t id) const noexcept
2231 {
2232 const auto libObjPtr = _ConstSpec::streamClassById(this->libObjPtr(), id);
2233
2234 if (libObjPtr) {
2235 return ConstStreamClass {libObjPtr};
2236 }
2237
2238 return nonstd::nullopt;
2239 }
2240
2241 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) noexcept
2242 {
2243 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2244
2245 if (libObjPtr) {
2246 return _StreamClass {libObjPtr};
2247 }
2248
2249 return nonstd::nullopt;
2250 }
2251
2252 template <typename LibValT>
2253 void userAttributes(const CommonMapValue<LibValT> userAttrs)
2254 {
2255 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2256
2257 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2258 }
2259
2260 ConstMapValue userAttributes() const noexcept
2261 {
2262 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
2263 }
2264
2265 UserAttributes userAttributes() noexcept
2266 {
2267 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2268 }
2269
2270 Shared shared() const noexcept
2271 {
2272 return Shared::createWithRef(*this);
2273 }
2274
2275 private:
2276 template <typename ObjT>
2277 typename ObjT::Shared
2278 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2279 {
2280 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2281
2282 const auto libObjPtr =
2283 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2284
2285 internal::validateCreatedObjPtr(libObjPtr);
2286 return ObjT::Shared::createWithoutRef(libObjPtr);
2287 }
2288 };
2289
2290 using TraceClass = CommonTraceClass<bt_trace_class>;
2291 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2292
2293 namespace internal {
2294
2295 struct TraceClassTypeDescr
2296 {
2297 using Const = ConstTraceClass;
2298 using NonConst = TraceClass;
2299 };
2300
2301 template <>
2302 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2303 {
2304 };
2305
2306 template <>
2307 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2308 {
2309 };
2310
2311 } /* namespace internal */
2312
2313 template <typename LibObjT>
2314 ConstTraceClass CommonStreamClass<LibObjT>::traceClass() const noexcept
2315 {
2316 return ConstTraceClass {_ConstSpec::traceClass(this->libObjPtr())};
2317 }
2318
2319 template <typename LibObjT>
2320 typename CommonStreamClass<LibObjT>::_TraceClass CommonStreamClass<LibObjT>::traceClass() noexcept
2321 {
2322 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2323 }
2324
2325 template <typename LibObjT>
2326 ConstTraceClass CommonTrace<LibObjT>::cls() const noexcept
2327 {
2328 return ConstTraceClass {_ConstSpec::cls(this->libObjPtr())};
2329 }
2330
2331 template <typename LibObjT>
2332 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() noexcept
2333 {
2334 return Class {_Spec::cls(this->libObjPtr())};
2335 }
2336
2337 } /* namespace bt2 */
2338
2339 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */
This page took 0.078727 seconds and 4 git commands to generate.