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