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 "common/macros.h"
16 #include "cpp-common/bt2c/c-string-view.hpp"
17 #include "cpp-common/bt2s/optional.hpp"
19 #include "borrowed-object.hpp"
20 #include "clock-class.hpp"
21 #include "field-class.hpp"
23 #include "internal/utils.hpp"
24 #include "optional-borrowed-object.hpp"
25 #include "shared-object.hpp"
30 template <typename LibObjT>
33 template <typename LibObjT>
36 template <typename LibObjT>
39 template <typename LibObjT>
42 template <typename LibObjT>
43 class CommonEventClass;
45 template <typename LibObjT>
46 class CommonStreamClass;
48 template <typename LibObjT>
49 class CommonTraceClass;
53 template <typename LibObjT>
54 struct CommonEventSpec;
56 /* Functions specific to mutable events */
58 struct CommonEventSpec<bt_event> final
60 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
62 return bt_event_borrow_class(libObjPtr);
65 static bt_stream *stream(bt_event * const libObjPtr) noexcept
67 return bt_event_borrow_stream(libObjPtr);
70 static bt_packet *packet(bt_event * const libObjPtr) noexcept
72 return bt_event_borrow_packet(libObjPtr);
75 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
77 return bt_event_borrow_payload_field(libObjPtr);
80 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
82 return bt_event_borrow_specific_context_field(libObjPtr);
85 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
87 return bt_event_borrow_common_context_field(libObjPtr);
91 /* Functions specific to constant events */
93 struct CommonEventSpec<const bt_event> final
95 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
97 return bt_event_borrow_class_const(libObjPtr);
100 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
102 return bt_event_borrow_stream_const(libObjPtr);
105 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
107 return bt_event_borrow_packet_const(libObjPtr);
110 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
112 return bt_event_borrow_payload_field_const(libObjPtr);
115 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
117 return bt_event_borrow_specific_context_field_const(libObjPtr);
120 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
122 return bt_event_borrow_common_context_field_const(libObjPtr);
126 template <typename LibObjT>
127 using DepStructField = DepType<LibObjT, StructureField, ConstStructureField>;
129 } /* namespace internal */
131 template <typename LibObjT>
132 class CommonEvent final : public BorrowedObject<LibObjT>
135 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
136 using _Spec = internal::CommonEventSpec<LibObjT>;
137 using _Packet = internal::DepPacket<LibObjT>;
138 using _Stream = internal::DepStream<LibObjT>;
139 using _StructureField = internal::DepStructField<LibObjT>;
142 using typename BorrowedObject<LibObjT>::LibObjPtr;
144 using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
145 CommonEventClass<const bt_event_class>>;
147 explicit CommonEvent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
151 template <typename OtherLibObjT>
152 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
156 template <typename OtherLibObjT>
157 CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept
159 _ThisBorrowedObject::operator=(event);
163 CommonEvent<const bt_event> asConst() const noexcept
165 return CommonEvent<const bt_event> {*this};
168 Class cls() const noexcept;
169 _Stream stream() const noexcept;
170 OptionalBorrowedObject<_Packet> packet() const noexcept;
172 OptionalBorrowedObject<_StructureField> payloadField() const noexcept
174 return _Spec::payloadField(this->libObjPtr());
177 OptionalBorrowedObject<_StructureField> specificContextField() const noexcept
179 return _Spec::specificContextField(this->libObjPtr());
182 OptionalBorrowedObject<_StructureField> commonContextField() const noexcept
184 return _Spec::commonContextField(this->libObjPtr());
188 using Event = CommonEvent<bt_event>;
189 using ConstEvent = CommonEvent<const bt_event>;
193 struct EventTypeDescr
195 using Const = ConstEvent;
196 using NonConst = Event;
200 struct TypeDescr<Event> : public EventTypeDescr
205 struct TypeDescr<ConstEvent> : public EventTypeDescr
209 struct PacketRefFuncs final
211 static void get(const bt_packet * const libObjPtr) noexcept
213 bt_packet_get_ref(libObjPtr);
216 static void put(const bt_packet * const libObjPtr) noexcept
218 bt_packet_put_ref(libObjPtr);
222 template <typename LibObjT>
223 struct CommonPacketSpec;
225 /* Functions specific to mutable packets */
227 struct CommonPacketSpec<bt_packet> final
229 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
231 return bt_packet_borrow_stream(libObjPtr);
234 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
236 return bt_packet_borrow_context_field(libObjPtr);
240 /* Functions specific to constant packets */
242 struct CommonPacketSpec<const bt_packet> final
244 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
246 return bt_packet_borrow_stream_const(libObjPtr);
249 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
251 return bt_packet_borrow_context_field_const(libObjPtr);
255 } /* namespace internal */
257 template <typename LibObjT>
258 class CommonPacket final : public BorrowedObject<LibObjT>
261 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
262 using _Spec = internal::CommonPacketSpec<LibObjT>;
263 using _Stream = internal::DepStream<LibObjT>;
264 using _StructureField = internal::DepStructField<LibObjT>;
267 using typename BorrowedObject<LibObjT>::LibObjPtr;
268 using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
270 explicit CommonPacket(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
274 template <typename OtherLibObjT>
275 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
279 template <typename OtherLibObjT>
280 CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept
282 _ThisBorrowedObject::operator=(packet);
286 CommonPacket<const bt_packet> asConst() const noexcept
288 return CommonPacket<const bt_packet> {*this};
291 _Stream stream() const noexcept;
293 OptionalBorrowedObject<_StructureField> contextField() const noexcept
295 return _Spec::contextField(this->libObjPtr());
298 Shared shared() const noexcept
300 return Shared::createWithRef(*this);
304 using Packet = CommonPacket<bt_packet>;
305 using ConstPacket = CommonPacket<const bt_packet>;
309 struct PacketTypeDescr
311 using Const = ConstPacket;
312 using NonConst = Packet;
316 struct TypeDescr<Packet> : public PacketTypeDescr
321 struct TypeDescr<ConstPacket> : public PacketTypeDescr
325 } /* namespace internal */
327 template <typename LibObjT>
328 OptionalBorrowedObject<typename CommonEvent<LibObjT>::_Packet>
329 CommonEvent<LibObjT>::packet() const noexcept
331 return _Spec::packet(this->libObjPtr());
336 struct StreamRefFuncs final
338 static void get(const bt_stream * const libObjPtr) noexcept
340 bt_stream_get_ref(libObjPtr);
343 static void put(const bt_stream * const libObjPtr) noexcept
345 bt_stream_put_ref(libObjPtr);
349 template <typename LibObjT>
350 struct CommonStreamSpec;
352 /* Functions specific to mutable streams */
354 struct CommonStreamSpec<bt_stream> final
356 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
358 return bt_stream_borrow_class(libObjPtr);
361 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
363 return bt_stream_borrow_trace(libObjPtr);
366 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
368 return bt_stream_borrow_user_attributes(libObjPtr);
372 /* Functions specific to constant streams */
374 struct CommonStreamSpec<const bt_stream> final
376 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
378 return bt_stream_borrow_class_const(libObjPtr);
381 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
383 return bt_stream_borrow_trace_const(libObjPtr);
386 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
388 return bt_stream_borrow_user_attributes_const(libObjPtr);
392 } /* namespace internal */
394 template <typename LibObjT>
395 class CommonStream final : public BorrowedObject<LibObjT>
398 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
399 using _Spec = internal::CommonStreamSpec<LibObjT>;
400 using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
403 using typename BorrowedObject<LibObjT>::LibObjPtr;
404 using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
405 using UserAttributes = internal::DepUserAttrs<LibObjT>;
407 using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
408 CommonStreamClass<const bt_stream_class>>;
410 explicit CommonStream(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
414 template <typename OtherLibObjT>
415 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
419 template <typename OtherLibObjT>
420 CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept
422 _ThisBorrowedObject::operator=(stream);
426 CommonStream<const bt_stream> asConst() const noexcept
428 return CommonStream<const bt_stream> {*this};
431 Packet::Shared createPacket() const
433 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
435 const auto libObjPtr = bt_packet_create(this->libObjPtr());
437 internal::validateCreatedObjPtr(libObjPtr);
438 return Packet::Shared::createWithoutRef(libObjPtr);
441 Class cls() const noexcept;
442 _Trace trace() const noexcept;
444 std::uint64_t id() const noexcept
446 return bt_stream_get_id(this->libObjPtr());
449 CommonStream name(const bt2c::CStringView name) const
451 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
453 const auto status = bt_stream_set_name(this->libObjPtr(), name);
455 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
456 throw MemoryError {};
462 bt2c::CStringView name() const noexcept
464 return bt_stream_get_name(this->libObjPtr());
467 template <typename LibValT>
468 CommonStream userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
470 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
472 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
476 UserAttributes userAttributes() const noexcept
478 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
481 Shared shared() const noexcept
483 return Shared::createWithRef(*this);
487 using Stream = CommonStream<bt_stream>;
488 using ConstStream = CommonStream<const bt_stream>;
492 struct StreamTypeDescr
494 using Const = ConstStream;
495 using NonConst = Stream;
499 struct TypeDescr<Stream> : public StreamTypeDescr
504 struct TypeDescr<ConstStream> : public StreamTypeDescr
508 } /* namespace internal */
510 template <typename LibObjT>
511 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
513 return _Stream {_Spec::stream(this->libObjPtr())};
516 template <typename LibObjT>
517 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
519 return _Stream {_Spec::stream(this->libObjPtr())};
524 struct TraceRefFuncs final
526 static void get(const bt_trace * const libObjPtr) noexcept
528 bt_trace_get_ref(libObjPtr);
531 static void put(const bt_trace * const libObjPtr) noexcept
533 bt_trace_put_ref(libObjPtr);
537 template <typename LibObjT>
538 struct CommonTraceSpec;
540 /* Functions specific to mutable traces */
542 struct CommonTraceSpec<bt_trace> final
544 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
546 return bt_trace_borrow_class(libObjPtr);
549 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
551 return bt_trace_borrow_stream_by_index(libObjPtr, index);
554 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
556 return bt_trace_borrow_stream_by_id(libObjPtr, id);
559 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
561 return bt_trace_borrow_user_attributes(libObjPtr);
565 /* Functions specific to constant traces */
567 struct CommonTraceSpec<const bt_trace> final
569 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
571 return bt_trace_borrow_class_const(libObjPtr);
574 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
575 const std::uint64_t index) noexcept
577 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
580 static const bt_stream *streamById(const bt_trace * const libObjPtr,
581 const std::uint64_t id) noexcept
583 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
586 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
588 return bt_trace_borrow_user_attributes_const(libObjPtr);
592 } /* namespace internal */
594 template <typename LibObjT>
595 class CommonTrace final : public BorrowedObject<LibObjT>
598 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
599 using _Spec = internal::CommonTraceSpec<LibObjT>;
600 using _Stream = internal::DepStream<LibObjT>;
603 using typename BorrowedObject<LibObjT>::LibObjPtr;
604 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
605 using UserAttributes = internal::DepUserAttrs<LibObjT>;
607 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
608 CommonTraceClass<const bt_trace_class>>;
610 struct ConstEnvironmentEntry
612 bt2c::CStringView name;
616 explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
620 template <typename OtherLibObjT>
621 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
625 template <typename OtherLibObjT>
626 CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
628 _ThisBorrowedObject::operator=(trace);
632 CommonTrace<const bt_trace> asConst() const noexcept
634 return CommonTrace<const bt_trace> {*this};
637 Class cls() const noexcept;
639 CommonTrace name(const bt2c::CStringView name) const
641 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
643 const auto status = bt_trace_set_name(this->libObjPtr(), name);
645 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
646 throw MemoryError {};
652 bt2c::CStringView name() const noexcept
654 return bt_trace_get_name(this->libObjPtr());
657 CommonTrace uuid(const bt2c::UuidView& uuid) const noexcept
659 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
663 bt2s::optional<bt2c::UuidView> uuid() const noexcept
665 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
668 return bt2c::UuidView {uuid};
671 return bt2s::nullopt;
674 std::uint64_t length() const noexcept
676 return bt_trace_get_stream_count(this->libObjPtr());
679 _Stream operator[](const std::uint64_t index) const noexcept
681 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
684 OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
686 return _Spec::streamById(this->libObjPtr(), id);
689 CommonTrace environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
691 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
693 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
695 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
696 throw MemoryError {};
702 CommonTrace environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
704 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
706 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
708 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
709 throw MemoryError {};
715 std::uint64_t environmentSize() const noexcept
717 return bt_trace_get_environment_entry_count(this->libObjPtr());
720 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
723 const bt_value *libObjPtr;
725 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
727 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
730 OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
732 return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
735 template <typename LibValT>
736 CommonTrace userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
738 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
740 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
744 UserAttributes userAttributes() const noexcept
746 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
749 Shared shared() const noexcept
751 return Shared::createWithRef(*this);
755 using Trace = CommonTrace<bt_trace>;
756 using ConstTrace = CommonTrace<const bt_trace>;
760 struct TraceTypeDescr
762 using Const = ConstTrace;
763 using NonConst = Trace;
767 struct TypeDescr<Trace> : public TraceTypeDescr
772 struct TypeDescr<ConstTrace> : public TraceTypeDescr
776 } /* namespace internal */
778 template <typename LibObjT>
779 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
781 return _Trace {_Spec::trace(this->libObjPtr())};
786 struct EventClassRefFuncs final
788 static void get(const bt_event_class * const libObjPtr) noexcept
790 bt_event_class_get_ref(libObjPtr);
793 static void put(const bt_event_class * const libObjPtr) noexcept
795 bt_event_class_put_ref(libObjPtr);
799 template <typename LibObjT>
800 struct CommonEventClassSpec;
802 /* Functions specific to mutable event classes */
804 struct CommonEventClassSpec<bt_event_class> final
806 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
808 return bt_event_class_borrow_stream_class(libObjPtr);
811 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
813 return bt_event_class_borrow_payload_field_class(libObjPtr);
816 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
818 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
821 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
823 return bt_event_class_borrow_user_attributes(libObjPtr);
827 /* Functions specific to constant event classes */
829 struct CommonEventClassSpec<const bt_event_class> final
831 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
833 return bt_event_class_borrow_stream_class_const(libObjPtr);
836 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
838 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
841 static const bt_field_class *
842 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
844 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
847 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
849 return bt_event_class_borrow_user_attributes_const(libObjPtr);
853 template <typename LibObjT>
854 using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
856 } /* namespace internal */
858 template <typename LibObjT>
859 class CommonEventClass final : public BorrowedObject<LibObjT>
862 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
863 using _Spec = internal::CommonEventClassSpec<LibObjT>;
864 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
866 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
867 CommonStreamClass<const bt_stream_class>>;
870 using typename BorrowedObject<LibObjT>::LibObjPtr;
871 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
872 using UserAttributes = internal::DepUserAttrs<LibObjT>;
874 /* Avoid `-Wshadow` error on GCC, conflicting with `bt2::Error` */
876 BT_DIAG_IGNORE_SHADOW
880 Emergency = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
881 Alert = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
882 Critical = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
883 Error = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
884 Warning = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
885 Notice = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
886 Info = BT_EVENT_CLASS_LOG_LEVEL_INFO,
887 DebugSystem = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
888 DebugProgram = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
889 DebugProcess = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
890 DebugModule = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
891 DebugUnit = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
892 DebugFunction = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
893 DebugLine = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
894 Debug = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
899 explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
903 template <typename OtherLibObjT>
904 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
905 _ThisBorrowedObject {eventClass}
909 template <typename OtherLibObjT>
910 CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
912 _ThisBorrowedObject::operator=(eventClass);
916 CommonEventClass<const bt_event_class> asConst() const noexcept
918 return CommonEventClass<const bt_event_class> {*this};
921 _StreamClass streamClass() const noexcept;
923 std::uint64_t id() const noexcept
925 return bt_event_class_get_id(this->libObjPtr());
928 CommonEventClass name(const bt2c::CStringView name) const
930 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
932 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
934 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
935 throw MemoryError {};
941 bt2c::CStringView name() const noexcept
943 return bt_event_class_get_name(this->libObjPtr());
946 CommonEventClass logLevel(const LogLevel logLevel) const noexcept
948 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
950 bt_event_class_set_log_level(this->libObjPtr(),
951 static_cast<bt_event_class_log_level>(logLevel));
955 bt2s::optional<LogLevel> logLevel() const noexcept
957 bt_event_class_log_level libLogLevel;
959 if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
960 return static_cast<LogLevel>(libLogLevel);
963 return bt2s::nullopt;
966 CommonEventClass emfUri(const bt2c::CStringView emfUri) const
968 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
970 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
972 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
973 throw MemoryError {};
979 bt2c::CStringView emfUri() const noexcept
981 return bt_event_class_get_emf_uri(this->libObjPtr());
984 CommonEventClass payloadFieldClass(const StructureFieldClass fc) const
986 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
989 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
991 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
992 throw MemoryError {};
998 OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
1000 return _Spec::payloadFieldClass(this->libObjPtr());
1003 CommonEventClass specificContextFieldClass(const StructureFieldClass fc) const
1005 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1008 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1010 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1011 throw MemoryError {};
1017 OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
1019 return _Spec::specificContextFieldClass(this->libObjPtr());
1022 template <typename LibValT>
1023 CommonEventClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1025 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1027 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1031 UserAttributes userAttributes() const noexcept
1033 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1036 Shared shared() const noexcept
1038 return Shared::createWithRef(*this);
1042 using EventClass = CommonEventClass<bt_event_class>;
1043 using ConstEventClass = CommonEventClass<const bt_event_class>;
1045 namespace internal {
1047 struct EventClassTypeDescr
1049 using Const = ConstEventClass;
1050 using NonConst = EventClass;
1054 struct TypeDescr<EventClass> : public EventClassTypeDescr
1059 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1063 } /* namespace internal */
1065 template <typename LibObjT>
1066 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1068 return Class {_Spec::cls(this->libObjPtr())};
1071 namespace internal {
1073 struct StreamClassRefFuncs final
1075 static void get(const bt_stream_class * const libObjPtr) noexcept
1077 bt_stream_class_get_ref(libObjPtr);
1080 static void put(const bt_stream_class * const libObjPtr) noexcept
1082 bt_stream_class_put_ref(libObjPtr);
1086 template <typename LibObjT>
1087 struct CommonStreamClassSpec;
1089 /* Functions specific to mutable stream classes */
1091 struct CommonStreamClassSpec<bt_stream_class> final
1093 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1095 return bt_stream_class_borrow_trace_class(libObjPtr);
1098 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1099 const std::uint64_t index) noexcept
1101 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1104 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1105 const std::uint64_t id) noexcept
1107 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1110 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1112 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1115 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1117 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1120 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1122 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1125 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1127 return bt_stream_class_borrow_user_attributes(libObjPtr);
1131 /* Functions specific to constant stream classes */
1133 struct CommonStreamClassSpec<const bt_stream_class> final
1135 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1137 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1140 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1141 const std::uint64_t index) noexcept
1143 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1146 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1147 const std::uint64_t id) noexcept
1149 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1152 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1154 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1157 static const bt_field_class *
1158 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1160 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1163 static const bt_field_class *
1164 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1166 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1169 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1171 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1175 } /* namespace internal */
1177 template <typename LibObjT>
1178 class CommonStreamClass final : public BorrowedObject<LibObjT>
1181 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1182 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1183 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
1185 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1186 CommonTraceClass<const bt_trace_class>>;
1188 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1189 CommonEventClass<const bt_event_class>>;
1191 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
1194 using typename BorrowedObject<LibObjT>::LibObjPtr;
1195 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1196 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1198 explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1202 template <typename OtherLibObjT>
1203 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1204 _ThisBorrowedObject {streamClass}
1208 template <typename OtherLibObjT>
1209 CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1211 _ThisBorrowedObject::operator=(streamClass);
1215 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1217 return CommonStreamClass<const bt_stream_class> {*this};
1220 Stream::Shared instantiate(const Trace trace) const
1222 static_assert(!std::is_const<LibObjT>::value,
1223 "Not available with `bt2::ConstStreamClass`.");
1225 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1227 internal::validateCreatedObjPtr(libObjPtr);
1228 return Stream::Shared::createWithoutRef(libObjPtr);
1231 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1233 static_assert(!std::is_const<LibObjT>::value,
1234 "Not available with `bt2::ConstStreamClass`.");
1236 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1238 internal::validateCreatedObjPtr(libObjPtr);
1239 return Stream::Shared::createWithoutRef(libObjPtr);
1242 EventClass::Shared createEventClass() const
1244 static_assert(!std::is_const<LibObjT>::value,
1245 "Not available with `bt2::ConstStreamClass`.");
1247 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1249 internal::validateCreatedObjPtr(libObjPtr);
1250 return EventClass::Shared::createWithoutRef(libObjPtr);
1253 EventClass::Shared createEventClass(const std::uint64_t id) const
1255 static_assert(!std::is_const<LibObjT>::value,
1256 "Not available with `bt2::ConstStreamClass`.");
1258 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1260 internal::validateCreatedObjPtr(libObjPtr);
1261 return EventClass::Shared::createWithoutRef(libObjPtr);
1264 _TraceClass traceClass() const noexcept;
1266 std::uint64_t id() const noexcept
1268 return bt_stream_class_get_id(this->libObjPtr());
1271 CommonStreamClass name(const bt2c::CStringView name) const
1273 static_assert(!std::is_const<LibObjT>::value,
1274 "Not available with `bt2::ConstStreamClass`.");
1276 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1278 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1279 throw MemoryError {};
1285 bt2c::CStringView name() const noexcept
1287 return bt_stream_class_get_name(this->libObjPtr());
1290 CommonStreamClass assignsAutomaticEventClassId(const bool val) const noexcept
1292 static_assert(!std::is_const<LibObjT>::value,
1293 "Not available with `bt2::ConstStreamClass`.");
1295 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1296 static_cast<bt_bool>(val));
1300 bool assignsAutomaticEventClassId() const noexcept
1302 return static_cast<bool>(
1303 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1306 CommonStreamClass assignsAutomaticStreamId(const bool val) const noexcept
1308 static_assert(!std::is_const<LibObjT>::value,
1309 "Not available with `bt2::ConstStreamClass`.");
1311 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1312 static_cast<bt_bool>(val));
1316 bool assignsAutomaticStreamId() const noexcept
1318 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1321 CommonStreamClass supportsPackets(const bool supportsPackets,
1322 const bool withBeginningDefaultClkSnapshot,
1323 const bool withEndDefaultClkSnapshot) const noexcept
1325 static_assert(!std::is_const<LibObjT>::value,
1326 "Not available with `bt2::ConstStreamClass`.");
1328 bt_stream_class_set_supports_packets(this->libObjPtr(),
1329 static_cast<bt_bool>(supportsPackets),
1330 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1331 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1335 bool supportsPackets() const noexcept
1337 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1340 bool packetsHaveBeginningClockSnapshot() const noexcept
1342 return static_cast<bool>(
1343 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1346 bool packetsHaveEndClockSnapshot() const noexcept
1348 return static_cast<bool>(
1349 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1352 CommonStreamClass supportsDiscardedEvents(const bool supportsDiscardedEvents,
1353 const bool withDefaultClkSnapshots) const noexcept
1355 static_assert(!std::is_const<LibObjT>::value,
1356 "Not available with `bt2::ConstStreamClass`.");
1358 bt_stream_class_set_supports_discarded_events(
1359 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1360 static_cast<bt_bool>(withDefaultClkSnapshots));
1364 bool supportsDiscardedEvents() const noexcept
1366 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1369 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1371 return static_cast<bool>(
1372 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1375 CommonStreamClass supportsDiscardedPackets(const bool supportsDiscardedPackets,
1376 const bool withDefaultClkSnapshots) const noexcept
1378 static_assert(!std::is_const<LibObjT>::value,
1379 "Not available with `bt2::ConstStreamClass`.");
1381 bt_stream_class_set_supports_discarded_packets(
1382 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1383 static_cast<bt_bool>(withDefaultClkSnapshots));
1387 bool supportsDiscardedPackets() const noexcept
1389 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1392 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1394 return static_cast<bool>(
1395 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1398 CommonStreamClass defaultClockClass(const ClockClass clkCls) const
1400 static_assert(!std::is_const<LibObjT>::value,
1401 "Not available with `bt2::ConstStreamClass`.");
1404 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1406 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1410 OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
1412 return _Spec::defaultClockClass(this->libObjPtr());
1415 std::uint64_t length() const noexcept
1417 return bt_stream_class_get_event_class_count(this->libObjPtr());
1420 _EventClass operator[](const std::uint64_t index) const noexcept
1422 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1425 OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1427 return _Spec::eventClassById(this->libObjPtr(), id);
1430 CommonStreamClass packetContextFieldClass(const StructureFieldClass fc) const
1432 static_assert(!std::is_const<LibObjT>::value,
1433 "Not available with `bt2::ConstStreamClass`.");
1436 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1438 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1439 throw MemoryError {};
1445 OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
1447 return _Spec::packetContextFieldClass(this->libObjPtr());
1450 CommonStreamClass eventCommonContextFieldClass(const StructureFieldClass fc) const
1452 static_assert(!std::is_const<LibObjT>::value,
1453 "Not available with `bt2::ConstStreamClass`.");
1456 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1458 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1459 throw MemoryError {};
1465 OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1467 return _Spec::eventCommonContextFieldClass(this->libObjPtr());
1470 template <typename LibValT>
1471 CommonStreamClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1473 static_assert(!std::is_const<LibObjT>::value,
1474 "Not available with `bt2::ConstStreamClass`.");
1476 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1480 UserAttributes userAttributes() const noexcept
1482 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1485 Shared shared() const noexcept
1487 return Shared::createWithRef(*this);
1491 using StreamClass = CommonStreamClass<bt_stream_class>;
1492 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1494 namespace internal {
1496 struct StreamClassTypeDescr
1498 using Const = ConstStreamClass;
1499 using NonConst = StreamClass;
1503 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1508 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1512 } /* namespace internal */
1514 template <typename LibObjT>
1515 typename CommonEventClass<LibObjT>::_StreamClass
1516 CommonEventClass<LibObjT>::streamClass() const noexcept
1518 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1521 template <typename LibObjT>
1522 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1524 return Class {_Spec::cls(this->libObjPtr())};
1527 namespace internal {
1529 struct TraceClassRefFuncs final
1531 static void get(const bt_trace_class * const libObjPtr) noexcept
1533 bt_trace_class_get_ref(libObjPtr);
1536 static void put(const bt_trace_class * const libObjPtr) noexcept
1538 bt_trace_class_put_ref(libObjPtr);
1542 template <typename LibObjT>
1543 struct CommonTraceClassSpec;
1545 /* Functions specific to mutable stream classes */
1547 struct CommonTraceClassSpec<bt_trace_class> final
1549 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1550 const std::uint64_t index) noexcept
1552 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1555 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1556 const std::uint64_t id) noexcept
1558 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1561 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1563 return bt_trace_class_borrow_user_attributes(libObjPtr);
1567 /* Functions specific to constant stream classes */
1569 struct CommonTraceClassSpec<const bt_trace_class> final
1571 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1572 const std::uint64_t index) noexcept
1574 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1577 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1578 const std::uint64_t id) noexcept
1580 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1583 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1585 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1589 } /* namespace internal */
1591 template <typename LibObjT>
1592 class CommonTraceClass final : public BorrowedObject<LibObjT>
1595 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1597 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1599 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1600 CommonStreamClass<const bt_stream_class>>;
1603 using typename BorrowedObject<LibObjT>::LibObjPtr;
1604 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1605 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1607 explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1611 template <typename OtherLibObjT>
1612 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1613 _ThisBorrowedObject {traceClass}
1617 template <typename OtherLibObjT>
1618 CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1620 _ThisBorrowedObject::operator=(traceClass);
1624 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1626 return CommonTraceClass<const bt_trace_class> {*this};
1629 Trace::Shared instantiate() const
1631 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1633 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1635 internal::validateCreatedObjPtr(libObjPtr);
1636 return Trace::Shared::createWithoutRef(libObjPtr);
1639 StreamClass::Shared createStreamClass() const
1641 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1643 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1645 internal::validateCreatedObjPtr(libObjPtr);
1646 return StreamClass::Shared::createWithoutRef(libObjPtr);
1649 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1651 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1653 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1655 internal::validateCreatedObjPtr(libObjPtr);
1656 return StreamClass::Shared::createWithoutRef(libObjPtr);
1659 FieldClass::Shared createBoolFieldClass() const
1661 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1663 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1665 internal::validateCreatedObjPtr(libObjPtr);
1666 return FieldClass::Shared::createWithoutRef(libObjPtr);
1669 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1671 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1673 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1675 internal::validateCreatedObjPtr(libObjPtr);
1676 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1679 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1681 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1683 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1685 internal::validateCreatedObjPtr(libObjPtr);
1686 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1689 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1691 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1693 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1695 internal::validateCreatedObjPtr(libObjPtr);
1696 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1699 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1701 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1703 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1705 internal::validateCreatedObjPtr(libObjPtr);
1706 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1709 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1711 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1713 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1715 internal::validateCreatedObjPtr(libObjPtr);
1716 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1719 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1721 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1723 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1725 internal::validateCreatedObjPtr(libObjPtr);
1726 return FieldClass::Shared::createWithoutRef(libObjPtr);
1729 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1731 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1733 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1735 internal::validateCreatedObjPtr(libObjPtr);
1736 return FieldClass::Shared::createWithoutRef(libObjPtr);
1739 FieldClass::Shared createStringFieldClass() const
1741 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1743 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1745 internal::validateCreatedObjPtr(libObjPtr);
1746 return FieldClass::Shared::createWithoutRef(libObjPtr);
1749 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1750 const std::uint64_t length) const
1752 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1754 const auto libObjPtr = bt_field_class_array_static_create(
1755 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1757 internal::validateCreatedObjPtr(libObjPtr);
1758 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1761 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1763 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1765 const auto libObjPtr = bt_field_class_array_dynamic_create(
1766 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1768 internal::validateCreatedObjPtr(libObjPtr);
1769 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1772 DynamicArrayWithLengthFieldClass::Shared
1773 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1774 const IntegerFieldClass lengthFieldClass) const
1776 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1778 const auto libObjPtr = bt_field_class_array_dynamic_create(
1779 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1781 internal::validateCreatedObjPtr(libObjPtr);
1782 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1785 StructureFieldClass::Shared createStructureFieldClass() const
1787 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1789 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1791 internal::validateCreatedObjPtr(libObjPtr);
1792 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1795 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1797 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1799 const auto libObjPtr = bt_field_class_option_without_selector_create(
1800 this->libObjPtr(), optionalFieldClass.libObjPtr());
1802 internal::validateCreatedObjPtr(libObjPtr);
1803 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1806 OptionWithBoolSelectorFieldClass::Shared
1807 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1808 const FieldClass selectorFieldClass) const
1810 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1812 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1813 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1815 internal::validateCreatedObjPtr(libObjPtr);
1816 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1819 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1820 createOptionWithUnsignedIntegerSelectorFieldClass(
1821 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1822 const ConstUnsignedIntegerRangeSet ranges) const
1824 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1826 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1827 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1828 ranges.libObjPtr());
1830 internal::validateCreatedObjPtr(libObjPtr);
1831 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1834 OptionWithSignedIntegerSelectorFieldClass::Shared
1835 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1836 const IntegerFieldClass selectorFieldClass,
1837 const ConstSignedIntegerRangeSet ranges) const
1839 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1841 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1842 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1843 ranges.libObjPtr());
1845 internal::validateCreatedObjPtr(libObjPtr);
1846 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1849 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1851 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1853 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1855 internal::validateCreatedObjPtr(libObjPtr);
1856 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1859 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1860 createVariantWithUnsignedIntegerSelectorFieldClass(
1861 const IntegerFieldClass selectorFieldClass) const
1863 return this->_createVariantWithIntegerSelectorFieldClass<
1864 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1867 VariantWithSignedIntegerSelectorFieldClass::Shared
1868 createVariantWithSignedIntegerSelectorFieldClass(
1869 const IntegerFieldClass selectorFieldClass) const
1871 return this->_createVariantWithIntegerSelectorFieldClass<
1872 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
1875 CommonTraceClass assignsAutomaticStreamClassId(const bool val) const noexcept
1877 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1879 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
1880 static_cast<bt_bool>(val));
1884 bool assignsAutomaticStreamClassId() const noexcept
1886 return static_cast<bool>(
1887 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
1890 std::uint64_t length() const noexcept
1892 return bt_trace_class_get_stream_class_count(this->libObjPtr());
1895 _StreamClass operator[](const std::uint64_t index) const noexcept
1897 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
1900 OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
1902 return _Spec::streamClassById(this->libObjPtr(), id);
1905 template <typename LibValT>
1906 CommonTraceClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1908 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1910 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1914 UserAttributes userAttributes() const noexcept
1916 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1919 Shared shared() const noexcept
1921 return Shared::createWithRef(*this);
1925 template <typename ObjT>
1926 typename ObjT::Shared
1927 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
1929 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1931 const auto libObjPtr =
1932 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
1934 internal::validateCreatedObjPtr(libObjPtr);
1935 return ObjT::Shared::createWithoutRef(libObjPtr);
1939 using TraceClass = CommonTraceClass<bt_trace_class>;
1940 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
1942 namespace internal {
1944 struct TraceClassTypeDescr
1946 using Const = ConstTraceClass;
1947 using NonConst = TraceClass;
1951 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
1956 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
1960 } /* namespace internal */
1962 template <typename LibObjT>
1963 typename CommonStreamClass<LibObjT>::_TraceClass
1964 CommonStreamClass<LibObjT>::traceClass() const noexcept
1966 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
1969 template <typename LibObjT>
1970 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
1972 return Class {_Spec::cls(this->libObjPtr())};
1975 } /* namespace bt2 */
1977 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */