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 CommonStream 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 {};
461 bt2c::CStringView name() const noexcept
463 return bt_stream_get_name(this->libObjPtr());
466 template <typename LibValT>
467 CommonStream userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
469 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
471 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
475 UserAttributes userAttributes() const noexcept
477 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
480 Shared shared() const noexcept
482 return Shared::createWithRef(*this);
486 using Stream = CommonStream<bt_stream>;
487 using ConstStream = CommonStream<const bt_stream>;
491 struct StreamTypeDescr
493 using Const = ConstStream;
494 using NonConst = Stream;
498 struct TypeDescr<Stream> : public StreamTypeDescr
503 struct TypeDescr<ConstStream> : public StreamTypeDescr
507 } /* namespace internal */
509 template <typename LibObjT>
510 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
512 return _Stream {_Spec::stream(this->libObjPtr())};
515 template <typename LibObjT>
516 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
518 return _Stream {_Spec::stream(this->libObjPtr())};
523 struct TraceRefFuncs final
525 static void get(const bt_trace * const libObjPtr) noexcept
527 bt_trace_get_ref(libObjPtr);
530 static void put(const bt_trace * const libObjPtr) noexcept
532 bt_trace_put_ref(libObjPtr);
536 template <typename LibObjT>
537 struct CommonTraceSpec;
539 /* Functions specific to mutable traces */
541 struct CommonTraceSpec<bt_trace> final
543 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
545 return bt_trace_borrow_class(libObjPtr);
548 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
550 return bt_trace_borrow_stream_by_index(libObjPtr, index);
553 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
555 return bt_trace_borrow_stream_by_id(libObjPtr, id);
558 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
560 return bt_trace_borrow_user_attributes(libObjPtr);
564 /* Functions specific to constant traces */
566 struct CommonTraceSpec<const bt_trace> final
568 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
570 return bt_trace_borrow_class_const(libObjPtr);
573 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
574 const std::uint64_t index) noexcept
576 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
579 static const bt_stream *streamById(const bt_trace * const libObjPtr,
580 const std::uint64_t id) noexcept
582 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
585 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
587 return bt_trace_borrow_user_attributes_const(libObjPtr);
591 } /* namespace internal */
593 template <typename LibObjT>
594 class CommonTrace final : public BorrowedObject<LibObjT>
597 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
598 using _Spec = internal::CommonTraceSpec<LibObjT>;
599 using _Stream = internal::DepStream<LibObjT>;
602 using typename BorrowedObject<LibObjT>::LibObjPtr;
603 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
604 using UserAttributes = internal::DepUserAttrs<LibObjT>;
606 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
607 CommonTraceClass<const bt_trace_class>>;
609 struct ConstEnvironmentEntry
611 bt2c::CStringView name;
615 explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
619 template <typename OtherLibObjT>
620 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
624 template <typename OtherLibObjT>
625 CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
627 _ThisBorrowedObject::operator=(trace);
631 CommonTrace<const bt_trace> asConst() const noexcept
633 return CommonTrace<const bt_trace> {*this};
636 Class cls() const noexcept;
638 CommonTrace name(const bt2c::CStringView name) const
640 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
642 const auto status = bt_trace_set_name(this->libObjPtr(), name);
644 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
645 throw MemoryError {};
651 bt2c::CStringView name() const noexcept
653 return bt_trace_get_name(this->libObjPtr());
656 CommonTrace uuid(const bt2c::UuidView& uuid) const noexcept
658 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
662 bt2s::optional<bt2c::UuidView> uuid() const noexcept
664 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
667 return bt2c::UuidView {uuid};
670 return bt2s::nullopt;
673 std::uint64_t length() const noexcept
675 return bt_trace_get_stream_count(this->libObjPtr());
678 _Stream operator[](const std::uint64_t index) const noexcept
680 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
683 OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
685 return _Spec::streamById(this->libObjPtr(), id);
688 CommonTrace environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
690 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
692 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
694 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
695 throw MemoryError {};
701 CommonTrace environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
703 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
705 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
707 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
708 throw MemoryError {};
714 std::uint64_t environmentSize() const noexcept
716 return bt_trace_get_environment_entry_count(this->libObjPtr());
719 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
722 const bt_value *libObjPtr;
724 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
726 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
729 OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
731 return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
734 template <typename LibValT>
735 CommonTrace userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
737 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
739 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
743 UserAttributes userAttributes() const noexcept
745 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
748 Shared shared() const noexcept
750 return Shared::createWithRef(*this);
754 using Trace = CommonTrace<bt_trace>;
755 using ConstTrace = CommonTrace<const bt_trace>;
759 struct TraceTypeDescr
761 using Const = ConstTrace;
762 using NonConst = Trace;
766 struct TypeDescr<Trace> : public TraceTypeDescr
771 struct TypeDescr<ConstTrace> : public TraceTypeDescr
775 } /* namespace internal */
777 template <typename LibObjT>
778 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
780 return _Trace {_Spec::trace(this->libObjPtr())};
785 struct EventClassRefFuncs final
787 static void get(const bt_event_class * const libObjPtr) noexcept
789 bt_event_class_get_ref(libObjPtr);
792 static void put(const bt_event_class * const libObjPtr) noexcept
794 bt_event_class_put_ref(libObjPtr);
798 template <typename LibObjT>
799 struct CommonEventClassSpec;
801 /* Functions specific to mutable event classes */
803 struct CommonEventClassSpec<bt_event_class> final
805 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
807 return bt_event_class_borrow_stream_class(libObjPtr);
810 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
812 return bt_event_class_borrow_payload_field_class(libObjPtr);
815 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
817 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
820 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
822 return bt_event_class_borrow_user_attributes(libObjPtr);
826 /* Functions specific to constant event classes */
828 struct CommonEventClassSpec<const bt_event_class> final
830 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
832 return bt_event_class_borrow_stream_class_const(libObjPtr);
835 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
837 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
840 static const bt_field_class *
841 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
843 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
846 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
848 return bt_event_class_borrow_user_attributes_const(libObjPtr);
852 template <typename LibObjT>
853 using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
855 } /* namespace internal */
857 template <typename LibObjT>
858 class CommonEventClass final : public BorrowedObject<LibObjT>
861 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
862 using _Spec = internal::CommonEventClassSpec<LibObjT>;
863 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
865 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
866 CommonStreamClass<const bt_stream_class>>;
869 using typename BorrowedObject<LibObjT>::LibObjPtr;
870 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
871 using UserAttributes = internal::DepUserAttrs<LibObjT>;
875 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
876 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
877 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
878 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
879 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
880 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
881 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
882 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
883 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
884 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
885 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
886 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
887 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
888 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
889 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
892 explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
896 template <typename OtherLibObjT>
897 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
898 _ThisBorrowedObject {eventClass}
902 template <typename OtherLibObjT>
903 CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
905 _ThisBorrowedObject::operator=(eventClass);
909 CommonEventClass<const bt_event_class> asConst() const noexcept
911 return CommonEventClass<const bt_event_class> {*this};
914 _StreamClass streamClass() const noexcept;
916 std::uint64_t id() const noexcept
918 return bt_event_class_get_id(this->libObjPtr());
921 CommonEventClass name(const bt2c::CStringView name) const
923 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
925 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
927 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
928 throw MemoryError {};
934 bt2c::CStringView name() const noexcept
936 return bt_event_class_get_name(this->libObjPtr());
939 CommonEventClass logLevel(const LogLevel logLevel) const noexcept
941 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
943 bt_event_class_set_log_level(this->libObjPtr(),
944 static_cast<bt_event_class_log_level>(logLevel));
948 bt2s::optional<LogLevel> logLevel() const noexcept
950 bt_event_class_log_level libLogLevel;
952 if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
953 return static_cast<LogLevel>(libLogLevel);
956 return bt2s::nullopt;
959 CommonEventClass emfUri(const bt2c::CStringView emfUri) const
961 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
963 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
965 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
966 throw MemoryError {};
972 bt2c::CStringView emfUri() const noexcept
974 return bt_event_class_get_emf_uri(this->libObjPtr());
977 CommonEventClass payloadFieldClass(const StructureFieldClass fc) const
979 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
982 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
984 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
985 throw MemoryError {};
991 OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
993 return _Spec::payloadFieldClass(this->libObjPtr());
996 CommonEventClass specificContextFieldClass(const StructureFieldClass fc) const
998 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1001 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1003 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1004 throw MemoryError {};
1010 OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
1012 return _Spec::specificContextFieldClass(this->libObjPtr());
1015 template <typename LibValT>
1016 CommonEventClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1018 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1020 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1024 UserAttributes userAttributes() const noexcept
1026 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1029 Shared shared() const noexcept
1031 return Shared::createWithRef(*this);
1035 using EventClass = CommonEventClass<bt_event_class>;
1036 using ConstEventClass = CommonEventClass<const bt_event_class>;
1038 namespace internal {
1040 struct EventClassTypeDescr
1042 using Const = ConstEventClass;
1043 using NonConst = EventClass;
1047 struct TypeDescr<EventClass> : public EventClassTypeDescr
1052 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1056 } /* namespace internal */
1058 template <typename LibObjT>
1059 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1061 return Class {_Spec::cls(this->libObjPtr())};
1064 namespace internal {
1066 struct StreamClassRefFuncs final
1068 static void get(const bt_stream_class * const libObjPtr) noexcept
1070 bt_stream_class_get_ref(libObjPtr);
1073 static void put(const bt_stream_class * const libObjPtr) noexcept
1075 bt_stream_class_put_ref(libObjPtr);
1079 template <typename LibObjT>
1080 struct CommonStreamClassSpec;
1082 /* Functions specific to mutable stream classes */
1084 struct CommonStreamClassSpec<bt_stream_class> final
1086 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1088 return bt_stream_class_borrow_trace_class(libObjPtr);
1091 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1092 const std::uint64_t index) noexcept
1094 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1097 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1098 const std::uint64_t id) noexcept
1100 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1103 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1105 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1108 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1110 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1113 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1115 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1118 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1120 return bt_stream_class_borrow_user_attributes(libObjPtr);
1124 /* Functions specific to constant stream classes */
1126 struct CommonStreamClassSpec<const bt_stream_class> final
1128 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1130 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1133 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1134 const std::uint64_t index) noexcept
1136 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1139 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1140 const std::uint64_t id) noexcept
1142 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1145 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1147 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1150 static const bt_field_class *
1151 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1153 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1156 static const bt_field_class *
1157 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1159 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1162 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1164 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1168 } /* namespace internal */
1170 template <typename LibObjT>
1171 class CommonStreamClass final : public BorrowedObject<LibObjT>
1174 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1175 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1176 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
1178 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1179 CommonTraceClass<const bt_trace_class>>;
1181 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1182 CommonEventClass<const bt_event_class>>;
1184 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
1187 using typename BorrowedObject<LibObjT>::LibObjPtr;
1188 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1189 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1191 explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1195 template <typename OtherLibObjT>
1196 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1197 _ThisBorrowedObject {streamClass}
1201 template <typename OtherLibObjT>
1202 CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1204 _ThisBorrowedObject::operator=(streamClass);
1208 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1210 return CommonStreamClass<const bt_stream_class> {*this};
1213 Stream::Shared instantiate(const Trace trace) const
1215 static_assert(!std::is_const<LibObjT>::value,
1216 "Not available with `bt2::ConstStreamClass`.");
1218 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1220 internal::validateCreatedObjPtr(libObjPtr);
1221 return Stream::Shared::createWithoutRef(libObjPtr);
1224 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1226 static_assert(!std::is_const<LibObjT>::value,
1227 "Not available with `bt2::ConstStreamClass`.");
1229 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1231 internal::validateCreatedObjPtr(libObjPtr);
1232 return Stream::Shared::createWithoutRef(libObjPtr);
1235 EventClass::Shared createEventClass() const
1237 static_assert(!std::is_const<LibObjT>::value,
1238 "Not available with `bt2::ConstStreamClass`.");
1240 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1242 internal::validateCreatedObjPtr(libObjPtr);
1243 return EventClass::Shared::createWithoutRef(libObjPtr);
1246 EventClass::Shared createEventClass(const std::uint64_t id) const
1248 static_assert(!std::is_const<LibObjT>::value,
1249 "Not available with `bt2::ConstStreamClass`.");
1251 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1253 internal::validateCreatedObjPtr(libObjPtr);
1254 return EventClass::Shared::createWithoutRef(libObjPtr);
1257 _TraceClass traceClass() const noexcept;
1259 std::uint64_t id() const noexcept
1261 return bt_stream_class_get_id(this->libObjPtr());
1264 CommonStreamClass name(const bt2c::CStringView name) const
1266 static_assert(!std::is_const<LibObjT>::value,
1267 "Not available with `bt2::ConstStreamClass`.");
1269 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1271 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1272 throw MemoryError {};
1278 bt2c::CStringView name() const noexcept
1280 return bt_stream_class_get_name(this->libObjPtr());
1283 CommonStreamClass assignsAutomaticEventClassId(const bool val) const noexcept
1285 static_assert(!std::is_const<LibObjT>::value,
1286 "Not available with `bt2::ConstStreamClass`.");
1288 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1289 static_cast<bt_bool>(val));
1293 bool assignsAutomaticEventClassId() const noexcept
1295 return static_cast<bool>(
1296 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1299 CommonStreamClass assignsAutomaticStreamId(const bool val) const noexcept
1301 static_assert(!std::is_const<LibObjT>::value,
1302 "Not available with `bt2::ConstStreamClass`.");
1304 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1305 static_cast<bt_bool>(val));
1309 bool assignsAutomaticStreamId() const noexcept
1311 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1314 CommonStreamClass supportsPackets(const bool supportsPackets,
1315 const bool withBeginningDefaultClkSnapshot,
1316 const bool withEndDefaultClkSnapshot) const noexcept
1318 static_assert(!std::is_const<LibObjT>::value,
1319 "Not available with `bt2::ConstStreamClass`.");
1321 bt_stream_class_set_supports_packets(this->libObjPtr(),
1322 static_cast<bt_bool>(supportsPackets),
1323 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1324 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1328 bool supportsPackets() const noexcept
1330 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1333 bool packetsHaveBeginningClockSnapshot() const noexcept
1335 return static_cast<bool>(
1336 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1339 bool packetsHaveEndClockSnapshot() const noexcept
1341 return static_cast<bool>(
1342 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1345 CommonStreamClass supportsDiscardedEvents(const bool supportsDiscardedEvents,
1346 const bool withDefaultClkSnapshots) const noexcept
1348 static_assert(!std::is_const<LibObjT>::value,
1349 "Not available with `bt2::ConstStreamClass`.");
1351 bt_stream_class_set_supports_discarded_events(
1352 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1353 static_cast<bt_bool>(withDefaultClkSnapshots));
1357 bool supportsDiscardedEvents() const noexcept
1359 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1362 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1364 return static_cast<bool>(
1365 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1368 CommonStreamClass supportsDiscardedPackets(const bool supportsDiscardedPackets,
1369 const bool withDefaultClkSnapshots) const noexcept
1371 static_assert(!std::is_const<LibObjT>::value,
1372 "Not available with `bt2::ConstStreamClass`.");
1374 bt_stream_class_set_supports_discarded_packets(
1375 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1376 static_cast<bt_bool>(withDefaultClkSnapshots));
1380 bool supportsDiscardedPackets() const noexcept
1382 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1385 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1387 return static_cast<bool>(
1388 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1391 CommonStreamClass defaultClockClass(const ClockClass clkCls) const
1393 static_assert(!std::is_const<LibObjT>::value,
1394 "Not available with `bt2::ConstStreamClass`.");
1397 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1399 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1403 OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
1405 return _Spec::defaultClockClass(this->libObjPtr());
1408 std::uint64_t length() const noexcept
1410 return bt_stream_class_get_event_class_count(this->libObjPtr());
1413 _EventClass operator[](const std::uint64_t index) const noexcept
1415 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1418 OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1420 return _Spec::eventClassById(this->libObjPtr(), id);
1423 CommonStreamClass packetContextFieldClass(const StructureFieldClass fc) const
1425 static_assert(!std::is_const<LibObjT>::value,
1426 "Not available with `bt2::ConstStreamClass`.");
1429 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1431 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1432 throw MemoryError {};
1438 OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
1440 return _Spec::packetContextFieldClass(this->libObjPtr());
1443 CommonStreamClass eventCommonContextFieldClass(const StructureFieldClass fc) const
1445 static_assert(!std::is_const<LibObjT>::value,
1446 "Not available with `bt2::ConstStreamClass`.");
1449 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1451 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1452 throw MemoryError {};
1458 OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1460 return _Spec::eventCommonContextFieldClass(this->libObjPtr());
1463 template <typename LibValT>
1464 CommonStreamClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1466 static_assert(!std::is_const<LibObjT>::value,
1467 "Not available with `bt2::ConstStreamClass`.");
1469 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1473 UserAttributes userAttributes() const noexcept
1475 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1478 Shared shared() const noexcept
1480 return Shared::createWithRef(*this);
1484 using StreamClass = CommonStreamClass<bt_stream_class>;
1485 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1487 namespace internal {
1489 struct StreamClassTypeDescr
1491 using Const = ConstStreamClass;
1492 using NonConst = StreamClass;
1496 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1501 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1505 } /* namespace internal */
1507 template <typename LibObjT>
1508 typename CommonEventClass<LibObjT>::_StreamClass
1509 CommonEventClass<LibObjT>::streamClass() const noexcept
1511 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1514 template <typename LibObjT>
1515 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1517 return Class {_Spec::cls(this->libObjPtr())};
1520 namespace internal {
1522 struct TraceClassRefFuncs final
1524 static void get(const bt_trace_class * const libObjPtr) noexcept
1526 bt_trace_class_get_ref(libObjPtr);
1529 static void put(const bt_trace_class * const libObjPtr) noexcept
1531 bt_trace_class_put_ref(libObjPtr);
1535 template <typename LibObjT>
1536 struct CommonTraceClassSpec;
1538 /* Functions specific to mutable stream classes */
1540 struct CommonTraceClassSpec<bt_trace_class> final
1542 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1543 const std::uint64_t index) noexcept
1545 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1548 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1549 const std::uint64_t id) noexcept
1551 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1554 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1556 return bt_trace_class_borrow_user_attributes(libObjPtr);
1560 /* Functions specific to constant stream classes */
1562 struct CommonTraceClassSpec<const bt_trace_class> final
1564 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1565 const std::uint64_t index) noexcept
1567 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1570 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1571 const std::uint64_t id) noexcept
1573 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1576 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1578 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1582 } /* namespace internal */
1584 template <typename LibObjT>
1585 class CommonTraceClass final : public BorrowedObject<LibObjT>
1588 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1590 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1592 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1593 CommonStreamClass<const bt_stream_class>>;
1596 using typename BorrowedObject<LibObjT>::LibObjPtr;
1597 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1598 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1600 explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1604 template <typename OtherLibObjT>
1605 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1606 _ThisBorrowedObject {traceClass}
1610 template <typename OtherLibObjT>
1611 CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1613 _ThisBorrowedObject::operator=(traceClass);
1617 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1619 return CommonTraceClass<const bt_trace_class> {*this};
1622 Trace::Shared instantiate() const
1624 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1626 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1628 internal::validateCreatedObjPtr(libObjPtr);
1629 return Trace::Shared::createWithoutRef(libObjPtr);
1632 StreamClass::Shared createStreamClass() const
1634 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1636 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1638 internal::validateCreatedObjPtr(libObjPtr);
1639 return StreamClass::Shared::createWithoutRef(libObjPtr);
1642 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1644 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1646 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1648 internal::validateCreatedObjPtr(libObjPtr);
1649 return StreamClass::Shared::createWithoutRef(libObjPtr);
1652 FieldClass::Shared createBoolFieldClass() const
1654 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1656 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1658 internal::validateCreatedObjPtr(libObjPtr);
1659 return FieldClass::Shared::createWithoutRef(libObjPtr);
1662 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1664 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1666 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1668 internal::validateCreatedObjPtr(libObjPtr);
1669 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1672 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1674 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1676 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1678 internal::validateCreatedObjPtr(libObjPtr);
1679 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1682 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1684 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1686 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1688 internal::validateCreatedObjPtr(libObjPtr);
1689 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1692 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1694 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1696 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1698 internal::validateCreatedObjPtr(libObjPtr);
1699 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1702 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1704 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1706 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1708 internal::validateCreatedObjPtr(libObjPtr);
1709 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1712 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1714 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1716 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1718 internal::validateCreatedObjPtr(libObjPtr);
1719 return FieldClass::Shared::createWithoutRef(libObjPtr);
1722 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1724 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1726 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1728 internal::validateCreatedObjPtr(libObjPtr);
1729 return FieldClass::Shared::createWithoutRef(libObjPtr);
1732 FieldClass::Shared createStringFieldClass() const
1734 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1736 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1738 internal::validateCreatedObjPtr(libObjPtr);
1739 return FieldClass::Shared::createWithoutRef(libObjPtr);
1742 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1743 const std::uint64_t length) const
1745 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1747 const auto libObjPtr = bt_field_class_array_static_create(
1748 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1750 internal::validateCreatedObjPtr(libObjPtr);
1751 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1754 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1756 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1758 const auto libObjPtr = bt_field_class_array_dynamic_create(
1759 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1761 internal::validateCreatedObjPtr(libObjPtr);
1762 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1765 DynamicArrayWithLengthFieldClass::Shared
1766 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1767 const IntegerFieldClass lengthFieldClass) const
1769 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1771 const auto libObjPtr = bt_field_class_array_dynamic_create(
1772 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1774 internal::validateCreatedObjPtr(libObjPtr);
1775 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1778 StructureFieldClass::Shared createStructureFieldClass() const
1780 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1782 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1784 internal::validateCreatedObjPtr(libObjPtr);
1785 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1788 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1790 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1792 const auto libObjPtr = bt_field_class_option_without_selector_create(
1793 this->libObjPtr(), optionalFieldClass.libObjPtr());
1795 internal::validateCreatedObjPtr(libObjPtr);
1796 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1799 OptionWithBoolSelectorFieldClass::Shared
1800 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1801 const FieldClass selectorFieldClass) const
1803 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1805 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1806 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1808 internal::validateCreatedObjPtr(libObjPtr);
1809 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1812 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1813 createOptionWithUnsignedIntegerSelectorFieldClass(
1814 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1815 const ConstUnsignedIntegerRangeSet ranges) const
1817 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1819 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1820 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1821 ranges.libObjPtr());
1823 internal::validateCreatedObjPtr(libObjPtr);
1824 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1827 OptionWithSignedIntegerSelectorFieldClass::Shared
1828 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1829 const IntegerFieldClass selectorFieldClass,
1830 const ConstSignedIntegerRangeSet ranges) const
1832 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1834 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1835 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1836 ranges.libObjPtr());
1838 internal::validateCreatedObjPtr(libObjPtr);
1839 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1842 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1844 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1846 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1848 internal::validateCreatedObjPtr(libObjPtr);
1849 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1852 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1853 createVariantWithUnsignedIntegerSelectorFieldClass(
1854 const IntegerFieldClass selectorFieldClass) const
1856 return this->_createVariantWithIntegerSelectorFieldClass<
1857 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1860 VariantWithSignedIntegerSelectorFieldClass::Shared
1861 createVariantWithSignedIntegerSelectorFieldClass(
1862 const IntegerFieldClass selectorFieldClass) const
1864 return this->_createVariantWithIntegerSelectorFieldClass<
1865 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
1868 CommonTraceClass assignsAutomaticStreamClassId(const bool val) const noexcept
1870 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1872 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
1873 static_cast<bt_bool>(val));
1877 bool assignsAutomaticStreamClassId() const noexcept
1879 return static_cast<bool>(
1880 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
1883 std::uint64_t length() const noexcept
1885 return bt_trace_class_get_stream_class_count(this->libObjPtr());
1888 _StreamClass operator[](const std::uint64_t index) const noexcept
1890 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
1893 OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
1895 return _Spec::streamClassById(this->libObjPtr(), id);
1898 template <typename LibValT>
1899 CommonTraceClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1901 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1903 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1907 UserAttributes userAttributes() const noexcept
1909 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1912 Shared shared() const noexcept
1914 return Shared::createWithRef(*this);
1918 template <typename ObjT>
1919 typename ObjT::Shared
1920 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
1922 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1924 const auto libObjPtr =
1925 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
1927 internal::validateCreatedObjPtr(libObjPtr);
1928 return ObjT::Shared::createWithoutRef(libObjPtr);
1932 using TraceClass = CommonTraceClass<bt_trace_class>;
1933 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
1935 namespace internal {
1937 struct TraceClassTypeDescr
1939 using Const = ConstTraceClass;
1940 using NonConst = TraceClass;
1944 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
1949 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
1953 } /* namespace internal */
1955 template <typename LibObjT>
1956 typename CommonStreamClass<LibObjT>::_TraceClass
1957 CommonStreamClass<LibObjT>::traceClass() const noexcept
1959 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
1962 template <typename LibObjT>
1963 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
1965 return Class {_Spec::cls(this->libObjPtr())};
1968 } /* namespace bt2 */
1970 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */