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