0542cd959c58cb3e70434a17ddd2477e9740df85
[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, "Not available with `bt2::ConstStream`.");
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, "Not available with `bt2::ConstStream`.");
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, "Not available with `bt2::ConstStream`.");
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, "Not available with `bt2::ConstTrace`.");
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, "Not available with `bt2::ConstTrace`.");
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, "Not available with `bt2::ConstTrace`.");
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, "Not available with `bt2::ConstTrace`.");
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, "Not available with `bt2::ConstEventClass`.");
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, "Not available with `bt2::ConstEventClass`.");
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, "Not available with `bt2::ConstEventClass`.");
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, "Not available with `bt2::ConstEventClass`.");
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, "Not available with `bt2::ConstEventClass`.");
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, "Not available with `bt2::ConstEventClass`.");
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,
1358 "Not available with `bt2::ConstStreamClass`.");
1359
1360 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1361
1362 internal::validateCreatedObjPtr(libObjPtr);
1363 return Stream::Shared::createWithoutRef(libObjPtr);
1364 }
1365
1366 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1367 {
1368 static_assert(!std::is_const<LibObjT>::value,
1369 "Not available with `bt2::ConstStreamClass`.");
1370
1371 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1372
1373 internal::validateCreatedObjPtr(libObjPtr);
1374 return Stream::Shared::createWithoutRef(libObjPtr);
1375 }
1376
1377 EventClass::Shared createEventClass() const
1378 {
1379 static_assert(!std::is_const<LibObjT>::value,
1380 "Not available with `bt2::ConstStreamClass`.");
1381
1382 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1383
1384 internal::validateCreatedObjPtr(libObjPtr);
1385 return EventClass::Shared::createWithoutRef(libObjPtr);
1386 }
1387
1388 EventClass::Shared createEventClass(const std::uint64_t id) const
1389 {
1390 static_assert(!std::is_const<LibObjT>::value,
1391 "Not available with `bt2::ConstStreamClass`.");
1392
1393 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1394
1395 internal::validateCreatedObjPtr(libObjPtr);
1396 return EventClass::Shared::createWithoutRef(libObjPtr);
1397 }
1398
1399 _TraceClass traceClass() const noexcept;
1400
1401 std::uint64_t id() const noexcept
1402 {
1403 return bt_stream_class_get_id(this->libObjPtr());
1404 }
1405
1406 void name(const char * const name) const
1407 {
1408 static_assert(!std::is_const<LibObjT>::value,
1409 "Not available with `bt2::ConstStreamClass`.");
1410
1411 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1412
1413 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1414 throw MemoryError {};
1415 }
1416 }
1417
1418 void name(const std::string& name) const
1419 {
1420 this->name(name.data());
1421 }
1422
1423 nonstd::optional<bpstd::string_view> name() const noexcept
1424 {
1425 const auto name = bt_stream_class_get_name(this->libObjPtr());
1426
1427 if (name) {
1428 return name;
1429 }
1430
1431 return nonstd::nullopt;
1432 }
1433
1434 void assignsAutomaticEventClassId(const bool val) const noexcept
1435 {
1436 static_assert(!std::is_const<LibObjT>::value,
1437 "Not available with `bt2::ConstStreamClass`.");
1438
1439 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1440 static_cast<bt_bool>(val));
1441 }
1442
1443 bool assignsAutomaticEventClassId() const noexcept
1444 {
1445 return static_cast<bool>(
1446 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1447 }
1448
1449 void assignsAutomaticStreamId(const bool val) const noexcept
1450 {
1451 static_assert(!std::is_const<LibObjT>::value,
1452 "Not available with `bt2::ConstStreamClass`.");
1453
1454 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1455 static_cast<bt_bool>(val));
1456 }
1457
1458 bool assignsAutomaticStreamId() const noexcept
1459 {
1460 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1461 }
1462
1463 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1464 const bool withEndDefaultClkSnapshot) const noexcept
1465 {
1466 static_assert(!std::is_const<LibObjT>::value,
1467 "Not available with `bt2::ConstStreamClass`.");
1468
1469 bt_stream_class_set_supports_packets(this->libObjPtr(),
1470 static_cast<bt_bool>(supportsPackets),
1471 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1472 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1473 }
1474
1475 bool supportsPackets() const noexcept
1476 {
1477 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1478 }
1479
1480 bool packetsHaveBeginningClockSnapshot() const noexcept
1481 {
1482 return static_cast<bool>(
1483 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1484 }
1485
1486 bool packetsHaveEndClockSnapshot() const noexcept
1487 {
1488 return static_cast<bool>(
1489 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1490 }
1491
1492 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1493 const bool withDefaultClkSnapshots) const noexcept
1494 {
1495 static_assert(!std::is_const<LibObjT>::value,
1496 "Not available with `bt2::ConstStreamClass`.");
1497
1498 bt_stream_class_set_supports_discarded_events(
1499 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1500 static_cast<bt_bool>(withDefaultClkSnapshots));
1501 }
1502
1503 bool supportsDiscardedEvents() const noexcept
1504 {
1505 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1506 }
1507
1508 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1509 {
1510 return static_cast<bool>(
1511 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1512 }
1513
1514 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1515 const bool withDefaultClkSnapshots) const noexcept
1516 {
1517 static_assert(!std::is_const<LibObjT>::value,
1518 "Not available with `bt2::ConstStreamClass`.");
1519
1520 bt_stream_class_set_supports_discarded_packets(
1521 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1522 static_cast<bt_bool>(withDefaultClkSnapshots));
1523 }
1524
1525 bool supportsDiscardedPackets() const noexcept
1526 {
1527 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1528 }
1529
1530 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1531 {
1532 return static_cast<bool>(
1533 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1534 }
1535
1536 void defaultClockClass(const ClockClass clkCls) const
1537 {
1538 static_assert(!std::is_const<LibObjT>::value,
1539 "Not available with `bt2::ConstStreamClass`.");
1540
1541 const auto status =
1542 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1543
1544 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1545 }
1546
1547 nonstd::optional<_ClockClass> defaultClockClass() const noexcept
1548 {
1549 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1550
1551 if (libObjPtr) {
1552 return _ClockClass {libObjPtr};
1553 }
1554
1555 return nonstd::nullopt;
1556 }
1557
1558 std::uint64_t length() const noexcept
1559 {
1560 return bt_stream_class_get_event_class_count(this->libObjPtr());
1561 }
1562
1563 _EventClass operator[](const std::uint64_t index) const noexcept
1564 {
1565 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1566 }
1567
1568 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1569 {
1570 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1571
1572 if (libObjPtr) {
1573 return _EventClass {libObjPtr};
1574 }
1575
1576 return nonstd::nullopt;
1577 }
1578
1579 void packetContextFieldClass(const StructureFieldClass fc) const
1580 {
1581 static_assert(!std::is_const<LibObjT>::value,
1582 "Not available with `bt2::ConstStreamClass`.");
1583
1584 const auto status =
1585 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1586
1587 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1588 throw MemoryError {};
1589 }
1590 }
1591
1592 nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
1593 {
1594 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1595
1596 if (libObjPtr) {
1597 return _StructureFieldClass {libObjPtr};
1598 }
1599
1600 return nonstd::nullopt;
1601 }
1602
1603 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1604 {
1605 static_assert(!std::is_const<LibObjT>::value,
1606 "Not available with `bt2::ConstStreamClass`.");
1607
1608 const auto status =
1609 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1610
1611 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1612 throw MemoryError {};
1613 }
1614 }
1615
1616 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1617 {
1618 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1619
1620 if (libObjPtr) {
1621 return _StructureFieldClass {libObjPtr};
1622 }
1623
1624 return nonstd::nullopt;
1625 }
1626
1627 template <typename LibValT>
1628 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1629 {
1630 static_assert(!std::is_const<LibObjT>::value,
1631 "Not available with `bt2::ConstStreamClass`.");
1632
1633 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1634 }
1635
1636 UserAttributes userAttributes() const noexcept
1637 {
1638 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1639 }
1640
1641 Shared shared() const noexcept
1642 {
1643 return Shared::createWithRef(*this);
1644 }
1645 };
1646
1647 using StreamClass = CommonStreamClass<bt_stream_class>;
1648 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1649
1650 namespace internal {
1651
1652 struct StreamClassTypeDescr
1653 {
1654 using Const = ConstStreamClass;
1655 using NonConst = StreamClass;
1656 };
1657
1658 template <>
1659 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1660 {
1661 };
1662
1663 template <>
1664 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1665 {
1666 };
1667
1668 } /* namespace internal */
1669
1670 template <typename LibObjT>
1671 typename CommonEventClass<LibObjT>::_StreamClass
1672 CommonEventClass<LibObjT>::streamClass() const noexcept
1673 {
1674 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1675 }
1676
1677 template <typename LibObjT>
1678 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1679 {
1680 return Class {_Spec::cls(this->libObjPtr())};
1681 }
1682
1683 namespace internal {
1684
1685 struct TraceClassRefFuncs final
1686 {
1687 static void get(const bt_trace_class * const libObjPtr) noexcept
1688 {
1689 bt_trace_class_get_ref(libObjPtr);
1690 }
1691
1692 static void put(const bt_trace_class * const libObjPtr) noexcept
1693 {
1694 bt_trace_class_put_ref(libObjPtr);
1695 }
1696 };
1697
1698 template <typename LibObjT>
1699 struct CommonTraceClassSpec;
1700
1701 /* Functions specific to mutable stream classes */
1702 template <>
1703 struct CommonTraceClassSpec<bt_trace_class> final
1704 {
1705 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1706 const std::uint64_t index) noexcept
1707 {
1708 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1709 }
1710
1711 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1712 const std::uint64_t id) noexcept
1713 {
1714 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1715 }
1716
1717 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1718 {
1719 return bt_trace_class_borrow_user_attributes(libObjPtr);
1720 }
1721 };
1722
1723 /* Functions specific to constant stream classes */
1724 template <>
1725 struct CommonTraceClassSpec<const bt_trace_class> final
1726 {
1727 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1728 const std::uint64_t index) noexcept
1729 {
1730 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1731 }
1732
1733 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1734 const std::uint64_t id) noexcept
1735 {
1736 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1737 }
1738
1739 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1740 {
1741 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1742 }
1743 };
1744
1745 } /* namespace internal */
1746
1747 template <typename LibObjT>
1748 class CommonTraceClass final : public BorrowedObject<LibObjT>
1749 {
1750 private:
1751 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1752 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1753 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1754 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1755
1756 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1757 CommonStreamClass<const bt_stream_class>,
1758 CommonStreamClass<bt_stream_class>>::type;
1759
1760 public:
1761 using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1762
1763 using UserAttributes =
1764 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1765
1766 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1767 {
1768 }
1769
1770 template <typename OtherLibObjT>
1771 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1772 _ThisBorrowedObject {traceClass}
1773 {
1774 }
1775
1776 template <typename OtherLibObjT>
1777 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1778 {
1779 _ThisBorrowedObject::operator=(traceClass);
1780 return *this;
1781 }
1782
1783 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1784 {
1785 return CommonTraceClass<const bt_trace_class> {*this};
1786 }
1787
1788 Trace::Shared instantiate() const
1789 {
1790 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1791
1792 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1793
1794 internal::validateCreatedObjPtr(libObjPtr);
1795 return Trace::Shared::createWithoutRef(libObjPtr);
1796 }
1797
1798 StreamClass::Shared createStreamClass() const
1799 {
1800 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1801
1802 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1803
1804 internal::validateCreatedObjPtr(libObjPtr);
1805 return StreamClass::Shared::createWithoutRef(libObjPtr);
1806 }
1807
1808 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1809 {
1810 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1811
1812 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1813
1814 internal::validateCreatedObjPtr(libObjPtr);
1815 return StreamClass::Shared::createWithoutRef(libObjPtr);
1816 }
1817
1818 FieldClass::Shared createBoolFieldClass() const
1819 {
1820 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1821
1822 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1823
1824 internal::validateCreatedObjPtr(libObjPtr);
1825 return FieldClass::Shared::createWithoutRef(libObjPtr);
1826 }
1827
1828 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1829 {
1830 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1831
1832 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1833
1834 internal::validateCreatedObjPtr(libObjPtr);
1835 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1836 }
1837
1838 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1839 {
1840 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1841
1842 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1843
1844 internal::validateCreatedObjPtr(libObjPtr);
1845 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1846 }
1847
1848 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1849 {
1850 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1851
1852 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1853
1854 internal::validateCreatedObjPtr(libObjPtr);
1855 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1856 }
1857
1858 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1859 {
1860 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1861
1862 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1863
1864 internal::validateCreatedObjPtr(libObjPtr);
1865 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1866 }
1867
1868 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1869 {
1870 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1871
1872 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1873
1874 internal::validateCreatedObjPtr(libObjPtr);
1875 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1876 }
1877
1878 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1879 {
1880 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1881
1882 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1883
1884 internal::validateCreatedObjPtr(libObjPtr);
1885 return FieldClass::Shared::createWithoutRef(libObjPtr);
1886 }
1887
1888 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1889 {
1890 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1891
1892 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1893
1894 internal::validateCreatedObjPtr(libObjPtr);
1895 return FieldClass::Shared::createWithoutRef(libObjPtr);
1896 }
1897
1898 FieldClass::Shared createStringFieldClass() const
1899 {
1900 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1901
1902 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1903
1904 internal::validateCreatedObjPtr(libObjPtr);
1905 return FieldClass::Shared::createWithoutRef(libObjPtr);
1906 }
1907
1908 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1909 const std::uint64_t length) const
1910 {
1911 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1912
1913 const auto libObjPtr = bt_field_class_array_static_create(
1914 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1915
1916 internal::validateCreatedObjPtr(libObjPtr);
1917 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1918 }
1919
1920 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1921 {
1922 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1923
1924 const auto libObjPtr = bt_field_class_array_dynamic_create(
1925 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1926
1927 internal::validateCreatedObjPtr(libObjPtr);
1928 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1929 }
1930
1931 DynamicArrayWithLengthFieldClass::Shared
1932 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1933 const IntegerFieldClass lengthFieldClass) const
1934 {
1935 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1936
1937 const auto libObjPtr = bt_field_class_array_dynamic_create(
1938 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1939
1940 internal::validateCreatedObjPtr(libObjPtr);
1941 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1942 }
1943
1944 StructureFieldClass::Shared createStructureFieldClass() const
1945 {
1946 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1947
1948 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1949
1950 internal::validateCreatedObjPtr(libObjPtr);
1951 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1952 }
1953
1954 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1955 {
1956 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1957
1958 const auto libObjPtr = bt_field_class_option_without_selector_create(
1959 this->libObjPtr(), optionalFieldClass.libObjPtr());
1960
1961 internal::validateCreatedObjPtr(libObjPtr);
1962 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1963 }
1964
1965 OptionWithBoolSelectorFieldClass::Shared
1966 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1967 const FieldClass selectorFieldClass) const
1968 {
1969 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1970
1971 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1972 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1973
1974 internal::validateCreatedObjPtr(libObjPtr);
1975 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1976 }
1977
1978 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1979 createOptionWithUnsignedIntegerSelectorFieldClass(
1980 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1981 const ConstUnsignedIntegerRangeSet ranges) const
1982 {
1983 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1984
1985 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1986 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1987 ranges.libObjPtr());
1988
1989 internal::validateCreatedObjPtr(libObjPtr);
1990 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1991 }
1992
1993 OptionWithSignedIntegerSelectorFieldClass::Shared
1994 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1995 const IntegerFieldClass selectorFieldClass,
1996 const ConstSignedIntegerRangeSet ranges) const
1997 {
1998 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1999
2000 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
2001 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2002 ranges.libObjPtr());
2003
2004 internal::validateCreatedObjPtr(libObjPtr);
2005 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2006 }
2007
2008 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
2009 {
2010 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2011
2012 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
2013
2014 internal::validateCreatedObjPtr(libObjPtr);
2015 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2016 }
2017
2018 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2019 createVariantWithUnsignedIntegerSelectorFieldClass(
2020 const IntegerFieldClass selectorFieldClass) const
2021 {
2022 return this->_createVariantWithIntegerSelectorFieldClass<
2023 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
2024 }
2025
2026 VariantWithSignedIntegerSelectorFieldClass::Shared
2027 createVariantWithSignedIntegerSelectorFieldClass(
2028 const IntegerFieldClass selectorFieldClass) const
2029 {
2030 return this->_createVariantWithIntegerSelectorFieldClass<
2031 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
2032 }
2033
2034 void assignsAutomaticStreamClassId(const bool val) const noexcept
2035 {
2036 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2037
2038 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
2039 static_cast<bt_bool>(val));
2040 }
2041
2042 bool assignsAutomaticStreamClassId() const noexcept
2043 {
2044 return static_cast<bool>(
2045 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2046 }
2047
2048 std::uint64_t length() const noexcept
2049 {
2050 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2051 }
2052
2053 _StreamClass operator[](const std::uint64_t index) const noexcept
2054 {
2055 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2056 }
2057
2058 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
2059 {
2060 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2061
2062 if (libObjPtr) {
2063 return _StreamClass {libObjPtr};
2064 }
2065
2066 return nonstd::nullopt;
2067 }
2068
2069 template <typename LibValT>
2070 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
2071 {
2072 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2073
2074 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2075 }
2076
2077 UserAttributes userAttributes() const noexcept
2078 {
2079 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2080 }
2081
2082 Shared shared() const noexcept
2083 {
2084 return Shared::createWithRef(*this);
2085 }
2086
2087 private:
2088 template <typename ObjT>
2089 typename ObjT::Shared
2090 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
2091 {
2092 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2093
2094 const auto libObjPtr =
2095 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2096
2097 internal::validateCreatedObjPtr(libObjPtr);
2098 return ObjT::Shared::createWithoutRef(libObjPtr);
2099 }
2100 };
2101
2102 using TraceClass = CommonTraceClass<bt_trace_class>;
2103 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2104
2105 namespace internal {
2106
2107 struct TraceClassTypeDescr
2108 {
2109 using Const = ConstTraceClass;
2110 using NonConst = TraceClass;
2111 };
2112
2113 template <>
2114 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2115 {
2116 };
2117
2118 template <>
2119 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2120 {
2121 };
2122
2123 } /* namespace internal */
2124
2125 template <typename LibObjT>
2126 typename CommonStreamClass<LibObjT>::_TraceClass
2127 CommonStreamClass<LibObjT>::traceClass() const noexcept
2128 {
2129 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2130 }
2131
2132 template <typename LibObjT>
2133 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
2134 {
2135 return Class {_Spec::cls(this->libObjPtr())};
2136 }
2137
2138 } /* namespace bt2 */
2139
2140 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */
This page took 0.103522 seconds and 4 git commands to generate.