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