cpp-common/bt2: use bt2c::CStringView in parameters and return values throughout
[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 void 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
459 bt2c::CStringView name() const noexcept
460 {
461 return bt_stream_get_name(this->libObjPtr());
462 }
463
464 template <typename LibValT>
465 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
466 {
467 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
468
469 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
470 }
471
472 UserAttributes userAttributes() const noexcept
473 {
474 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
475 }
476
477 Shared shared() const noexcept
478 {
479 return Shared::createWithRef(*this);
480 }
481 };
482
483 using Stream = CommonStream<bt_stream>;
484 using ConstStream = CommonStream<const bt_stream>;
485
486 namespace internal {
487
488 struct StreamTypeDescr
489 {
490 using Const = ConstStream;
491 using NonConst = Stream;
492 };
493
494 template <>
495 struct TypeDescr<Stream> : public StreamTypeDescr
496 {
497 };
498
499 template <>
500 struct TypeDescr<ConstStream> : public StreamTypeDescr
501 {
502 };
503
504 } /* namespace internal */
505
506 template <typename LibObjT>
507 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
508 {
509 return _Stream {_Spec::stream(this->libObjPtr())};
510 }
511
512 template <typename LibObjT>
513 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
514 {
515 return _Stream {_Spec::stream(this->libObjPtr())};
516 }
517
518 namespace internal {
519
520 struct TraceRefFuncs final
521 {
522 static void get(const bt_trace * const libObjPtr) noexcept
523 {
524 bt_trace_get_ref(libObjPtr);
525 }
526
527 static void put(const bt_trace * const libObjPtr) noexcept
528 {
529 bt_trace_put_ref(libObjPtr);
530 }
531 };
532
533 template <typename LibObjT>
534 struct CommonTraceSpec;
535
536 /* Functions specific to mutable traces */
537 template <>
538 struct CommonTraceSpec<bt_trace> final
539 {
540 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
541 {
542 return bt_trace_borrow_class(libObjPtr);
543 }
544
545 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
546 {
547 return bt_trace_borrow_stream_by_index(libObjPtr, index);
548 }
549
550 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
551 {
552 return bt_trace_borrow_stream_by_id(libObjPtr, id);
553 }
554
555 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
556 {
557 return bt_trace_borrow_user_attributes(libObjPtr);
558 }
559 };
560
561 /* Functions specific to constant traces */
562 template <>
563 struct CommonTraceSpec<const bt_trace> final
564 {
565 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
566 {
567 return bt_trace_borrow_class_const(libObjPtr);
568 }
569
570 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
571 const std::uint64_t index) noexcept
572 {
573 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
574 }
575
576 static const bt_stream *streamById(const bt_trace * const libObjPtr,
577 const std::uint64_t id) noexcept
578 {
579 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
580 }
581
582 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
583 {
584 return bt_trace_borrow_user_attributes_const(libObjPtr);
585 }
586 };
587
588 } /* namespace internal */
589
590 template <typename LibObjT>
591 class CommonTrace final : public BorrowedObject<LibObjT>
592 {
593 private:
594 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
595 using _Spec = internal::CommonTraceSpec<LibObjT>;
596 using _Stream = internal::DepStream<LibObjT>;
597
598 public:
599 using typename BorrowedObject<LibObjT>::LibObjPtr;
600 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
601 using UserAttributes = internal::DepUserAttrs<LibObjT>;
602
603 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
604 CommonTraceClass<const bt_trace_class>>;
605
606 struct ConstEnvironmentEntry
607 {
608 bt2c::CStringView name;
609 ConstValue value;
610 };
611
612 explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
613 {
614 }
615
616 template <typename OtherLibObjT>
617 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
618 {
619 }
620
621 template <typename OtherLibObjT>
622 CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
623 {
624 _ThisBorrowedObject::operator=(trace);
625 return *this;
626 }
627
628 CommonTrace<const bt_trace> asConst() const noexcept
629 {
630 return CommonTrace<const bt_trace> {*this};
631 }
632
633 Class cls() const noexcept;
634
635 void name(const bt2c::CStringView name) const
636 {
637 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
638
639 const auto status = bt_trace_set_name(this->libObjPtr(), name);
640
641 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
642 throw MemoryError {};
643 }
644 }
645
646 bt2c::CStringView name() const noexcept
647 {
648 return bt_trace_get_name(this->libObjPtr());
649 }
650
651 void uuid(const bt2c::UuidView& uuid) const noexcept
652 {
653 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
654 }
655
656 bt2s::optional<bt2c::UuidView> uuid() const noexcept
657 {
658 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
659
660 if (uuid) {
661 return bt2c::UuidView {uuid};
662 }
663
664 return bt2s::nullopt;
665 }
666
667 std::uint64_t length() const noexcept
668 {
669 return bt_trace_get_stream_count(this->libObjPtr());
670 }
671
672 _Stream operator[](const std::uint64_t index) const noexcept
673 {
674 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
675 }
676
677 OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
678 {
679 return _Spec::streamById(this->libObjPtr(), id);
680 }
681
682 void environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
683 {
684 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
685
686 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
687
688 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
689 throw MemoryError {};
690 }
691 }
692
693 void environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
694 {
695 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
696
697 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
698
699 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
700 throw MemoryError {};
701 }
702 }
703
704 std::uint64_t environmentSize() const noexcept
705 {
706 return bt_trace_get_environment_entry_count(this->libObjPtr());
707 }
708
709 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
710 {
711 const char *name;
712 const bt_value *libObjPtr;
713
714 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
715 &libObjPtr);
716 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
717 }
718
719 OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
720 {
721 return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
722 }
723
724 template <typename LibValT>
725 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
726 {
727 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
728
729 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
730 }
731
732 UserAttributes userAttributes() const noexcept
733 {
734 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
735 }
736
737 Shared shared() const noexcept
738 {
739 return Shared::createWithRef(*this);
740 }
741 };
742
743 using Trace = CommonTrace<bt_trace>;
744 using ConstTrace = CommonTrace<const bt_trace>;
745
746 namespace internal {
747
748 struct TraceTypeDescr
749 {
750 using Const = ConstTrace;
751 using NonConst = Trace;
752 };
753
754 template <>
755 struct TypeDescr<Trace> : public TraceTypeDescr
756 {
757 };
758
759 template <>
760 struct TypeDescr<ConstTrace> : public TraceTypeDescr
761 {
762 };
763
764 } /* namespace internal */
765
766 template <typename LibObjT>
767 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
768 {
769 return _Trace {_Spec::trace(this->libObjPtr())};
770 }
771
772 namespace internal {
773
774 struct EventClassRefFuncs final
775 {
776 static void get(const bt_event_class * const libObjPtr) noexcept
777 {
778 bt_event_class_get_ref(libObjPtr);
779 }
780
781 static void put(const bt_event_class * const libObjPtr) noexcept
782 {
783 bt_event_class_put_ref(libObjPtr);
784 }
785 };
786
787 template <typename LibObjT>
788 struct CommonEventClassSpec;
789
790 /* Functions specific to mutable event classes */
791 template <>
792 struct CommonEventClassSpec<bt_event_class> final
793 {
794 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
795 {
796 return bt_event_class_borrow_stream_class(libObjPtr);
797 }
798
799 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
800 {
801 return bt_event_class_borrow_payload_field_class(libObjPtr);
802 }
803
804 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
805 {
806 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
807 }
808
809 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
810 {
811 return bt_event_class_borrow_user_attributes(libObjPtr);
812 }
813 };
814
815 /* Functions specific to constant event classes */
816 template <>
817 struct CommonEventClassSpec<const bt_event_class> final
818 {
819 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
820 {
821 return bt_event_class_borrow_stream_class_const(libObjPtr);
822 }
823
824 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
825 {
826 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
827 }
828
829 static const bt_field_class *
830 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
831 {
832 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
833 }
834
835 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
836 {
837 return bt_event_class_borrow_user_attributes_const(libObjPtr);
838 }
839 };
840
841 template <typename LibObjT>
842 using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
843
844 } /* namespace internal */
845
846 template <typename LibObjT>
847 class CommonEventClass final : public BorrowedObject<LibObjT>
848 {
849 private:
850 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
851 using _Spec = internal::CommonEventClassSpec<LibObjT>;
852 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
853
854 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
855 CommonStreamClass<const bt_stream_class>>;
856
857 public:
858 using typename BorrowedObject<LibObjT>::LibObjPtr;
859 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
860 using UserAttributes = internal::DepUserAttrs<LibObjT>;
861
862 enum class LogLevel
863 {
864 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
865 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
866 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
867 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
868 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
869 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
870 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
871 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
872 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
873 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
874 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
875 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
876 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
877 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
878 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
879 };
880
881 explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
882 {
883 }
884
885 template <typename OtherLibObjT>
886 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
887 _ThisBorrowedObject {eventClass}
888 {
889 }
890
891 template <typename OtherLibObjT>
892 CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
893 {
894 _ThisBorrowedObject::operator=(eventClass);
895 return *this;
896 }
897
898 CommonEventClass<const bt_event_class> asConst() const noexcept
899 {
900 return CommonEventClass<const bt_event_class> {*this};
901 }
902
903 _StreamClass streamClass() const noexcept;
904
905 std::uint64_t id() const noexcept
906 {
907 return bt_event_class_get_id(this->libObjPtr());
908 }
909
910 void name(const bt2c::CStringView name) const
911 {
912 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
913
914 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
915
916 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
917 throw MemoryError {};
918 }
919 }
920
921 bt2c::CStringView name() const noexcept
922 {
923 return bt_event_class_get_name(this->libObjPtr());
924 }
925
926 void logLevel(const LogLevel logLevel) const noexcept
927 {
928 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
929
930 bt_event_class_set_log_level(this->libObjPtr(),
931 static_cast<bt_event_class_log_level>(logLevel));
932 }
933
934 bt2s::optional<LogLevel> logLevel() const noexcept
935 {
936 bt_event_class_log_level libLogLevel;
937
938 if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
939 return static_cast<LogLevel>(libLogLevel);
940 }
941
942 return bt2s::nullopt;
943 }
944
945 void emfUri(const bt2c::CStringView emfUri) const
946 {
947 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
948
949 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
950
951 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
952 throw MemoryError {};
953 }
954 }
955
956 bt2c::CStringView emfUri() const noexcept
957 {
958 return bt_event_class_get_emf_uri(this->libObjPtr());
959 }
960
961 void payloadFieldClass(const StructureFieldClass fc) const
962 {
963 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
964
965 const auto status =
966 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
967
968 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
969 throw MemoryError {};
970 }
971 }
972
973 OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
974 {
975 return _Spec::payloadFieldClass(this->libObjPtr());
976 }
977
978 void specificContextFieldClass(const StructureFieldClass fc) const
979 {
980 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
981
982 const auto status =
983 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
984
985 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
986 throw MemoryError {};
987 }
988 }
989
990 OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
991 {
992 return _Spec::specificContextFieldClass(this->libObjPtr());
993 }
994
995 template <typename LibValT>
996 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
997 {
998 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
999
1000 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1001 }
1002
1003 UserAttributes userAttributes() const noexcept
1004 {
1005 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1006 }
1007
1008 Shared shared() const noexcept
1009 {
1010 return Shared::createWithRef(*this);
1011 }
1012 };
1013
1014 using EventClass = CommonEventClass<bt_event_class>;
1015 using ConstEventClass = CommonEventClass<const bt_event_class>;
1016
1017 namespace internal {
1018
1019 struct EventClassTypeDescr
1020 {
1021 using Const = ConstEventClass;
1022 using NonConst = EventClass;
1023 };
1024
1025 template <>
1026 struct TypeDescr<EventClass> : public EventClassTypeDescr
1027 {
1028 };
1029
1030 template <>
1031 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1032 {
1033 };
1034
1035 } /* namespace internal */
1036
1037 template <typename LibObjT>
1038 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1039 {
1040 return Class {_Spec::cls(this->libObjPtr())};
1041 }
1042
1043 namespace internal {
1044
1045 struct StreamClassRefFuncs final
1046 {
1047 static void get(const bt_stream_class * const libObjPtr) noexcept
1048 {
1049 bt_stream_class_get_ref(libObjPtr);
1050 }
1051
1052 static void put(const bt_stream_class * const libObjPtr) noexcept
1053 {
1054 bt_stream_class_put_ref(libObjPtr);
1055 }
1056 };
1057
1058 template <typename LibObjT>
1059 struct CommonStreamClassSpec;
1060
1061 /* Functions specific to mutable stream classes */
1062 template <>
1063 struct CommonStreamClassSpec<bt_stream_class> final
1064 {
1065 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1066 {
1067 return bt_stream_class_borrow_trace_class(libObjPtr);
1068 }
1069
1070 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1071 const std::uint64_t index) noexcept
1072 {
1073 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1074 }
1075
1076 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1077 const std::uint64_t id) noexcept
1078 {
1079 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1080 }
1081
1082 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1083 {
1084 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1085 }
1086
1087 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1088 {
1089 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1090 }
1091
1092 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1093 {
1094 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1095 }
1096
1097 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1098 {
1099 return bt_stream_class_borrow_user_attributes(libObjPtr);
1100 }
1101 };
1102
1103 /* Functions specific to constant stream classes */
1104 template <>
1105 struct CommonStreamClassSpec<const bt_stream_class> final
1106 {
1107 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1108 {
1109 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1110 }
1111
1112 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1113 const std::uint64_t index) noexcept
1114 {
1115 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1116 }
1117
1118 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1119 const std::uint64_t id) noexcept
1120 {
1121 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1122 }
1123
1124 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1125 {
1126 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1127 }
1128
1129 static const bt_field_class *
1130 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1131 {
1132 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1133 }
1134
1135 static const bt_field_class *
1136 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1137 {
1138 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1139 }
1140
1141 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1142 {
1143 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1144 }
1145 };
1146
1147 } /* namespace internal */
1148
1149 template <typename LibObjT>
1150 class CommonStreamClass final : public BorrowedObject<LibObjT>
1151 {
1152 private:
1153 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1154 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1155 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
1156
1157 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1158 CommonTraceClass<const bt_trace_class>>;
1159
1160 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1161 CommonEventClass<const bt_event_class>>;
1162
1163 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
1164
1165 public:
1166 using typename BorrowedObject<LibObjT>::LibObjPtr;
1167 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1168 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1169
1170 explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1171 {
1172 }
1173
1174 template <typename OtherLibObjT>
1175 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1176 _ThisBorrowedObject {streamClass}
1177 {
1178 }
1179
1180 template <typename OtherLibObjT>
1181 CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1182 {
1183 _ThisBorrowedObject::operator=(streamClass);
1184 return *this;
1185 }
1186
1187 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1188 {
1189 return CommonStreamClass<const bt_stream_class> {*this};
1190 }
1191
1192 Stream::Shared instantiate(const Trace trace) const
1193 {
1194 static_assert(!std::is_const<LibObjT>::value,
1195 "Not available with `bt2::ConstStreamClass`.");
1196
1197 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1198
1199 internal::validateCreatedObjPtr(libObjPtr);
1200 return Stream::Shared::createWithoutRef(libObjPtr);
1201 }
1202
1203 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1204 {
1205 static_assert(!std::is_const<LibObjT>::value,
1206 "Not available with `bt2::ConstStreamClass`.");
1207
1208 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1209
1210 internal::validateCreatedObjPtr(libObjPtr);
1211 return Stream::Shared::createWithoutRef(libObjPtr);
1212 }
1213
1214 EventClass::Shared createEventClass() const
1215 {
1216 static_assert(!std::is_const<LibObjT>::value,
1217 "Not available with `bt2::ConstStreamClass`.");
1218
1219 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1220
1221 internal::validateCreatedObjPtr(libObjPtr);
1222 return EventClass::Shared::createWithoutRef(libObjPtr);
1223 }
1224
1225 EventClass::Shared createEventClass(const std::uint64_t id) const
1226 {
1227 static_assert(!std::is_const<LibObjT>::value,
1228 "Not available with `bt2::ConstStreamClass`.");
1229
1230 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1231
1232 internal::validateCreatedObjPtr(libObjPtr);
1233 return EventClass::Shared::createWithoutRef(libObjPtr);
1234 }
1235
1236 _TraceClass traceClass() const noexcept;
1237
1238 std::uint64_t id() const noexcept
1239 {
1240 return bt_stream_class_get_id(this->libObjPtr());
1241 }
1242
1243 void name(const bt2c::CStringView name) const
1244 {
1245 static_assert(!std::is_const<LibObjT>::value,
1246 "Not available with `bt2::ConstStreamClass`.");
1247
1248 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1249
1250 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1251 throw MemoryError {};
1252 }
1253 }
1254
1255 bt2c::CStringView name() const noexcept
1256 {
1257 return bt_stream_class_get_name(this->libObjPtr());
1258 }
1259
1260 void assignsAutomaticEventClassId(const bool val) const noexcept
1261 {
1262 static_assert(!std::is_const<LibObjT>::value,
1263 "Not available with `bt2::ConstStreamClass`.");
1264
1265 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1266 static_cast<bt_bool>(val));
1267 }
1268
1269 bool assignsAutomaticEventClassId() const noexcept
1270 {
1271 return static_cast<bool>(
1272 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1273 }
1274
1275 void assignsAutomaticStreamId(const bool val) const noexcept
1276 {
1277 static_assert(!std::is_const<LibObjT>::value,
1278 "Not available with `bt2::ConstStreamClass`.");
1279
1280 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1281 static_cast<bt_bool>(val));
1282 }
1283
1284 bool assignsAutomaticStreamId() const noexcept
1285 {
1286 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1287 }
1288
1289 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1290 const bool withEndDefaultClkSnapshot) const noexcept
1291 {
1292 static_assert(!std::is_const<LibObjT>::value,
1293 "Not available with `bt2::ConstStreamClass`.");
1294
1295 bt_stream_class_set_supports_packets(this->libObjPtr(),
1296 static_cast<bt_bool>(supportsPackets),
1297 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1298 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1299 }
1300
1301 bool supportsPackets() const noexcept
1302 {
1303 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1304 }
1305
1306 bool packetsHaveBeginningClockSnapshot() const noexcept
1307 {
1308 return static_cast<bool>(
1309 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1310 }
1311
1312 bool packetsHaveEndClockSnapshot() const noexcept
1313 {
1314 return static_cast<bool>(
1315 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1316 }
1317
1318 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1319 const bool withDefaultClkSnapshots) const noexcept
1320 {
1321 static_assert(!std::is_const<LibObjT>::value,
1322 "Not available with `bt2::ConstStreamClass`.");
1323
1324 bt_stream_class_set_supports_discarded_events(
1325 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1326 static_cast<bt_bool>(withDefaultClkSnapshots));
1327 }
1328
1329 bool supportsDiscardedEvents() const noexcept
1330 {
1331 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1332 }
1333
1334 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1335 {
1336 return static_cast<bool>(
1337 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1338 }
1339
1340 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1341 const bool withDefaultClkSnapshots) const noexcept
1342 {
1343 static_assert(!std::is_const<LibObjT>::value,
1344 "Not available with `bt2::ConstStreamClass`.");
1345
1346 bt_stream_class_set_supports_discarded_packets(
1347 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1348 static_cast<bt_bool>(withDefaultClkSnapshots));
1349 }
1350
1351 bool supportsDiscardedPackets() const noexcept
1352 {
1353 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1354 }
1355
1356 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1357 {
1358 return static_cast<bool>(
1359 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1360 }
1361
1362 void defaultClockClass(const ClockClass clkCls) const
1363 {
1364 static_assert(!std::is_const<LibObjT>::value,
1365 "Not available with `bt2::ConstStreamClass`.");
1366
1367 const auto status =
1368 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1369
1370 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1371 }
1372
1373 OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
1374 {
1375 return _Spec::defaultClockClass(this->libObjPtr());
1376 }
1377
1378 std::uint64_t length() const noexcept
1379 {
1380 return bt_stream_class_get_event_class_count(this->libObjPtr());
1381 }
1382
1383 _EventClass operator[](const std::uint64_t index) const noexcept
1384 {
1385 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1386 }
1387
1388 OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1389 {
1390 return _Spec::eventClassById(this->libObjPtr(), id);
1391 }
1392
1393 void packetContextFieldClass(const StructureFieldClass fc) const
1394 {
1395 static_assert(!std::is_const<LibObjT>::value,
1396 "Not available with `bt2::ConstStreamClass`.");
1397
1398 const auto status =
1399 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1400
1401 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1402 throw MemoryError {};
1403 }
1404 }
1405
1406 OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
1407 {
1408 return _Spec::packetContextFieldClass(this->libObjPtr());
1409 }
1410
1411 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1412 {
1413 static_assert(!std::is_const<LibObjT>::value,
1414 "Not available with `bt2::ConstStreamClass`.");
1415
1416 const auto status =
1417 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1418
1419 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1420 throw MemoryError {};
1421 }
1422 }
1423
1424 OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1425 {
1426 return _Spec::eventCommonContextFieldClass(this->libObjPtr());
1427 }
1428
1429 template <typename LibValT>
1430 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1431 {
1432 static_assert(!std::is_const<LibObjT>::value,
1433 "Not available with `bt2::ConstStreamClass`.");
1434
1435 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1436 }
1437
1438 UserAttributes userAttributes() const noexcept
1439 {
1440 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1441 }
1442
1443 Shared shared() const noexcept
1444 {
1445 return Shared::createWithRef(*this);
1446 }
1447 };
1448
1449 using StreamClass = CommonStreamClass<bt_stream_class>;
1450 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1451
1452 namespace internal {
1453
1454 struct StreamClassTypeDescr
1455 {
1456 using Const = ConstStreamClass;
1457 using NonConst = StreamClass;
1458 };
1459
1460 template <>
1461 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1462 {
1463 };
1464
1465 template <>
1466 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1467 {
1468 };
1469
1470 } /* namespace internal */
1471
1472 template <typename LibObjT>
1473 typename CommonEventClass<LibObjT>::_StreamClass
1474 CommonEventClass<LibObjT>::streamClass() const noexcept
1475 {
1476 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1477 }
1478
1479 template <typename LibObjT>
1480 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1481 {
1482 return Class {_Spec::cls(this->libObjPtr())};
1483 }
1484
1485 namespace internal {
1486
1487 struct TraceClassRefFuncs final
1488 {
1489 static void get(const bt_trace_class * const libObjPtr) noexcept
1490 {
1491 bt_trace_class_get_ref(libObjPtr);
1492 }
1493
1494 static void put(const bt_trace_class * const libObjPtr) noexcept
1495 {
1496 bt_trace_class_put_ref(libObjPtr);
1497 }
1498 };
1499
1500 template <typename LibObjT>
1501 struct CommonTraceClassSpec;
1502
1503 /* Functions specific to mutable stream classes */
1504 template <>
1505 struct CommonTraceClassSpec<bt_trace_class> final
1506 {
1507 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1508 const std::uint64_t index) noexcept
1509 {
1510 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1511 }
1512
1513 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1514 const std::uint64_t id) noexcept
1515 {
1516 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1517 }
1518
1519 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1520 {
1521 return bt_trace_class_borrow_user_attributes(libObjPtr);
1522 }
1523 };
1524
1525 /* Functions specific to constant stream classes */
1526 template <>
1527 struct CommonTraceClassSpec<const bt_trace_class> final
1528 {
1529 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1530 const std::uint64_t index) noexcept
1531 {
1532 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1533 }
1534
1535 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1536 const std::uint64_t id) noexcept
1537 {
1538 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1539 }
1540
1541 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1542 {
1543 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1544 }
1545 };
1546
1547 } /* namespace internal */
1548
1549 template <typename LibObjT>
1550 class CommonTraceClass final : public BorrowedObject<LibObjT>
1551 {
1552 private:
1553 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1554
1555 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1556
1557 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1558 CommonStreamClass<const bt_stream_class>>;
1559
1560 public:
1561 using typename BorrowedObject<LibObjT>::LibObjPtr;
1562 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1563 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1564
1565 explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1566 {
1567 }
1568
1569 template <typename OtherLibObjT>
1570 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1571 _ThisBorrowedObject {traceClass}
1572 {
1573 }
1574
1575 template <typename OtherLibObjT>
1576 CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1577 {
1578 _ThisBorrowedObject::operator=(traceClass);
1579 return *this;
1580 }
1581
1582 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1583 {
1584 return CommonTraceClass<const bt_trace_class> {*this};
1585 }
1586
1587 Trace::Shared instantiate() const
1588 {
1589 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1590
1591 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1592
1593 internal::validateCreatedObjPtr(libObjPtr);
1594 return Trace::Shared::createWithoutRef(libObjPtr);
1595 }
1596
1597 StreamClass::Shared createStreamClass() const
1598 {
1599 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1600
1601 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1602
1603 internal::validateCreatedObjPtr(libObjPtr);
1604 return StreamClass::Shared::createWithoutRef(libObjPtr);
1605 }
1606
1607 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1608 {
1609 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1610
1611 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1612
1613 internal::validateCreatedObjPtr(libObjPtr);
1614 return StreamClass::Shared::createWithoutRef(libObjPtr);
1615 }
1616
1617 FieldClass::Shared createBoolFieldClass() const
1618 {
1619 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1620
1621 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1622
1623 internal::validateCreatedObjPtr(libObjPtr);
1624 return FieldClass::Shared::createWithoutRef(libObjPtr);
1625 }
1626
1627 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1628 {
1629 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1630
1631 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1632
1633 internal::validateCreatedObjPtr(libObjPtr);
1634 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1635 }
1636
1637 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1638 {
1639 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1640
1641 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1642
1643 internal::validateCreatedObjPtr(libObjPtr);
1644 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1645 }
1646
1647 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1648 {
1649 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1650
1651 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1652
1653 internal::validateCreatedObjPtr(libObjPtr);
1654 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1655 }
1656
1657 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1658 {
1659 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1660
1661 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1662
1663 internal::validateCreatedObjPtr(libObjPtr);
1664 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1665 }
1666
1667 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1668 {
1669 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1670
1671 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1672
1673 internal::validateCreatedObjPtr(libObjPtr);
1674 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1675 }
1676
1677 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1678 {
1679 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1680
1681 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1682
1683 internal::validateCreatedObjPtr(libObjPtr);
1684 return FieldClass::Shared::createWithoutRef(libObjPtr);
1685 }
1686
1687 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1688 {
1689 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1690
1691 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1692
1693 internal::validateCreatedObjPtr(libObjPtr);
1694 return FieldClass::Shared::createWithoutRef(libObjPtr);
1695 }
1696
1697 FieldClass::Shared createStringFieldClass() const
1698 {
1699 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1700
1701 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1702
1703 internal::validateCreatedObjPtr(libObjPtr);
1704 return FieldClass::Shared::createWithoutRef(libObjPtr);
1705 }
1706
1707 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1708 const std::uint64_t length) const
1709 {
1710 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1711
1712 const auto libObjPtr = bt_field_class_array_static_create(
1713 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1714
1715 internal::validateCreatedObjPtr(libObjPtr);
1716 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1717 }
1718
1719 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1720 {
1721 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1722
1723 const auto libObjPtr = bt_field_class_array_dynamic_create(
1724 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1725
1726 internal::validateCreatedObjPtr(libObjPtr);
1727 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1728 }
1729
1730 DynamicArrayWithLengthFieldClass::Shared
1731 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1732 const IntegerFieldClass lengthFieldClass) const
1733 {
1734 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1735
1736 const auto libObjPtr = bt_field_class_array_dynamic_create(
1737 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1738
1739 internal::validateCreatedObjPtr(libObjPtr);
1740 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1741 }
1742
1743 StructureFieldClass::Shared createStructureFieldClass() const
1744 {
1745 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1746
1747 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1748
1749 internal::validateCreatedObjPtr(libObjPtr);
1750 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1751 }
1752
1753 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1754 {
1755 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1756
1757 const auto libObjPtr = bt_field_class_option_without_selector_create(
1758 this->libObjPtr(), optionalFieldClass.libObjPtr());
1759
1760 internal::validateCreatedObjPtr(libObjPtr);
1761 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1762 }
1763
1764 OptionWithBoolSelectorFieldClass::Shared
1765 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1766 const FieldClass selectorFieldClass) const
1767 {
1768 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1769
1770 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1771 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1772
1773 internal::validateCreatedObjPtr(libObjPtr);
1774 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1775 }
1776
1777 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1778 createOptionWithUnsignedIntegerSelectorFieldClass(
1779 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1780 const ConstUnsignedIntegerRangeSet ranges) const
1781 {
1782 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1783
1784 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1785 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1786 ranges.libObjPtr());
1787
1788 internal::validateCreatedObjPtr(libObjPtr);
1789 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1790 }
1791
1792 OptionWithSignedIntegerSelectorFieldClass::Shared
1793 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1794 const IntegerFieldClass selectorFieldClass,
1795 const ConstSignedIntegerRangeSet ranges) const
1796 {
1797 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1798
1799 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1800 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1801 ranges.libObjPtr());
1802
1803 internal::validateCreatedObjPtr(libObjPtr);
1804 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1805 }
1806
1807 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1808 {
1809 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1810
1811 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1812
1813 internal::validateCreatedObjPtr(libObjPtr);
1814 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1815 }
1816
1817 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1818 createVariantWithUnsignedIntegerSelectorFieldClass(
1819 const IntegerFieldClass selectorFieldClass) const
1820 {
1821 return this->_createVariantWithIntegerSelectorFieldClass<
1822 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1823 }
1824
1825 VariantWithSignedIntegerSelectorFieldClass::Shared
1826 createVariantWithSignedIntegerSelectorFieldClass(
1827 const IntegerFieldClass selectorFieldClass) const
1828 {
1829 return this->_createVariantWithIntegerSelectorFieldClass<
1830 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
1831 }
1832
1833 void assignsAutomaticStreamClassId(const bool val) const noexcept
1834 {
1835 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1836
1837 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
1838 static_cast<bt_bool>(val));
1839 }
1840
1841 bool assignsAutomaticStreamClassId() const noexcept
1842 {
1843 return static_cast<bool>(
1844 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
1845 }
1846
1847 std::uint64_t length() const noexcept
1848 {
1849 return bt_trace_class_get_stream_class_count(this->libObjPtr());
1850 }
1851
1852 _StreamClass operator[](const std::uint64_t index) const noexcept
1853 {
1854 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
1855 }
1856
1857 OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
1858 {
1859 return _Spec::streamClassById(this->libObjPtr(), id);
1860 }
1861
1862 template <typename LibValT>
1863 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1864 {
1865 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1866
1867 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1868 }
1869
1870 UserAttributes userAttributes() const noexcept
1871 {
1872 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1873 }
1874
1875 Shared shared() const noexcept
1876 {
1877 return Shared::createWithRef(*this);
1878 }
1879
1880 private:
1881 template <typename ObjT>
1882 typename ObjT::Shared
1883 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
1884 {
1885 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1886
1887 const auto libObjPtr =
1888 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
1889
1890 internal::validateCreatedObjPtr(libObjPtr);
1891 return ObjT::Shared::createWithoutRef(libObjPtr);
1892 }
1893 };
1894
1895 using TraceClass = CommonTraceClass<bt_trace_class>;
1896 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
1897
1898 namespace internal {
1899
1900 struct TraceClassTypeDescr
1901 {
1902 using Const = ConstTraceClass;
1903 using NonConst = TraceClass;
1904 };
1905
1906 template <>
1907 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
1908 {
1909 };
1910
1911 template <>
1912 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
1913 {
1914 };
1915
1916 } /* namespace internal */
1917
1918 template <typename LibObjT>
1919 typename CommonStreamClass<LibObjT>::_TraceClass
1920 CommonStreamClass<LibObjT>::traceClass() const noexcept
1921 {
1922 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
1923 }
1924
1925 template <typename LibObjT>
1926 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
1927 {
1928 return Class {_Spec::cls(this->libObjPtr())};
1929 }
1930
1931 } /* namespace bt2 */
1932
1933 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */
This page took 0.10221 seconds and 4 git commands to generate.