2 * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
11 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "cpp-common/optional.hpp"
17 #include "borrowed-object.hpp"
18 #include "clock-class.hpp"
19 #include "field-class.hpp"
21 #include "internal/utils.hpp"
22 #include "shared-object.hpp"
27 template <typename LibObjT>
30 template <typename LibObjT>
33 template <typename LibObjT>
36 template <typename LibObjT>
39 template <typename LibObjT>
40 class CommonEventClass;
42 template <typename LibObjT>
43 class CommonStreamClass;
45 template <typename LibObjT>
46 class CommonTraceClass;
50 template <typename LibObjT>
51 struct CommonEventSpec;
53 /* Functions specific to mutable events */
55 struct CommonEventSpec<bt_event> final
57 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
59 return bt_event_borrow_class(libObjPtr);
62 static bt_stream *stream(bt_event * const libObjPtr) noexcept
64 return bt_event_borrow_stream(libObjPtr);
67 static bt_packet *packet(bt_event * const libObjPtr) noexcept
69 return bt_event_borrow_packet(libObjPtr);
72 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
74 return bt_event_borrow_payload_field(libObjPtr);
77 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
79 return bt_event_borrow_specific_context_field(libObjPtr);
82 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
84 return bt_event_borrow_common_context_field(libObjPtr);
88 /* Functions specific to constant events */
90 struct CommonEventSpec<const bt_event> final
92 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
94 return bt_event_borrow_class_const(libObjPtr);
97 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
99 return bt_event_borrow_stream_const(libObjPtr);
102 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
104 return bt_event_borrow_packet_const(libObjPtr);
107 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
109 return bt_event_borrow_payload_field_const(libObjPtr);
112 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
114 return bt_event_borrow_specific_context_field_const(libObjPtr);
117 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
119 return bt_event_borrow_common_context_field_const(libObjPtr);
123 template <typename LibObjT>
124 using DepStructField = DepType<LibObjT, StructureField, ConstStructureField>;
126 } /* namespace internal */
128 template <typename LibObjT>
129 class CommonEvent final : public BorrowedObject<LibObjT>
132 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
133 using typename BorrowedObject<LibObjT>::_LibObjPtr;
134 using _Spec = internal::CommonEventSpec<LibObjT>;
135 using _Packet = internal::DepPacket<LibObjT>;
136 using _Stream = internal::DepStream<LibObjT>;
137 using _StructureField = internal::DepStructField<LibObjT>;
140 using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
141 CommonEventClass<const bt_event_class>>;
143 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
147 template <typename OtherLibObjT>
148 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
152 template <typename OtherLibObjT>
153 CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept
155 _ThisBorrowedObject::operator=(event);
159 CommonEvent<const bt_event> asConst() const noexcept
161 return CommonEvent<const bt_event> {*this};
164 Class cls() const noexcept;
165 _Stream stream() const noexcept;
166 nonstd::optional<_Packet> packet() const noexcept;
168 nonstd::optional<_StructureField> payloadField() const noexcept
170 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
173 return _StructureField {libObjPtr};
176 return nonstd::nullopt;
179 nonstd::optional<_StructureField> specificContextField() const noexcept
181 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
184 return _StructureField {libObjPtr};
187 return nonstd::nullopt;
190 nonstd::optional<_StructureField> commonContextField() const noexcept
192 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
195 return _StructureField {libObjPtr};
198 return nonstd::nullopt;
202 using Event = CommonEvent<bt_event>;
203 using ConstEvent = CommonEvent<const bt_event>;
207 struct EventTypeDescr
209 using Const = ConstEvent;
210 using NonConst = Event;
214 struct TypeDescr<Event> : public EventTypeDescr
219 struct TypeDescr<ConstEvent> : public EventTypeDescr
223 struct PacketRefFuncs final
225 static void get(const bt_packet * const libObjPtr) noexcept
227 bt_packet_get_ref(libObjPtr);
230 static void put(const bt_packet * const libObjPtr) noexcept
232 bt_packet_put_ref(libObjPtr);
236 template <typename LibObjT>
237 struct CommonPacketSpec;
239 /* Functions specific to mutable packets */
241 struct CommonPacketSpec<bt_packet> final
243 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
245 return bt_packet_borrow_stream(libObjPtr);
248 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
250 return bt_packet_borrow_context_field(libObjPtr);
254 /* Functions specific to constant packets */
256 struct CommonPacketSpec<const bt_packet> final
258 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
260 return bt_packet_borrow_stream_const(libObjPtr);
263 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
265 return bt_packet_borrow_context_field_const(libObjPtr);
269 } /* namespace internal */
271 template <typename LibObjT>
272 class CommonPacket final : public BorrowedObject<LibObjT>
275 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
276 using typename BorrowedObject<LibObjT>::_LibObjPtr;
277 using _Spec = internal::CommonPacketSpec<LibObjT>;
278 using _Stream = internal::DepStream<LibObjT>;
279 using _StructureField = internal::DepStructField<LibObjT>;
282 using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
284 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
288 template <typename OtherLibObjT>
289 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
293 template <typename OtherLibObjT>
294 CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept
296 _ThisBorrowedObject::operator=(packet);
300 CommonPacket<const bt_packet> asConst() const noexcept
302 return CommonPacket<const bt_packet> {*this};
305 _Stream stream() const noexcept;
307 nonstd::optional<_StructureField> contextField() const noexcept
309 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
312 return _StructureField {libObjPtr};
315 return nonstd::nullopt;
318 Shared shared() const noexcept
320 return Shared::createWithRef(*this);
324 using Packet = CommonPacket<bt_packet>;
325 using ConstPacket = CommonPacket<const bt_packet>;
329 struct PacketTypeDescr
331 using Const = ConstPacket;
332 using NonConst = Packet;
336 struct TypeDescr<Packet> : public PacketTypeDescr
341 struct TypeDescr<ConstPacket> : public PacketTypeDescr
345 } /* namespace internal */
347 template <typename LibObjT>
348 nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
349 CommonEvent<LibObjT>::packet() const noexcept
351 const auto libObjPtr = _Spec::packet(this->libObjPtr());
354 return _Packet {libObjPtr};
357 return nonstd::nullopt;
362 struct StreamRefFuncs final
364 static void get(const bt_stream * const libObjPtr) noexcept
366 bt_stream_get_ref(libObjPtr);
369 static void put(const bt_stream * const libObjPtr) noexcept
371 bt_stream_put_ref(libObjPtr);
375 template <typename LibObjT>
376 struct CommonStreamSpec;
378 /* Functions specific to mutable streams */
380 struct CommonStreamSpec<bt_stream> final
382 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
384 return bt_stream_borrow_class(libObjPtr);
387 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
389 return bt_stream_borrow_trace(libObjPtr);
392 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
394 return bt_stream_borrow_user_attributes(libObjPtr);
398 /* Functions specific to constant streams */
400 struct CommonStreamSpec<const bt_stream> final
402 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
404 return bt_stream_borrow_class_const(libObjPtr);
407 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
409 return bt_stream_borrow_trace_const(libObjPtr);
412 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
414 return bt_stream_borrow_user_attributes_const(libObjPtr);
418 } /* namespace internal */
420 template <typename LibObjT>
421 class CommonStream final : public BorrowedObject<LibObjT>
424 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
425 using typename BorrowedObject<LibObjT>::_LibObjPtr;
426 using _Spec = internal::CommonStreamSpec<LibObjT>;
427 using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
430 using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
431 using UserAttributes = internal::DepUserAttrs<LibObjT>;
433 using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
434 CommonStreamClass<const bt_stream_class>>;
436 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
440 template <typename OtherLibObjT>
441 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
445 template <typename OtherLibObjT>
446 CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept
448 _ThisBorrowedObject::operator=(stream);
452 CommonStream<const bt_stream> asConst() const noexcept
454 return CommonStream<const bt_stream> {*this};
457 Packet::Shared createPacket() const
459 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
461 const auto libObjPtr = bt_packet_create(this->libObjPtr());
463 internal::validateCreatedObjPtr(libObjPtr);
464 return Packet::Shared::createWithoutRef(libObjPtr);
467 Class cls() const noexcept;
468 _Trace trace() const noexcept;
470 std::uint64_t id() const noexcept
472 return bt_stream_get_id(this->libObjPtr());
475 void name(const char * const name) const
477 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
479 const auto status = bt_stream_set_name(this->libObjPtr(), name);
481 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
482 throw MemoryError {};
486 void name(const std::string& name) const
488 this->name(name.data());
491 const char *name() const noexcept
493 return bt_stream_get_name(this->libObjPtr());
496 template <typename LibValT>
497 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
499 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
501 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
504 UserAttributes userAttributes() const noexcept
506 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
509 Shared shared() const noexcept
511 return Shared::createWithRef(*this);
515 using Stream = CommonStream<bt_stream>;
516 using ConstStream = CommonStream<const bt_stream>;
520 struct StreamTypeDescr
522 using Const = ConstStream;
523 using NonConst = Stream;
527 struct TypeDescr<Stream> : public StreamTypeDescr
532 struct TypeDescr<ConstStream> : public StreamTypeDescr
536 } /* namespace internal */
538 template <typename LibObjT>
539 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
541 return _Stream {_Spec::stream(this->libObjPtr())};
544 template <typename LibObjT>
545 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
547 return _Stream {_Spec::stream(this->libObjPtr())};
552 struct TraceRefFuncs final
554 static void get(const bt_trace * const libObjPtr) noexcept
556 bt_trace_get_ref(libObjPtr);
559 static void put(const bt_trace * const libObjPtr) noexcept
561 bt_trace_put_ref(libObjPtr);
565 template <typename LibObjT>
566 struct CommonTraceSpec;
568 /* Functions specific to mutable traces */
570 struct CommonTraceSpec<bt_trace> final
572 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
574 return bt_trace_borrow_class(libObjPtr);
577 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
579 return bt_trace_borrow_stream_by_index(libObjPtr, index);
582 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
584 return bt_trace_borrow_stream_by_id(libObjPtr, id);
587 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
589 return bt_trace_borrow_user_attributes(libObjPtr);
593 /* Functions specific to constant traces */
595 struct CommonTraceSpec<const bt_trace> final
597 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
599 return bt_trace_borrow_class_const(libObjPtr);
602 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
603 const std::uint64_t index) noexcept
605 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
608 static const bt_stream *streamById(const bt_trace * const libObjPtr,
609 const std::uint64_t id) noexcept
611 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
614 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
616 return bt_trace_borrow_user_attributes_const(libObjPtr);
620 } /* namespace internal */
622 template <typename LibObjT>
623 class CommonTrace final : public BorrowedObject<LibObjT>
626 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
627 using typename BorrowedObject<LibObjT>::_LibObjPtr;
628 using _Spec = internal::CommonTraceSpec<LibObjT>;
629 using _Stream = internal::DepStream<LibObjT>;
632 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
633 using UserAttributes = internal::DepUserAttrs<LibObjT>;
635 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
636 CommonTraceClass<const bt_trace_class>>;
638 struct ConstEnvironmentEntry
644 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
648 template <typename OtherLibObjT>
649 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
653 template <typename OtherLibObjT>
654 CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
656 _ThisBorrowedObject::operator=(trace);
660 CommonTrace<const bt_trace> asConst() const noexcept
662 return CommonTrace<const bt_trace> {*this};
665 Class cls() const noexcept;
667 void name(const char * const name) const
669 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
671 const auto status = bt_trace_set_name(this->libObjPtr(), name);
673 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
674 throw MemoryError {};
678 void name(const std::string& name) const
680 this->name(name.data());
683 const char *name() const noexcept
685 return bt_trace_get_name(this->libObjPtr());
688 void uuid(const bt2c::UuidView& uuid) const noexcept
690 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
693 nonstd::optional<bt2c::UuidView> uuid() const noexcept
695 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
698 return bt2c::UuidView {uuid};
701 return nonstd::nullopt;
704 std::uint64_t length() const noexcept
706 return bt_trace_get_stream_count(this->libObjPtr());
709 _Stream operator[](const std::uint64_t index) const noexcept
711 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
714 nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
716 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
719 return _Stream {libObjPtr};
722 return nonstd::nullopt;
725 void environmentEntry(const char * const name, const std::int64_t val) const
727 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
729 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
731 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
732 throw MemoryError {};
736 void environmentEntry(const std::string& name, const std::int64_t val) const
738 this->environmentEntry(name.data(), val);
741 void environmentEntry(const char * const name, const char * const val) const
743 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
745 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
747 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
748 throw MemoryError {};
752 void environmentEntry(const std::string& name, const char * const val) const
754 this->environmentEntry(name.data(), val);
757 void environmentEntry(const char * const name, const std::string& val) const
759 this->environmentEntry(name, val.data());
762 void environmentEntry(const std::string& name, const std::string& val) const
764 this->environmentEntry(name.data(), val.data());
767 std::uint64_t environmentSize() const noexcept
769 return bt_trace_get_environment_entry_count(this->libObjPtr());
772 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
775 const bt_value *libObjPtr;
777 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
779 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
782 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
784 const auto libObjPtr =
785 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
788 return ConstValue {libObjPtr};
791 return nonstd::nullopt;
794 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
796 return this->environmentEntry(name.data());
799 template <typename LibValT>
800 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
802 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
804 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
807 UserAttributes userAttributes() const noexcept
809 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
812 Shared shared() const noexcept
814 return Shared::createWithRef(*this);
818 using Trace = CommonTrace<bt_trace>;
819 using ConstTrace = CommonTrace<const bt_trace>;
823 struct TraceTypeDescr
825 using Const = ConstTrace;
826 using NonConst = Trace;
830 struct TypeDescr<Trace> : public TraceTypeDescr
835 struct TypeDescr<ConstTrace> : public TraceTypeDescr
839 } /* namespace internal */
841 template <typename LibObjT>
842 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
844 return _Trace {_Spec::trace(this->libObjPtr())};
849 struct EventClassRefFuncs final
851 static void get(const bt_event_class * const libObjPtr) noexcept
853 bt_event_class_get_ref(libObjPtr);
856 static void put(const bt_event_class * const libObjPtr) noexcept
858 bt_event_class_put_ref(libObjPtr);
862 template <typename LibObjT>
863 struct CommonEventClassSpec;
865 /* Functions specific to mutable event classes */
867 struct CommonEventClassSpec<bt_event_class> final
869 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
871 return bt_event_class_borrow_stream_class(libObjPtr);
874 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
876 return bt_event_class_borrow_payload_field_class(libObjPtr);
879 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
881 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
884 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
886 return bt_event_class_borrow_user_attributes(libObjPtr);
890 /* Functions specific to constant event classes */
892 struct CommonEventClassSpec<const bt_event_class> final
894 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
896 return bt_event_class_borrow_stream_class_const(libObjPtr);
899 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
901 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
904 static const bt_field_class *
905 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
907 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
910 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
912 return bt_event_class_borrow_user_attributes_const(libObjPtr);
916 template <typename LibObjT>
917 using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
919 } /* namespace internal */
921 template <typename LibObjT>
922 class CommonEventClass final : public BorrowedObject<LibObjT>
925 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
926 using typename BorrowedObject<LibObjT>::_LibObjPtr;
927 using _Spec = internal::CommonEventClassSpec<LibObjT>;
928 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
930 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
931 CommonStreamClass<const bt_stream_class>>;
934 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
935 using UserAttributes = internal::DepUserAttrs<LibObjT>;
939 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
940 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
941 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
942 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
943 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
944 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
945 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
946 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
947 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
948 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
949 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
950 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
951 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
952 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
953 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
956 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
960 template <typename OtherLibObjT>
961 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
962 _ThisBorrowedObject {eventClass}
966 template <typename OtherLibObjT>
967 CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
969 _ThisBorrowedObject::operator=(eventClass);
973 CommonEventClass<const bt_event_class> asConst() const noexcept
975 return CommonEventClass<const bt_event_class> {*this};
978 _StreamClass streamClass() const noexcept;
980 std::uint64_t id() const noexcept
982 return bt_event_class_get_id(this->libObjPtr());
985 void name(const char * const name) const
987 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
989 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
991 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
992 throw MemoryError {};
996 void name(const std::string& name) const
998 this->name(name.data());
1001 const char *name() const noexcept
1003 return bt_event_class_get_name(this->libObjPtr());
1006 void logLevel(const LogLevel logLevel) const noexcept
1008 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1010 bt_event_class_set_log_level(this->libObjPtr(),
1011 static_cast<bt_event_class_log_level>(logLevel));
1014 nonstd::optional<LogLevel> logLevel() const noexcept
1016 bt_event_class_log_level libLogLevel;
1017 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1019 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1020 return static_cast<LogLevel>(libLogLevel);
1023 return nonstd::nullopt;
1026 void emfUri(const char * const emfUri) const
1028 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1030 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1032 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1033 throw MemoryError {};
1037 void emfUri(const std::string& emfUri) const
1039 this->emfUri(emfUri.data());
1042 const char *emfUri() const noexcept
1044 return bt_event_class_get_emf_uri(this->libObjPtr());
1047 void payloadFieldClass(const StructureFieldClass fc) const
1049 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1052 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1054 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1055 throw MemoryError {};
1059 nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
1061 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1064 return _StructureFieldClass {libObjPtr};
1067 return nonstd::nullopt;
1070 void specificContextFieldClass(const StructureFieldClass fc) const
1072 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1075 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1077 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1078 throw MemoryError {};
1082 nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
1084 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1087 return _StructureFieldClass {libObjPtr};
1090 return nonstd::nullopt;
1093 template <typename LibValT>
1094 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1096 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1098 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1101 UserAttributes userAttributes() const noexcept
1103 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1106 Shared shared() const noexcept
1108 return Shared::createWithRef(*this);
1112 using EventClass = CommonEventClass<bt_event_class>;
1113 using ConstEventClass = CommonEventClass<const bt_event_class>;
1115 namespace internal {
1117 struct EventClassTypeDescr
1119 using Const = ConstEventClass;
1120 using NonConst = EventClass;
1124 struct TypeDescr<EventClass> : public EventClassTypeDescr
1129 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1133 } /* namespace internal */
1135 template <typename LibObjT>
1136 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1138 return Class {_Spec::cls(this->libObjPtr())};
1141 namespace internal {
1143 struct StreamClassRefFuncs final
1145 static void get(const bt_stream_class * const libObjPtr) noexcept
1147 bt_stream_class_get_ref(libObjPtr);
1150 static void put(const bt_stream_class * const libObjPtr) noexcept
1152 bt_stream_class_put_ref(libObjPtr);
1156 template <typename LibObjT>
1157 struct CommonStreamClassSpec;
1159 /* Functions specific to mutable stream classes */
1161 struct CommonStreamClassSpec<bt_stream_class> final
1163 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1165 return bt_stream_class_borrow_trace_class(libObjPtr);
1168 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1169 const std::uint64_t index) noexcept
1171 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1174 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1175 const std::uint64_t id) noexcept
1177 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1180 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1182 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1185 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1187 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1190 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1192 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1195 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1197 return bt_stream_class_borrow_user_attributes(libObjPtr);
1201 /* Functions specific to constant stream classes */
1203 struct CommonStreamClassSpec<const bt_stream_class> final
1205 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1207 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1210 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1211 const std::uint64_t index) noexcept
1213 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1216 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1217 const std::uint64_t id) noexcept
1219 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1222 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1224 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1227 static const bt_field_class *
1228 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1230 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1233 static const bt_field_class *
1234 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1236 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1239 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1241 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1245 } /* namespace internal */
1247 template <typename LibObjT>
1248 class CommonStreamClass final : public BorrowedObject<LibObjT>
1251 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1252 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1253 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1254 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
1256 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1257 CommonTraceClass<const bt_trace_class>>;
1259 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1260 CommonEventClass<const bt_event_class>>;
1262 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
1265 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1266 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1268 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
1269 _ThisBorrowedObject {libObjPtr}
1273 template <typename OtherLibObjT>
1274 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1275 _ThisBorrowedObject {streamClass}
1279 template <typename OtherLibObjT>
1280 CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1282 _ThisBorrowedObject::operator=(streamClass);
1286 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1288 return CommonStreamClass<const bt_stream_class> {*this};
1291 Stream::Shared instantiate(const Trace trace) const
1293 static_assert(!std::is_const<LibObjT>::value,
1294 "Not available with `bt2::ConstStreamClass`.");
1296 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1298 internal::validateCreatedObjPtr(libObjPtr);
1299 return Stream::Shared::createWithoutRef(libObjPtr);
1302 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1304 static_assert(!std::is_const<LibObjT>::value,
1305 "Not available with `bt2::ConstStreamClass`.");
1307 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1309 internal::validateCreatedObjPtr(libObjPtr);
1310 return Stream::Shared::createWithoutRef(libObjPtr);
1313 EventClass::Shared createEventClass() const
1315 static_assert(!std::is_const<LibObjT>::value,
1316 "Not available with `bt2::ConstStreamClass`.");
1318 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1320 internal::validateCreatedObjPtr(libObjPtr);
1321 return EventClass::Shared::createWithoutRef(libObjPtr);
1324 EventClass::Shared createEventClass(const std::uint64_t id) const
1326 static_assert(!std::is_const<LibObjT>::value,
1327 "Not available with `bt2::ConstStreamClass`.");
1329 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1331 internal::validateCreatedObjPtr(libObjPtr);
1332 return EventClass::Shared::createWithoutRef(libObjPtr);
1335 _TraceClass traceClass() const noexcept;
1337 std::uint64_t id() const noexcept
1339 return bt_stream_class_get_id(this->libObjPtr());
1342 void name(const char * const name) const
1344 static_assert(!std::is_const<LibObjT>::value,
1345 "Not available with `bt2::ConstStreamClass`.");
1347 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1349 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1350 throw MemoryError {};
1354 void name(const std::string& name) const
1356 this->name(name.data());
1359 const char *name() const noexcept
1361 return bt_stream_class_get_name(this->libObjPtr());
1364 void assignsAutomaticEventClassId(const bool val) const noexcept
1366 static_assert(!std::is_const<LibObjT>::value,
1367 "Not available with `bt2::ConstStreamClass`.");
1369 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1370 static_cast<bt_bool>(val));
1373 bool assignsAutomaticEventClassId() const noexcept
1375 return static_cast<bool>(
1376 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1379 void assignsAutomaticStreamId(const bool val) const noexcept
1381 static_assert(!std::is_const<LibObjT>::value,
1382 "Not available with `bt2::ConstStreamClass`.");
1384 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1385 static_cast<bt_bool>(val));
1388 bool assignsAutomaticStreamId() const noexcept
1390 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1393 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1394 const bool withEndDefaultClkSnapshot) const noexcept
1396 static_assert(!std::is_const<LibObjT>::value,
1397 "Not available with `bt2::ConstStreamClass`.");
1399 bt_stream_class_set_supports_packets(this->libObjPtr(),
1400 static_cast<bt_bool>(supportsPackets),
1401 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1402 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1405 bool supportsPackets() const noexcept
1407 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1410 bool packetsHaveBeginningClockSnapshot() const noexcept
1412 return static_cast<bool>(
1413 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1416 bool packetsHaveEndClockSnapshot() const noexcept
1418 return static_cast<bool>(
1419 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1422 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1423 const bool withDefaultClkSnapshots) const noexcept
1425 static_assert(!std::is_const<LibObjT>::value,
1426 "Not available with `bt2::ConstStreamClass`.");
1428 bt_stream_class_set_supports_discarded_events(
1429 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1430 static_cast<bt_bool>(withDefaultClkSnapshots));
1433 bool supportsDiscardedEvents() const noexcept
1435 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1438 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1440 return static_cast<bool>(
1441 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1444 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1445 const bool withDefaultClkSnapshots) const noexcept
1447 static_assert(!std::is_const<LibObjT>::value,
1448 "Not available with `bt2::ConstStreamClass`.");
1450 bt_stream_class_set_supports_discarded_packets(
1451 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1452 static_cast<bt_bool>(withDefaultClkSnapshots));
1455 bool supportsDiscardedPackets() const noexcept
1457 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1460 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1462 return static_cast<bool>(
1463 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1466 void defaultClockClass(const ClockClass clkCls) const
1468 static_assert(!std::is_const<LibObjT>::value,
1469 "Not available with `bt2::ConstStreamClass`.");
1472 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1474 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1477 nonstd::optional<_ClockClass> defaultClockClass() const noexcept
1479 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1482 return _ClockClass {libObjPtr};
1485 return nonstd::nullopt;
1488 std::uint64_t length() const noexcept
1490 return bt_stream_class_get_event_class_count(this->libObjPtr());
1493 _EventClass operator[](const std::uint64_t index) const noexcept
1495 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1498 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1500 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1503 return _EventClass {libObjPtr};
1506 return nonstd::nullopt;
1509 void packetContextFieldClass(const StructureFieldClass fc) const
1511 static_assert(!std::is_const<LibObjT>::value,
1512 "Not available with `bt2::ConstStreamClass`.");
1515 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1517 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1518 throw MemoryError {};
1522 nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
1524 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1527 return _StructureFieldClass {libObjPtr};
1530 return nonstd::nullopt;
1533 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1535 static_assert(!std::is_const<LibObjT>::value,
1536 "Not available with `bt2::ConstStreamClass`.");
1539 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1541 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1542 throw MemoryError {};
1546 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1548 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1551 return _StructureFieldClass {libObjPtr};
1554 return nonstd::nullopt;
1557 template <typename LibValT>
1558 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1560 static_assert(!std::is_const<LibObjT>::value,
1561 "Not available with `bt2::ConstStreamClass`.");
1563 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1566 UserAttributes userAttributes() const noexcept
1568 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1571 Shared shared() const noexcept
1573 return Shared::createWithRef(*this);
1577 using StreamClass = CommonStreamClass<bt_stream_class>;
1578 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1580 namespace internal {
1582 struct StreamClassTypeDescr
1584 using Const = ConstStreamClass;
1585 using NonConst = StreamClass;
1589 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1594 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1598 } /* namespace internal */
1600 template <typename LibObjT>
1601 typename CommonEventClass<LibObjT>::_StreamClass
1602 CommonEventClass<LibObjT>::streamClass() const noexcept
1604 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1607 template <typename LibObjT>
1608 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1610 return Class {_Spec::cls(this->libObjPtr())};
1613 namespace internal {
1615 struct TraceClassRefFuncs final
1617 static void get(const bt_trace_class * const libObjPtr) noexcept
1619 bt_trace_class_get_ref(libObjPtr);
1622 static void put(const bt_trace_class * const libObjPtr) noexcept
1624 bt_trace_class_put_ref(libObjPtr);
1628 template <typename LibObjT>
1629 struct CommonTraceClassSpec;
1631 /* Functions specific to mutable stream classes */
1633 struct CommonTraceClassSpec<bt_trace_class> final
1635 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1636 const std::uint64_t index) noexcept
1638 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1641 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1642 const std::uint64_t id) noexcept
1644 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1647 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1649 return bt_trace_class_borrow_user_attributes(libObjPtr);
1653 /* Functions specific to constant stream classes */
1655 struct CommonTraceClassSpec<const bt_trace_class> final
1657 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1658 const std::uint64_t index) noexcept
1660 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1663 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1664 const std::uint64_t id) noexcept
1666 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1669 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1671 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1675 } /* namespace internal */
1677 template <typename LibObjT>
1678 class CommonTraceClass final : public BorrowedObject<LibObjT>
1681 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1682 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1683 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1685 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1686 CommonStreamClass<const bt_stream_class>>;
1689 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1690 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1692 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1696 template <typename OtherLibObjT>
1697 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1698 _ThisBorrowedObject {traceClass}
1702 template <typename OtherLibObjT>
1703 CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1705 _ThisBorrowedObject::operator=(traceClass);
1709 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1711 return CommonTraceClass<const bt_trace_class> {*this};
1714 Trace::Shared instantiate() const
1716 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1718 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1720 internal::validateCreatedObjPtr(libObjPtr);
1721 return Trace::Shared::createWithoutRef(libObjPtr);
1724 StreamClass::Shared createStreamClass() const
1726 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1728 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1730 internal::validateCreatedObjPtr(libObjPtr);
1731 return StreamClass::Shared::createWithoutRef(libObjPtr);
1734 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1736 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1738 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1740 internal::validateCreatedObjPtr(libObjPtr);
1741 return StreamClass::Shared::createWithoutRef(libObjPtr);
1744 FieldClass::Shared createBoolFieldClass() const
1746 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1748 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1750 internal::validateCreatedObjPtr(libObjPtr);
1751 return FieldClass::Shared::createWithoutRef(libObjPtr);
1754 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1756 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1758 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1760 internal::validateCreatedObjPtr(libObjPtr);
1761 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1764 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1766 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1768 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1770 internal::validateCreatedObjPtr(libObjPtr);
1771 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1774 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1776 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1778 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1780 internal::validateCreatedObjPtr(libObjPtr);
1781 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1784 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1786 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1788 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1790 internal::validateCreatedObjPtr(libObjPtr);
1791 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1794 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1796 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1798 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1800 internal::validateCreatedObjPtr(libObjPtr);
1801 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1804 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1806 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1808 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1810 internal::validateCreatedObjPtr(libObjPtr);
1811 return FieldClass::Shared::createWithoutRef(libObjPtr);
1814 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1816 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1818 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1820 internal::validateCreatedObjPtr(libObjPtr);
1821 return FieldClass::Shared::createWithoutRef(libObjPtr);
1824 FieldClass::Shared createStringFieldClass() const
1826 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1828 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1830 internal::validateCreatedObjPtr(libObjPtr);
1831 return FieldClass::Shared::createWithoutRef(libObjPtr);
1834 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1835 const std::uint64_t length) const
1837 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1839 const auto libObjPtr = bt_field_class_array_static_create(
1840 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1842 internal::validateCreatedObjPtr(libObjPtr);
1843 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1846 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1848 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1850 const auto libObjPtr = bt_field_class_array_dynamic_create(
1851 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1853 internal::validateCreatedObjPtr(libObjPtr);
1854 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1857 DynamicArrayWithLengthFieldClass::Shared
1858 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1859 const IntegerFieldClass lengthFieldClass) const
1861 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1863 const auto libObjPtr = bt_field_class_array_dynamic_create(
1864 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1866 internal::validateCreatedObjPtr(libObjPtr);
1867 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1870 StructureFieldClass::Shared createStructureFieldClass() const
1872 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1874 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1876 internal::validateCreatedObjPtr(libObjPtr);
1877 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1880 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1882 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1884 const auto libObjPtr = bt_field_class_option_without_selector_create(
1885 this->libObjPtr(), optionalFieldClass.libObjPtr());
1887 internal::validateCreatedObjPtr(libObjPtr);
1888 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1891 OptionWithBoolSelectorFieldClass::Shared
1892 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1893 const FieldClass selectorFieldClass) const
1895 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1897 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1898 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1900 internal::validateCreatedObjPtr(libObjPtr);
1901 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1904 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1905 createOptionWithUnsignedIntegerSelectorFieldClass(
1906 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1907 const ConstUnsignedIntegerRangeSet ranges) const
1909 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1911 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1912 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1913 ranges.libObjPtr());
1915 internal::validateCreatedObjPtr(libObjPtr);
1916 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1919 OptionWithSignedIntegerSelectorFieldClass::Shared
1920 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1921 const IntegerFieldClass selectorFieldClass,
1922 const ConstSignedIntegerRangeSet ranges) const
1924 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1926 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1927 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1928 ranges.libObjPtr());
1930 internal::validateCreatedObjPtr(libObjPtr);
1931 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1934 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1936 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1938 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1940 internal::validateCreatedObjPtr(libObjPtr);
1941 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1944 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1945 createVariantWithUnsignedIntegerSelectorFieldClass(
1946 const IntegerFieldClass selectorFieldClass) const
1948 return this->_createVariantWithIntegerSelectorFieldClass<
1949 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1952 VariantWithSignedIntegerSelectorFieldClass::Shared
1953 createVariantWithSignedIntegerSelectorFieldClass(
1954 const IntegerFieldClass selectorFieldClass) const
1956 return this->_createVariantWithIntegerSelectorFieldClass<
1957 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
1960 void assignsAutomaticStreamClassId(const bool val) const noexcept
1962 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1964 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
1965 static_cast<bt_bool>(val));
1968 bool assignsAutomaticStreamClassId() const noexcept
1970 return static_cast<bool>(
1971 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
1974 std::uint64_t length() const noexcept
1976 return bt_trace_class_get_stream_class_count(this->libObjPtr());
1979 _StreamClass operator[](const std::uint64_t index) const noexcept
1981 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
1984 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
1986 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
1989 return _StreamClass {libObjPtr};
1992 return nonstd::nullopt;
1995 template <typename LibValT>
1996 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1998 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2000 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2003 UserAttributes userAttributes() const noexcept
2005 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2008 Shared shared() const noexcept
2010 return Shared::createWithRef(*this);
2014 template <typename ObjT>
2015 typename ObjT::Shared
2016 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
2018 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2020 const auto libObjPtr =
2021 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2023 internal::validateCreatedObjPtr(libObjPtr);
2024 return ObjT::Shared::createWithoutRef(libObjPtr);
2028 using TraceClass = CommonTraceClass<bt_trace_class>;
2029 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2031 namespace internal {
2033 struct TraceClassTypeDescr
2035 using Const = ConstTraceClass;
2036 using NonConst = TraceClass;
2040 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2045 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2049 } /* namespace internal */
2051 template <typename LibObjT>
2052 typename CommonStreamClass<LibObjT>::_TraceClass
2053 CommonStreamClass<LibObjT>::traceClass() const noexcept
2055 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2058 template <typename LibObjT>
2059 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
2061 return Class {_Spec::cls(this->libObjPtr())};
2064 } /* namespace bt2 */
2066 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */