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