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/bt2c/c-string-view.hpp"
16 #include "cpp-common/bt2s/optional.hpp"
18 #include "borrowed-object.hpp"
19 #include "clock-class.hpp"
20 #include "field-class.hpp"
22 #include "internal/utils.hpp"
23 #include "optional-borrowed-object.hpp"
24 #include "shared-object.hpp"
29 template <typename LibObjT>
32 template <typename LibObjT>
35 template <typename LibObjT>
38 template <typename LibObjT>
41 template <typename LibObjT>
42 class CommonEventClass;
44 template <typename LibObjT>
45 class CommonStreamClass;
47 template <typename LibObjT>
48 class CommonTraceClass;
52 template <typename LibObjT>
53 struct CommonEventSpec;
55 /* Functions specific to mutable events */
57 struct CommonEventSpec<bt_event> final
59 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
61 return bt_event_borrow_class(libObjPtr);
64 static bt_stream *stream(bt_event * const libObjPtr) noexcept
66 return bt_event_borrow_stream(libObjPtr);
69 static bt_packet *packet(bt_event * const libObjPtr) noexcept
71 return bt_event_borrow_packet(libObjPtr);
74 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
76 return bt_event_borrow_payload_field(libObjPtr);
79 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
81 return bt_event_borrow_specific_context_field(libObjPtr);
84 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
86 return bt_event_borrow_common_context_field(libObjPtr);
90 /* Functions specific to constant events */
92 struct CommonEventSpec<const bt_event> final
94 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
96 return bt_event_borrow_class_const(libObjPtr);
99 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
101 return bt_event_borrow_stream_const(libObjPtr);
104 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
106 return bt_event_borrow_packet_const(libObjPtr);
109 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
111 return bt_event_borrow_payload_field_const(libObjPtr);
114 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
116 return bt_event_borrow_specific_context_field_const(libObjPtr);
119 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
121 return bt_event_borrow_common_context_field_const(libObjPtr);
125 template <typename LibObjT>
126 using DepStructField = DepType<LibObjT, StructureField, ConstStructureField>;
128 } /* namespace internal */
130 template <typename LibObjT>
131 class CommonEvent final : public BorrowedObject<LibObjT>
134 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
135 using _Spec = internal::CommonEventSpec<LibObjT>;
136 using _Packet = internal::DepPacket<LibObjT>;
137 using _Stream = internal::DepStream<LibObjT>;
138 using _StructureField = internal::DepStructField<LibObjT>;
141 using typename BorrowedObject<LibObjT>::LibObjPtr;
143 using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
144 CommonEventClass<const bt_event_class>>;
146 explicit CommonEvent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
150 template <typename OtherLibObjT>
151 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
155 template <typename OtherLibObjT>
156 CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept
158 _ThisBorrowedObject::operator=(event);
162 CommonEvent<const bt_event> asConst() const noexcept
164 return CommonEvent<const bt_event> {*this};
167 Class cls() const noexcept;
168 _Stream stream() const noexcept;
169 OptionalBorrowedObject<_Packet> packet() const noexcept;
171 OptionalBorrowedObject<_StructureField> payloadField() const noexcept
173 return _Spec::payloadField(this->libObjPtr());
176 OptionalBorrowedObject<_StructureField> specificContextField() const noexcept
178 return _Spec::specificContextField(this->libObjPtr());
181 OptionalBorrowedObject<_StructureField> commonContextField() const noexcept
183 return _Spec::commonContextField(this->libObjPtr());
187 using Event = CommonEvent<bt_event>;
188 using ConstEvent = CommonEvent<const bt_event>;
192 struct EventTypeDescr
194 using Const = ConstEvent;
195 using NonConst = Event;
199 struct TypeDescr<Event> : public EventTypeDescr
204 struct TypeDescr<ConstEvent> : public EventTypeDescr
208 struct PacketRefFuncs final
210 static void get(const bt_packet * const libObjPtr) noexcept
212 bt_packet_get_ref(libObjPtr);
215 static void put(const bt_packet * const libObjPtr) noexcept
217 bt_packet_put_ref(libObjPtr);
221 template <typename LibObjT>
222 struct CommonPacketSpec;
224 /* Functions specific to mutable packets */
226 struct CommonPacketSpec<bt_packet> final
228 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
230 return bt_packet_borrow_stream(libObjPtr);
233 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
235 return bt_packet_borrow_context_field(libObjPtr);
239 /* Functions specific to constant packets */
241 struct CommonPacketSpec<const bt_packet> final
243 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
245 return bt_packet_borrow_stream_const(libObjPtr);
248 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
250 return bt_packet_borrow_context_field_const(libObjPtr);
254 } /* namespace internal */
256 template <typename LibObjT>
257 class CommonPacket final : public BorrowedObject<LibObjT>
260 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
261 using _Spec = internal::CommonPacketSpec<LibObjT>;
262 using _Stream = internal::DepStream<LibObjT>;
263 using _StructureField = internal::DepStructField<LibObjT>;
266 using typename BorrowedObject<LibObjT>::LibObjPtr;
267 using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
269 explicit CommonPacket(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
273 template <typename OtherLibObjT>
274 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
278 template <typename OtherLibObjT>
279 CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept
281 _ThisBorrowedObject::operator=(packet);
285 CommonPacket<const bt_packet> asConst() const noexcept
287 return CommonPacket<const bt_packet> {*this};
290 _Stream stream() const noexcept;
292 OptionalBorrowedObject<_StructureField> contextField() const noexcept
294 return _Spec::contextField(this->libObjPtr());
297 Shared shared() const noexcept
299 return Shared::createWithRef(*this);
303 using Packet = CommonPacket<bt_packet>;
304 using ConstPacket = CommonPacket<const bt_packet>;
308 struct PacketTypeDescr
310 using Const = ConstPacket;
311 using NonConst = Packet;
315 struct TypeDescr<Packet> : public PacketTypeDescr
320 struct TypeDescr<ConstPacket> : public PacketTypeDescr
324 } /* namespace internal */
326 template <typename LibObjT>
327 OptionalBorrowedObject<typename CommonEvent<LibObjT>::_Packet>
328 CommonEvent<LibObjT>::packet() const noexcept
330 return _Spec::packet(this->libObjPtr());
335 struct StreamRefFuncs final
337 static void get(const bt_stream * const libObjPtr) noexcept
339 bt_stream_get_ref(libObjPtr);
342 static void put(const bt_stream * const libObjPtr) noexcept
344 bt_stream_put_ref(libObjPtr);
348 template <typename LibObjT>
349 struct CommonStreamSpec;
351 /* Functions specific to mutable streams */
353 struct CommonStreamSpec<bt_stream> final
355 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
357 return bt_stream_borrow_class(libObjPtr);
360 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
362 return bt_stream_borrow_trace(libObjPtr);
365 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
367 return bt_stream_borrow_user_attributes(libObjPtr);
371 /* Functions specific to constant streams */
373 struct CommonStreamSpec<const bt_stream> final
375 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
377 return bt_stream_borrow_class_const(libObjPtr);
380 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
382 return bt_stream_borrow_trace_const(libObjPtr);
385 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
387 return bt_stream_borrow_user_attributes_const(libObjPtr);
391 } /* namespace internal */
393 template <typename LibObjT>
394 class CommonStream final : public BorrowedObject<LibObjT>
397 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
398 using _Spec = internal::CommonStreamSpec<LibObjT>;
399 using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
402 using typename BorrowedObject<LibObjT>::LibObjPtr;
403 using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
404 using UserAttributes = internal::DepUserAttrs<LibObjT>;
406 using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
407 CommonStreamClass<const bt_stream_class>>;
409 explicit CommonStream(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
413 template <typename OtherLibObjT>
414 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
418 template <typename OtherLibObjT>
419 CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept
421 _ThisBorrowedObject::operator=(stream);
425 CommonStream<const bt_stream> asConst() const noexcept
427 return CommonStream<const bt_stream> {*this};
430 Packet::Shared createPacket() const
432 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
434 const auto libObjPtr = bt_packet_create(this->libObjPtr());
436 internal::validateCreatedObjPtr(libObjPtr);
437 return Packet::Shared::createWithoutRef(libObjPtr);
440 Class cls() const noexcept;
441 _Trace trace() const noexcept;
443 std::uint64_t id() const noexcept
445 return bt_stream_get_id(this->libObjPtr());
448 void name(const bt2c::CStringView name) const
450 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
452 const auto status = bt_stream_set_name(this->libObjPtr(), name);
454 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
455 throw MemoryError {};
459 bt2c::CStringView name() const noexcept
461 return bt_stream_get_name(this->libObjPtr());
464 template <typename LibValT>
465 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
467 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
469 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
472 UserAttributes userAttributes() const noexcept
474 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
477 Shared shared() const noexcept
479 return Shared::createWithRef(*this);
483 using Stream = CommonStream<bt_stream>;
484 using ConstStream = CommonStream<const bt_stream>;
488 struct StreamTypeDescr
490 using Const = ConstStream;
491 using NonConst = Stream;
495 struct TypeDescr<Stream> : public StreamTypeDescr
500 struct TypeDescr<ConstStream> : public StreamTypeDescr
504 } /* namespace internal */
506 template <typename LibObjT>
507 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
509 return _Stream {_Spec::stream(this->libObjPtr())};
512 template <typename LibObjT>
513 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
515 return _Stream {_Spec::stream(this->libObjPtr())};
520 struct TraceRefFuncs final
522 static void get(const bt_trace * const libObjPtr) noexcept
524 bt_trace_get_ref(libObjPtr);
527 static void put(const bt_trace * const libObjPtr) noexcept
529 bt_trace_put_ref(libObjPtr);
533 template <typename LibObjT>
534 struct CommonTraceSpec;
536 /* Functions specific to mutable traces */
538 struct CommonTraceSpec<bt_trace> final
540 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
542 return bt_trace_borrow_class(libObjPtr);
545 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
547 return bt_trace_borrow_stream_by_index(libObjPtr, index);
550 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
552 return bt_trace_borrow_stream_by_id(libObjPtr, id);
555 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
557 return bt_trace_borrow_user_attributes(libObjPtr);
561 /* Functions specific to constant traces */
563 struct CommonTraceSpec<const bt_trace> final
565 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
567 return bt_trace_borrow_class_const(libObjPtr);
570 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
571 const std::uint64_t index) noexcept
573 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
576 static const bt_stream *streamById(const bt_trace * const libObjPtr,
577 const std::uint64_t id) noexcept
579 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
582 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
584 return bt_trace_borrow_user_attributes_const(libObjPtr);
588 } /* namespace internal */
590 template <typename LibObjT>
591 class CommonTrace final : public BorrowedObject<LibObjT>
594 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
595 using _Spec = internal::CommonTraceSpec<LibObjT>;
596 using _Stream = internal::DepStream<LibObjT>;
599 using typename BorrowedObject<LibObjT>::LibObjPtr;
600 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
601 using UserAttributes = internal::DepUserAttrs<LibObjT>;
603 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
604 CommonTraceClass<const bt_trace_class>>;
606 struct ConstEnvironmentEntry
608 bt2c::CStringView name;
612 explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
616 template <typename OtherLibObjT>
617 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
621 template <typename OtherLibObjT>
622 CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
624 _ThisBorrowedObject::operator=(trace);
628 CommonTrace<const bt_trace> asConst() const noexcept
630 return CommonTrace<const bt_trace> {*this};
633 Class cls() const noexcept;
635 void name(const bt2c::CStringView name) const
637 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
639 const auto status = bt_trace_set_name(this->libObjPtr(), name);
641 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
642 throw MemoryError {};
646 bt2c::CStringView name() const noexcept
648 return bt_trace_get_name(this->libObjPtr());
651 void uuid(const bt2c::UuidView& uuid) const noexcept
653 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
656 bt2s::optional<bt2c::UuidView> uuid() const noexcept
658 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
661 return bt2c::UuidView {uuid};
664 return bt2s::nullopt;
667 std::uint64_t length() const noexcept
669 return bt_trace_get_stream_count(this->libObjPtr());
672 _Stream operator[](const std::uint64_t index) const noexcept
674 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
677 OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
679 return _Spec::streamById(this->libObjPtr(), id);
682 void environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
684 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
686 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
688 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
689 throw MemoryError {};
693 void environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
695 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
697 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
699 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
700 throw MemoryError {};
704 std::uint64_t environmentSize() const noexcept
706 return bt_trace_get_environment_entry_count(this->libObjPtr());
709 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
712 const bt_value *libObjPtr;
714 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
716 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
719 OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
721 return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
724 template <typename LibValT>
725 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
727 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
729 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
732 UserAttributes userAttributes() const noexcept
734 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
737 Shared shared() const noexcept
739 return Shared::createWithRef(*this);
743 using Trace = CommonTrace<bt_trace>;
744 using ConstTrace = CommonTrace<const bt_trace>;
748 struct TraceTypeDescr
750 using Const = ConstTrace;
751 using NonConst = Trace;
755 struct TypeDescr<Trace> : public TraceTypeDescr
760 struct TypeDescr<ConstTrace> : public TraceTypeDescr
764 } /* namespace internal */
766 template <typename LibObjT>
767 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
769 return _Trace {_Spec::trace(this->libObjPtr())};
774 struct EventClassRefFuncs final
776 static void get(const bt_event_class * const libObjPtr) noexcept
778 bt_event_class_get_ref(libObjPtr);
781 static void put(const bt_event_class * const libObjPtr) noexcept
783 bt_event_class_put_ref(libObjPtr);
787 template <typename LibObjT>
788 struct CommonEventClassSpec;
790 /* Functions specific to mutable event classes */
792 struct CommonEventClassSpec<bt_event_class> final
794 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
796 return bt_event_class_borrow_stream_class(libObjPtr);
799 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
801 return bt_event_class_borrow_payload_field_class(libObjPtr);
804 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
806 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
809 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
811 return bt_event_class_borrow_user_attributes(libObjPtr);
815 /* Functions specific to constant event classes */
817 struct CommonEventClassSpec<const bt_event_class> final
819 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
821 return bt_event_class_borrow_stream_class_const(libObjPtr);
824 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
826 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
829 static const bt_field_class *
830 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
832 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
835 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
837 return bt_event_class_borrow_user_attributes_const(libObjPtr);
841 template <typename LibObjT>
842 using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
844 } /* namespace internal */
846 template <typename LibObjT>
847 class CommonEventClass final : public BorrowedObject<LibObjT>
850 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
851 using _Spec = internal::CommonEventClassSpec<LibObjT>;
852 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
854 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
855 CommonStreamClass<const bt_stream_class>>;
858 using typename BorrowedObject<LibObjT>::LibObjPtr;
859 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
860 using UserAttributes = internal::DepUserAttrs<LibObjT>;
864 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
865 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
866 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
867 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
868 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
869 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
870 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
871 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
872 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
873 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
874 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
875 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
876 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
877 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
878 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
881 explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
885 template <typename OtherLibObjT>
886 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
887 _ThisBorrowedObject {eventClass}
891 template <typename OtherLibObjT>
892 CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
894 _ThisBorrowedObject::operator=(eventClass);
898 CommonEventClass<const bt_event_class> asConst() const noexcept
900 return CommonEventClass<const bt_event_class> {*this};
903 _StreamClass streamClass() const noexcept;
905 std::uint64_t id() const noexcept
907 return bt_event_class_get_id(this->libObjPtr());
910 void name(const bt2c::CStringView name) const
912 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
914 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
916 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
917 throw MemoryError {};
921 bt2c::CStringView name() const noexcept
923 return bt_event_class_get_name(this->libObjPtr());
926 void logLevel(const LogLevel logLevel) const noexcept
928 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
930 bt_event_class_set_log_level(this->libObjPtr(),
931 static_cast<bt_event_class_log_level>(logLevel));
934 bt2s::optional<LogLevel> logLevel() const noexcept
936 bt_event_class_log_level libLogLevel;
938 if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
939 return static_cast<LogLevel>(libLogLevel);
942 return bt2s::nullopt;
945 void emfUri(const bt2c::CStringView emfUri) const
947 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
949 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
951 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
952 throw MemoryError {};
956 bt2c::CStringView emfUri() const noexcept
958 return bt_event_class_get_emf_uri(this->libObjPtr());
961 void payloadFieldClass(const StructureFieldClass fc) const
963 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
966 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
968 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
969 throw MemoryError {};
973 OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
975 return _Spec::payloadFieldClass(this->libObjPtr());
978 void specificContextFieldClass(const StructureFieldClass fc) const
980 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
983 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
985 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
986 throw MemoryError {};
990 OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
992 return _Spec::specificContextFieldClass(this->libObjPtr());
995 template <typename LibValT>
996 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
998 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1000 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1003 UserAttributes userAttributes() const noexcept
1005 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1008 Shared shared() const noexcept
1010 return Shared::createWithRef(*this);
1014 using EventClass = CommonEventClass<bt_event_class>;
1015 using ConstEventClass = CommonEventClass<const bt_event_class>;
1017 namespace internal {
1019 struct EventClassTypeDescr
1021 using Const = ConstEventClass;
1022 using NonConst = EventClass;
1026 struct TypeDescr<EventClass> : public EventClassTypeDescr
1031 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1035 } /* namespace internal */
1037 template <typename LibObjT>
1038 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1040 return Class {_Spec::cls(this->libObjPtr())};
1043 namespace internal {
1045 struct StreamClassRefFuncs final
1047 static void get(const bt_stream_class * const libObjPtr) noexcept
1049 bt_stream_class_get_ref(libObjPtr);
1052 static void put(const bt_stream_class * const libObjPtr) noexcept
1054 bt_stream_class_put_ref(libObjPtr);
1058 template <typename LibObjT>
1059 struct CommonStreamClassSpec;
1061 /* Functions specific to mutable stream classes */
1063 struct CommonStreamClassSpec<bt_stream_class> final
1065 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1067 return bt_stream_class_borrow_trace_class(libObjPtr);
1070 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1071 const std::uint64_t index) noexcept
1073 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1076 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1077 const std::uint64_t id) noexcept
1079 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1082 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1084 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1087 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1089 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1092 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1094 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1097 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1099 return bt_stream_class_borrow_user_attributes(libObjPtr);
1103 /* Functions specific to constant stream classes */
1105 struct CommonStreamClassSpec<const bt_stream_class> final
1107 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1109 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1112 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1113 const std::uint64_t index) noexcept
1115 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1118 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1119 const std::uint64_t id) noexcept
1121 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1124 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1126 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1129 static const bt_field_class *
1130 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1132 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1135 static const bt_field_class *
1136 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1138 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1141 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1143 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1147 } /* namespace internal */
1149 template <typename LibObjT>
1150 class CommonStreamClass final : public BorrowedObject<LibObjT>
1153 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1154 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1155 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
1157 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1158 CommonTraceClass<const bt_trace_class>>;
1160 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1161 CommonEventClass<const bt_event_class>>;
1163 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
1166 using typename BorrowedObject<LibObjT>::LibObjPtr;
1167 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1168 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1170 explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1174 template <typename OtherLibObjT>
1175 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1176 _ThisBorrowedObject {streamClass}
1180 template <typename OtherLibObjT>
1181 CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1183 _ThisBorrowedObject::operator=(streamClass);
1187 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1189 return CommonStreamClass<const bt_stream_class> {*this};
1192 Stream::Shared instantiate(const Trace trace) const
1194 static_assert(!std::is_const<LibObjT>::value,
1195 "Not available with `bt2::ConstStreamClass`.");
1197 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1199 internal::validateCreatedObjPtr(libObjPtr);
1200 return Stream::Shared::createWithoutRef(libObjPtr);
1203 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1205 static_assert(!std::is_const<LibObjT>::value,
1206 "Not available with `bt2::ConstStreamClass`.");
1208 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1210 internal::validateCreatedObjPtr(libObjPtr);
1211 return Stream::Shared::createWithoutRef(libObjPtr);
1214 EventClass::Shared createEventClass() const
1216 static_assert(!std::is_const<LibObjT>::value,
1217 "Not available with `bt2::ConstStreamClass`.");
1219 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1221 internal::validateCreatedObjPtr(libObjPtr);
1222 return EventClass::Shared::createWithoutRef(libObjPtr);
1225 EventClass::Shared createEventClass(const std::uint64_t id) const
1227 static_assert(!std::is_const<LibObjT>::value,
1228 "Not available with `bt2::ConstStreamClass`.");
1230 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1232 internal::validateCreatedObjPtr(libObjPtr);
1233 return EventClass::Shared::createWithoutRef(libObjPtr);
1236 _TraceClass traceClass() const noexcept;
1238 std::uint64_t id() const noexcept
1240 return bt_stream_class_get_id(this->libObjPtr());
1243 void name(const bt2c::CStringView name) const
1245 static_assert(!std::is_const<LibObjT>::value,
1246 "Not available with `bt2::ConstStreamClass`.");
1248 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1250 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1251 throw MemoryError {};
1255 bt2c::CStringView name() const noexcept
1257 return bt_stream_class_get_name(this->libObjPtr());
1260 void assignsAutomaticEventClassId(const bool val) const noexcept
1262 static_assert(!std::is_const<LibObjT>::value,
1263 "Not available with `bt2::ConstStreamClass`.");
1265 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1266 static_cast<bt_bool>(val));
1269 bool assignsAutomaticEventClassId() const noexcept
1271 return static_cast<bool>(
1272 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1275 void assignsAutomaticStreamId(const bool val) const noexcept
1277 static_assert(!std::is_const<LibObjT>::value,
1278 "Not available with `bt2::ConstStreamClass`.");
1280 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1281 static_cast<bt_bool>(val));
1284 bool assignsAutomaticStreamId() const noexcept
1286 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1289 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1290 const bool withEndDefaultClkSnapshot) const noexcept
1292 static_assert(!std::is_const<LibObjT>::value,
1293 "Not available with `bt2::ConstStreamClass`.");
1295 bt_stream_class_set_supports_packets(this->libObjPtr(),
1296 static_cast<bt_bool>(supportsPackets),
1297 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1298 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1301 bool supportsPackets() const noexcept
1303 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1306 bool packetsHaveBeginningClockSnapshot() const noexcept
1308 return static_cast<bool>(
1309 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1312 bool packetsHaveEndClockSnapshot() const noexcept
1314 return static_cast<bool>(
1315 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1318 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1319 const bool withDefaultClkSnapshots) const noexcept
1321 static_assert(!std::is_const<LibObjT>::value,
1322 "Not available with `bt2::ConstStreamClass`.");
1324 bt_stream_class_set_supports_discarded_events(
1325 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1326 static_cast<bt_bool>(withDefaultClkSnapshots));
1329 bool supportsDiscardedEvents() const noexcept
1331 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1334 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1336 return static_cast<bool>(
1337 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1340 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1341 const bool withDefaultClkSnapshots) const noexcept
1343 static_assert(!std::is_const<LibObjT>::value,
1344 "Not available with `bt2::ConstStreamClass`.");
1346 bt_stream_class_set_supports_discarded_packets(
1347 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1348 static_cast<bt_bool>(withDefaultClkSnapshots));
1351 bool supportsDiscardedPackets() const noexcept
1353 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1356 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1358 return static_cast<bool>(
1359 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1362 void defaultClockClass(const ClockClass clkCls) const
1364 static_assert(!std::is_const<LibObjT>::value,
1365 "Not available with `bt2::ConstStreamClass`.");
1368 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1370 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1373 OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
1375 return _Spec::defaultClockClass(this->libObjPtr());
1378 std::uint64_t length() const noexcept
1380 return bt_stream_class_get_event_class_count(this->libObjPtr());
1383 _EventClass operator[](const std::uint64_t index) const noexcept
1385 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1388 OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1390 return _Spec::eventClassById(this->libObjPtr(), id);
1393 void packetContextFieldClass(const StructureFieldClass fc) const
1395 static_assert(!std::is_const<LibObjT>::value,
1396 "Not available with `bt2::ConstStreamClass`.");
1399 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1401 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1402 throw MemoryError {};
1406 OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
1408 return _Spec::packetContextFieldClass(this->libObjPtr());
1411 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1413 static_assert(!std::is_const<LibObjT>::value,
1414 "Not available with `bt2::ConstStreamClass`.");
1417 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1419 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1420 throw MemoryError {};
1424 OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1426 return _Spec::eventCommonContextFieldClass(this->libObjPtr());
1429 template <typename LibValT>
1430 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1432 static_assert(!std::is_const<LibObjT>::value,
1433 "Not available with `bt2::ConstStreamClass`.");
1435 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1438 UserAttributes userAttributes() const noexcept
1440 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1443 Shared shared() const noexcept
1445 return Shared::createWithRef(*this);
1449 using StreamClass = CommonStreamClass<bt_stream_class>;
1450 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1452 namespace internal {
1454 struct StreamClassTypeDescr
1456 using Const = ConstStreamClass;
1457 using NonConst = StreamClass;
1461 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1466 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1470 } /* namespace internal */
1472 template <typename LibObjT>
1473 typename CommonEventClass<LibObjT>::_StreamClass
1474 CommonEventClass<LibObjT>::streamClass() const noexcept
1476 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1479 template <typename LibObjT>
1480 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1482 return Class {_Spec::cls(this->libObjPtr())};
1485 namespace internal {
1487 struct TraceClassRefFuncs final
1489 static void get(const bt_trace_class * const libObjPtr) noexcept
1491 bt_trace_class_get_ref(libObjPtr);
1494 static void put(const bt_trace_class * const libObjPtr) noexcept
1496 bt_trace_class_put_ref(libObjPtr);
1500 template <typename LibObjT>
1501 struct CommonTraceClassSpec;
1503 /* Functions specific to mutable stream classes */
1505 struct CommonTraceClassSpec<bt_trace_class> final
1507 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1508 const std::uint64_t index) noexcept
1510 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1513 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1514 const std::uint64_t id) noexcept
1516 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1519 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1521 return bt_trace_class_borrow_user_attributes(libObjPtr);
1525 /* Functions specific to constant stream classes */
1527 struct CommonTraceClassSpec<const bt_trace_class> final
1529 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1530 const std::uint64_t index) noexcept
1532 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1535 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1536 const std::uint64_t id) noexcept
1538 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1541 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1543 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1547 } /* namespace internal */
1549 template <typename LibObjT>
1550 class CommonTraceClass final : public BorrowedObject<LibObjT>
1553 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1555 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1557 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1558 CommonStreamClass<const bt_stream_class>>;
1561 using typename BorrowedObject<LibObjT>::LibObjPtr;
1562 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1563 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1565 explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1569 template <typename OtherLibObjT>
1570 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1571 _ThisBorrowedObject {traceClass}
1575 template <typename OtherLibObjT>
1576 CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1578 _ThisBorrowedObject::operator=(traceClass);
1582 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1584 return CommonTraceClass<const bt_trace_class> {*this};
1587 Trace::Shared instantiate() const
1589 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1591 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1593 internal::validateCreatedObjPtr(libObjPtr);
1594 return Trace::Shared::createWithoutRef(libObjPtr);
1597 StreamClass::Shared createStreamClass() const
1599 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1601 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1603 internal::validateCreatedObjPtr(libObjPtr);
1604 return StreamClass::Shared::createWithoutRef(libObjPtr);
1607 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1609 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1611 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1613 internal::validateCreatedObjPtr(libObjPtr);
1614 return StreamClass::Shared::createWithoutRef(libObjPtr);
1617 FieldClass::Shared createBoolFieldClass() const
1619 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1621 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1623 internal::validateCreatedObjPtr(libObjPtr);
1624 return FieldClass::Shared::createWithoutRef(libObjPtr);
1627 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1629 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1631 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1633 internal::validateCreatedObjPtr(libObjPtr);
1634 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1637 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1639 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1641 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1643 internal::validateCreatedObjPtr(libObjPtr);
1644 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1647 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1649 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1651 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1653 internal::validateCreatedObjPtr(libObjPtr);
1654 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1657 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1659 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1661 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1663 internal::validateCreatedObjPtr(libObjPtr);
1664 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1667 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1669 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1671 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1673 internal::validateCreatedObjPtr(libObjPtr);
1674 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1677 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1679 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1681 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1683 internal::validateCreatedObjPtr(libObjPtr);
1684 return FieldClass::Shared::createWithoutRef(libObjPtr);
1687 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1689 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1691 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1693 internal::validateCreatedObjPtr(libObjPtr);
1694 return FieldClass::Shared::createWithoutRef(libObjPtr);
1697 FieldClass::Shared createStringFieldClass() const
1699 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1701 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1703 internal::validateCreatedObjPtr(libObjPtr);
1704 return FieldClass::Shared::createWithoutRef(libObjPtr);
1707 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1708 const std::uint64_t length) const
1710 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1712 const auto libObjPtr = bt_field_class_array_static_create(
1713 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1715 internal::validateCreatedObjPtr(libObjPtr);
1716 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1719 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1721 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1723 const auto libObjPtr = bt_field_class_array_dynamic_create(
1724 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1726 internal::validateCreatedObjPtr(libObjPtr);
1727 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1730 DynamicArrayWithLengthFieldClass::Shared
1731 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1732 const IntegerFieldClass lengthFieldClass) const
1734 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1736 const auto libObjPtr = bt_field_class_array_dynamic_create(
1737 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1739 internal::validateCreatedObjPtr(libObjPtr);
1740 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1743 StructureFieldClass::Shared createStructureFieldClass() const
1745 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1747 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1749 internal::validateCreatedObjPtr(libObjPtr);
1750 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1753 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1755 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1757 const auto libObjPtr = bt_field_class_option_without_selector_create(
1758 this->libObjPtr(), optionalFieldClass.libObjPtr());
1760 internal::validateCreatedObjPtr(libObjPtr);
1761 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1764 OptionWithBoolSelectorFieldClass::Shared
1765 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1766 const FieldClass selectorFieldClass) const
1768 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1770 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1771 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1773 internal::validateCreatedObjPtr(libObjPtr);
1774 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1777 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1778 createOptionWithUnsignedIntegerSelectorFieldClass(
1779 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1780 const ConstUnsignedIntegerRangeSet ranges) const
1782 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1784 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1785 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1786 ranges.libObjPtr());
1788 internal::validateCreatedObjPtr(libObjPtr);
1789 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1792 OptionWithSignedIntegerSelectorFieldClass::Shared
1793 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1794 const IntegerFieldClass selectorFieldClass,
1795 const ConstSignedIntegerRangeSet ranges) const
1797 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1799 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1800 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1801 ranges.libObjPtr());
1803 internal::validateCreatedObjPtr(libObjPtr);
1804 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1807 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1809 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1811 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1813 internal::validateCreatedObjPtr(libObjPtr);
1814 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1817 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1818 createVariantWithUnsignedIntegerSelectorFieldClass(
1819 const IntegerFieldClass selectorFieldClass) const
1821 return this->_createVariantWithIntegerSelectorFieldClass<
1822 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1825 VariantWithSignedIntegerSelectorFieldClass::Shared
1826 createVariantWithSignedIntegerSelectorFieldClass(
1827 const IntegerFieldClass selectorFieldClass) const
1829 return this->_createVariantWithIntegerSelectorFieldClass<
1830 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
1833 void assignsAutomaticStreamClassId(const bool val) const noexcept
1835 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1837 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
1838 static_cast<bt_bool>(val));
1841 bool assignsAutomaticStreamClassId() const noexcept
1843 return static_cast<bool>(
1844 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
1847 std::uint64_t length() const noexcept
1849 return bt_trace_class_get_stream_class_count(this->libObjPtr());
1852 _StreamClass operator[](const std::uint64_t index) const noexcept
1854 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
1857 OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
1859 return _Spec::streamClassById(this->libObjPtr(), id);
1862 template <typename LibValT>
1863 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1865 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1867 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1870 UserAttributes userAttributes() const noexcept
1872 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1875 Shared shared() const noexcept
1877 return Shared::createWithRef(*this);
1881 template <typename ObjT>
1882 typename ObjT::Shared
1883 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
1885 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1887 const auto libObjPtr =
1888 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
1890 internal::validateCreatedObjPtr(libObjPtr);
1891 return ObjT::Shared::createWithoutRef(libObjPtr);
1895 using TraceClass = CommonTraceClass<bt_trace_class>;
1896 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
1898 namespace internal {
1900 struct TraceClassTypeDescr
1902 using Const = ConstTraceClass;
1903 using NonConst = TraceClass;
1907 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
1912 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
1916 } /* namespace internal */
1918 template <typename LibObjT>
1919 typename CommonStreamClass<LibObjT>::_TraceClass
1920 CommonStreamClass<LibObjT>::traceClass() const noexcept
1922 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
1925 template <typename LibObjT>
1926 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
1928 return Class {_Spec::cls(this->libObjPtr())};
1931 } /* namespace bt2 */
1933 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */