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