2 * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
11 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "cpp-common/optional.hpp"
16 #include "cpp-common/string_view.hpp"
18 #include "borrowed-object.hpp"
19 #include "clock-class.hpp"
20 #include "field-class.hpp"
22 #include "internal/utils.hpp"
23 #include "shared-object.hpp"
28 template <typename LibObjT>
31 template <typename LibObjT>
34 template <typename LibObjT>
37 template <typename LibObjT>
40 template <typename LibObjT>
41 class CommonEventClass;
43 template <typename LibObjT>
44 class CommonStreamClass;
46 template <typename LibObjT>
47 class CommonTraceClass;
51 template <typename LibObjT>
52 struct CommonEventSpec;
54 /* Functions specific to mutable events */
56 struct CommonEventSpec<bt_event> final
58 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
60 return bt_event_borrow_class(libObjPtr);
63 static bt_stream *stream(bt_event * const libObjPtr) noexcept
65 return bt_event_borrow_stream(libObjPtr);
68 static bt_packet *packet(bt_event * const libObjPtr) noexcept
70 return bt_event_borrow_packet(libObjPtr);
73 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
75 return bt_event_borrow_payload_field(libObjPtr);
78 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
80 return bt_event_borrow_specific_context_field(libObjPtr);
83 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
85 return bt_event_borrow_common_context_field(libObjPtr);
89 /* Functions specific to constant events */
91 struct CommonEventSpec<const bt_event> final
93 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
95 return bt_event_borrow_class_const(libObjPtr);
98 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
100 return bt_event_borrow_stream_const(libObjPtr);
103 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
105 return bt_event_borrow_packet_const(libObjPtr);
108 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
110 return bt_event_borrow_payload_field_const(libObjPtr);
113 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
115 return bt_event_borrow_specific_context_field_const(libObjPtr);
118 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
120 return bt_event_borrow_common_context_field_const(libObjPtr);
124 template <typename LibObjT>
125 using DepStructField = DepType<LibObjT, StructureField, ConstStructureField>;
127 } /* namespace internal */
129 template <typename LibObjT>
130 class CommonEvent final : public BorrowedObject<LibObjT>
133 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
134 using typename BorrowedObject<LibObjT>::_LibObjPtr;
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 Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
142 CommonEventClass<const bt_event_class>>;
144 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
148 template <typename OtherLibObjT>
149 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
153 template <typename OtherLibObjT>
154 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
156 _ThisBorrowedObject::operator=(event);
160 CommonEvent<const bt_event> asConst() const noexcept
162 return CommonEvent<const bt_event> {*this};
165 Class cls() const noexcept;
166 _Stream stream() const noexcept;
167 nonstd::optional<_Packet> packet() const noexcept;
169 nonstd::optional<_StructureField> payloadField() const noexcept
171 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
174 return _StructureField {libObjPtr};
177 return nonstd::nullopt;
180 nonstd::optional<_StructureField> specificContextField() const noexcept
182 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
185 return _StructureField {libObjPtr};
188 return nonstd::nullopt;
191 nonstd::optional<_StructureField> commonContextField() const noexcept
193 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
196 return _StructureField {libObjPtr};
199 return nonstd::nullopt;
203 using Event = CommonEvent<bt_event>;
204 using ConstEvent = CommonEvent<const bt_event>;
208 struct EventTypeDescr
210 using Const = ConstEvent;
211 using NonConst = Event;
215 struct TypeDescr<Event> : public EventTypeDescr
220 struct TypeDescr<ConstEvent> : public EventTypeDescr
224 struct PacketRefFuncs final
226 static void get(const bt_packet * const libObjPtr) noexcept
228 bt_packet_get_ref(libObjPtr);
231 static void put(const bt_packet * const libObjPtr) noexcept
233 bt_packet_put_ref(libObjPtr);
237 template <typename LibObjT>
238 struct CommonPacketSpec;
240 /* Functions specific to mutable packets */
242 struct CommonPacketSpec<bt_packet> final
244 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
246 return bt_packet_borrow_stream(libObjPtr);
249 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
251 return bt_packet_borrow_context_field(libObjPtr);
255 /* Functions specific to constant packets */
257 struct CommonPacketSpec<const bt_packet> final
259 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
261 return bt_packet_borrow_stream_const(libObjPtr);
264 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
266 return bt_packet_borrow_context_field_const(libObjPtr);
270 } /* namespace internal */
272 template <typename LibObjT>
273 class CommonPacket final : public BorrowedObject<LibObjT>
276 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
277 using typename BorrowedObject<LibObjT>::_LibObjPtr;
278 using _Spec = internal::CommonPacketSpec<LibObjT>;
279 using _ThisCommonPacket = CommonPacket<LibObjT>;
280 using _Stream = internal::DepStream<LibObjT>;
281 using _StructureField = internal::DepStructField<LibObjT>;
284 using Shared = SharedObject<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
286 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
290 template <typename OtherLibObjT>
291 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
295 template <typename OtherLibObjT>
296 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
298 _ThisBorrowedObject::operator=(packet);
302 CommonPacket<const bt_packet> asConst() const noexcept
304 return CommonPacket<const bt_packet> {*this};
307 _Stream stream() const noexcept;
309 nonstd::optional<_StructureField> contextField() const noexcept
311 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
314 return _StructureField {libObjPtr};
317 return nonstd::nullopt;
320 Shared shared() const noexcept
322 return Shared::createWithRef(*this);
326 using Packet = CommonPacket<bt_packet>;
327 using ConstPacket = CommonPacket<const bt_packet>;
331 struct PacketTypeDescr
333 using Const = ConstPacket;
334 using NonConst = Packet;
338 struct TypeDescr<Packet> : public PacketTypeDescr
343 struct TypeDescr<ConstPacket> : public PacketTypeDescr
347 } /* namespace internal */
349 template <typename LibObjT>
350 nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
351 CommonEvent<LibObjT>::packet() const noexcept
353 const auto libObjPtr = _Spec::packet(this->libObjPtr());
356 return _Packet {libObjPtr};
359 return nonstd::nullopt;
364 struct StreamRefFuncs final
366 static void get(const bt_stream * const libObjPtr) noexcept
368 bt_stream_get_ref(libObjPtr);
371 static void put(const bt_stream * const libObjPtr) noexcept
373 bt_stream_put_ref(libObjPtr);
377 template <typename LibObjT>
378 struct CommonStreamSpec;
380 /* Functions specific to mutable streams */
382 struct CommonStreamSpec<bt_stream> final
384 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
386 return bt_stream_borrow_class(libObjPtr);
389 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
391 return bt_stream_borrow_trace(libObjPtr);
394 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
396 return bt_stream_borrow_user_attributes(libObjPtr);
400 /* Functions specific to constant streams */
402 struct CommonStreamSpec<const bt_stream> final
404 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
406 return bt_stream_borrow_class_const(libObjPtr);
409 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
411 return bt_stream_borrow_trace_const(libObjPtr);
414 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
416 return bt_stream_borrow_user_attributes_const(libObjPtr);
420 } /* namespace internal */
422 template <typename LibObjT>
423 class CommonStream final : public BorrowedObject<LibObjT>
426 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
427 using typename BorrowedObject<LibObjT>::_LibObjPtr;
428 using _Spec = internal::CommonStreamSpec<LibObjT>;
429 using _ThisCommonStream = CommonStream<LibObjT>;
430 using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
433 using Shared = SharedObject<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
434 using UserAttributes = internal::DepUserAttrs<LibObjT>;
436 using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
437 CommonStreamClass<const bt_stream_class>>;
439 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
443 template <typename OtherLibObjT>
444 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
448 template <typename OtherLibObjT>
449 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
451 _ThisBorrowedObject::operator=(stream);
455 CommonStream<const bt_stream> asConst() const noexcept
457 return CommonStream<const bt_stream> {*this};
460 Packet::Shared createPacket() const
462 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
464 const auto libObjPtr = bt_packet_create(this->libObjPtr());
466 internal::validateCreatedObjPtr(libObjPtr);
467 return Packet::Shared::createWithoutRef(libObjPtr);
470 Class cls() const noexcept;
471 _Trace trace() const noexcept;
473 std::uint64_t id() const noexcept
475 return bt_stream_get_id(this->libObjPtr());
478 void name(const char * const name) const
480 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
482 const auto status = bt_stream_set_name(this->libObjPtr(), name);
484 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
485 throw MemoryError {};
489 void name(const std::string& name) const
491 this->name(name.data());
494 nonstd::optional<bpstd::string_view> name() const noexcept
496 const auto name = bt_stream_get_name(this->libObjPtr());
502 return nonstd::nullopt;
505 template <typename LibValT>
506 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
508 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
510 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
513 UserAttributes userAttributes() const noexcept
515 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
518 Shared shared() const noexcept
520 return Shared::createWithRef(*this);
524 using Stream = CommonStream<bt_stream>;
525 using ConstStream = CommonStream<const bt_stream>;
529 struct StreamTypeDescr
531 using Const = ConstStream;
532 using NonConst = Stream;
536 struct TypeDescr<Stream> : public StreamTypeDescr
541 struct TypeDescr<ConstStream> : public StreamTypeDescr
545 } /* namespace internal */
547 template <typename LibObjT>
548 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
550 return _Stream {_Spec::stream(this->libObjPtr())};
553 template <typename LibObjT>
554 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
556 return _Stream {_Spec::stream(this->libObjPtr())};
561 struct TraceRefFuncs final
563 static void get(const bt_trace * const libObjPtr) noexcept
565 bt_trace_get_ref(libObjPtr);
568 static void put(const bt_trace * const libObjPtr) noexcept
570 bt_trace_put_ref(libObjPtr);
574 template <typename LibObjT>
575 struct CommonTraceSpec;
577 /* Functions specific to mutable traces */
579 struct CommonTraceSpec<bt_trace> final
581 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
583 return bt_trace_borrow_class(libObjPtr);
586 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
588 return bt_trace_borrow_stream_by_index(libObjPtr, index);
591 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
593 return bt_trace_borrow_stream_by_id(libObjPtr, id);
596 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
598 return bt_trace_borrow_user_attributes(libObjPtr);
602 /* Functions specific to constant traces */
604 struct CommonTraceSpec<const bt_trace> final
606 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
608 return bt_trace_borrow_class_const(libObjPtr);
611 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
612 const std::uint64_t index) noexcept
614 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
617 static const bt_stream *streamById(const bt_trace * const libObjPtr,
618 const std::uint64_t id) noexcept
620 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
623 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
625 return bt_trace_borrow_user_attributes_const(libObjPtr);
629 } /* namespace internal */
631 template <typename LibObjT>
632 class CommonTrace final : public BorrowedObject<LibObjT>
635 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
636 using typename BorrowedObject<LibObjT>::_LibObjPtr;
637 using _Spec = internal::CommonTraceSpec<LibObjT>;
638 using _ThisCommonTrace = CommonTrace<LibObjT>;
639 using _Stream = internal::DepStream<LibObjT>;
642 using Shared = SharedObject<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
643 using UserAttributes = internal::DepUserAttrs<LibObjT>;
645 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
646 CommonTraceClass<const bt_trace_class>>;
648 struct ConstEnvironmentEntry
650 bpstd::string_view name;
654 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
658 template <typename OtherLibObjT>
659 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
663 template <typename OtherLibObjT>
664 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
666 _ThisBorrowedObject::operator=(trace);
670 CommonTrace<const bt_trace> asConst() const noexcept
672 return CommonTrace<const bt_trace> {*this};
675 Class cls() const noexcept;
677 void name(const char * const name) const
679 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
681 const auto status = bt_trace_set_name(this->libObjPtr(), name);
683 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
684 throw MemoryError {};
688 void name(const std::string& name) const
690 this->name(name.data());
693 nonstd::optional<bpstd::string_view> name() const noexcept
695 const auto name = bt_trace_get_name(this->libObjPtr());
701 return nonstd::nullopt;
704 void uuid(const bt2_common::UuidView& uuid) const noexcept
706 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
709 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
711 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
714 return bt2_common::UuidView {uuid};
717 return nonstd::nullopt;
720 std::uint64_t length() const noexcept
722 return bt_trace_get_stream_count(this->libObjPtr());
725 _Stream operator[](const std::uint64_t index) const noexcept
727 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
730 nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
732 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
735 return _Stream {libObjPtr};
738 return nonstd::nullopt;
741 void environmentEntry(const char * const name, const std::int64_t val) const
743 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
745 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
747 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
748 throw MemoryError {};
752 void environmentEntry(const std::string& name, const std::int64_t val) const
754 this->environmentEntry(name.data(), val);
757 void environmentEntry(const char * const name, const char * const val) const
759 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
761 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
763 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
764 throw MemoryError {};
768 void environmentEntry(const std::string& name, const char * const val) const
770 this->environmentEntry(name.data(), val);
773 void environmentEntry(const char * const name, const std::string& val) const
775 this->environmentEntry(name, val.data());
778 void environmentEntry(const std::string& name, const std::string& val) const
780 this->environmentEntry(name.data(), val.data());
783 std::uint64_t environmentSize() const noexcept
785 return bt_trace_get_environment_entry_count(this->libObjPtr());
788 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
791 const bt_value *libObjPtr;
793 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
795 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
798 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
800 const auto libObjPtr =
801 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
804 return ConstValue {libObjPtr};
807 return nonstd::nullopt;
810 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
812 return this->environmentEntry(name.data());
815 template <typename LibValT>
816 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
818 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
820 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
823 UserAttributes userAttributes() const noexcept
825 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
828 Shared shared() const noexcept
830 return Shared::createWithRef(*this);
834 using Trace = CommonTrace<bt_trace>;
835 using ConstTrace = CommonTrace<const bt_trace>;
839 struct TraceTypeDescr
841 using Const = ConstTrace;
842 using NonConst = Trace;
846 struct TypeDescr<Trace> : public TraceTypeDescr
851 struct TypeDescr<ConstTrace> : public TraceTypeDescr
855 } /* namespace internal */
857 template <typename LibObjT>
858 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
860 return _Trace {_Spec::trace(this->libObjPtr())};
865 struct EventClassRefFuncs final
867 static void get(const bt_event_class * const libObjPtr) noexcept
869 bt_event_class_get_ref(libObjPtr);
872 static void put(const bt_event_class * const libObjPtr) noexcept
874 bt_event_class_put_ref(libObjPtr);
878 template <typename LibObjT>
879 struct CommonEventClassSpec;
881 /* Functions specific to mutable event classes */
883 struct CommonEventClassSpec<bt_event_class> final
885 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
887 return bt_event_class_borrow_stream_class(libObjPtr);
890 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
892 return bt_event_class_borrow_payload_field_class(libObjPtr);
895 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
897 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
900 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
902 return bt_event_class_borrow_user_attributes(libObjPtr);
906 /* Functions specific to constant event classes */
908 struct CommonEventClassSpec<const bt_event_class> final
910 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
912 return bt_event_class_borrow_stream_class_const(libObjPtr);
915 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
917 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
920 static const bt_field_class *
921 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
923 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
926 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
928 return bt_event_class_borrow_user_attributes_const(libObjPtr);
932 template <typename LibObjT>
933 using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
935 } /* namespace internal */
937 template <typename LibObjT>
938 class CommonEventClass final : public BorrowedObject<LibObjT>
941 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
942 using typename BorrowedObject<LibObjT>::_LibObjPtr;
943 using _Spec = internal::CommonEventClassSpec<LibObjT>;
944 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
945 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
947 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
948 CommonStreamClass<const bt_stream_class>>;
951 using Shared = SharedObject<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
953 using UserAttributes = internal::DepUserAttrs<LibObjT>;
957 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
958 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
959 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
960 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
961 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
962 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
963 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
964 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
965 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
966 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
967 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
968 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
969 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
970 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
971 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
974 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
978 template <typename OtherLibObjT>
979 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
980 _ThisBorrowedObject {eventClass}
984 template <typename OtherLibObjT>
985 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
987 _ThisBorrowedObject::operator=(eventClass);
991 CommonEventClass<const bt_event_class> asConst() const noexcept
993 return CommonEventClass<const bt_event_class> {*this};
996 _StreamClass streamClass() const noexcept;
998 std::uint64_t id() const noexcept
1000 return bt_event_class_get_id(this->libObjPtr());
1003 void name(const char * const name) const
1005 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1007 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1009 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1010 throw MemoryError {};
1014 void name(const std::string& name) const
1016 this->name(name.data());
1019 nonstd::optional<bpstd::string_view> name() const noexcept
1021 const auto name = bt_event_class_get_name(this->libObjPtr());
1027 return nonstd::nullopt;
1030 void logLevel(const LogLevel logLevel) const noexcept
1032 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1034 bt_event_class_set_log_level(this->libObjPtr(),
1035 static_cast<bt_event_class_log_level>(logLevel));
1038 nonstd::optional<LogLevel> logLevel() const noexcept
1040 bt_event_class_log_level libLogLevel;
1041 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1043 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1044 return static_cast<LogLevel>(libLogLevel);
1047 return nonstd::nullopt;
1050 void emfUri(const char * const emfUri) const
1052 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1054 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1056 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1057 throw MemoryError {};
1061 void emfUri(const std::string& emfUri) const
1063 this->emfUri(emfUri.data());
1066 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1068 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1074 return nonstd::nullopt;
1077 void payloadFieldClass(const StructureFieldClass fc) const
1079 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1082 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1084 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1085 throw MemoryError {};
1089 nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
1091 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1094 return _StructureFieldClass {libObjPtr};
1097 return nonstd::nullopt;
1100 void specificContextFieldClass(const StructureFieldClass fc) const
1102 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1105 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1107 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1108 throw MemoryError {};
1112 nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
1114 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1117 return _StructureFieldClass {libObjPtr};
1120 return nonstd::nullopt;
1123 template <typename LibValT>
1124 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1126 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1128 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1131 UserAttributes userAttributes() const noexcept
1133 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1136 Shared shared() const noexcept
1138 return Shared::createWithRef(*this);
1142 using EventClass = CommonEventClass<bt_event_class>;
1143 using ConstEventClass = CommonEventClass<const bt_event_class>;
1145 namespace internal {
1147 struct EventClassTypeDescr
1149 using Const = ConstEventClass;
1150 using NonConst = EventClass;
1154 struct TypeDescr<EventClass> : public EventClassTypeDescr
1159 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1163 } /* namespace internal */
1165 template <typename LibObjT>
1166 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1168 return Class {_Spec::cls(this->libObjPtr())};
1171 namespace internal {
1173 struct StreamClassRefFuncs final
1175 static void get(const bt_stream_class * const libObjPtr) noexcept
1177 bt_stream_class_get_ref(libObjPtr);
1180 static void put(const bt_stream_class * const libObjPtr) noexcept
1182 bt_stream_class_put_ref(libObjPtr);
1186 template <typename LibObjT>
1187 struct CommonStreamClassSpec;
1189 /* Functions specific to mutable stream classes */
1191 struct CommonStreamClassSpec<bt_stream_class> final
1193 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1195 return bt_stream_class_borrow_trace_class(libObjPtr);
1198 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1199 const std::uint64_t index) noexcept
1201 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1204 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1205 const std::uint64_t id) noexcept
1207 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1210 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1212 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1215 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1217 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1220 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1222 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1225 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1227 return bt_stream_class_borrow_user_attributes(libObjPtr);
1231 /* Functions specific to constant stream classes */
1233 struct CommonStreamClassSpec<const bt_stream_class> final
1235 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1237 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1240 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1241 const std::uint64_t index) noexcept
1243 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1246 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1247 const std::uint64_t id) noexcept
1249 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1252 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1254 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1257 static const bt_field_class *
1258 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1260 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1263 static const bt_field_class *
1264 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1266 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1269 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1271 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1275 } /* namespace internal */
1277 template <typename LibObjT>
1278 class CommonStreamClass final : public BorrowedObject<LibObjT>
1281 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1282 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1283 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1284 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1285 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
1287 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1288 CommonTraceClass<const bt_trace_class>>;
1290 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1291 CommonEventClass<const bt_event_class>>;
1293 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
1296 using Shared = SharedObject<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1298 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1300 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
1301 _ThisBorrowedObject {libObjPtr}
1305 template <typename OtherLibObjT>
1306 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1307 _ThisBorrowedObject {streamClass}
1311 template <typename OtherLibObjT>
1312 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1314 _ThisBorrowedObject::operator=(streamClass);
1318 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1320 return CommonStreamClass<const bt_stream_class> {*this};
1323 Stream::Shared instantiate(const Trace trace) const
1325 static_assert(!std::is_const<LibObjT>::value,
1326 "Not available with `bt2::ConstStreamClass`.");
1328 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1330 internal::validateCreatedObjPtr(libObjPtr);
1331 return Stream::Shared::createWithoutRef(libObjPtr);
1334 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1336 static_assert(!std::is_const<LibObjT>::value,
1337 "Not available with `bt2::ConstStreamClass`.");
1339 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1341 internal::validateCreatedObjPtr(libObjPtr);
1342 return Stream::Shared::createWithoutRef(libObjPtr);
1345 EventClass::Shared createEventClass() const
1347 static_assert(!std::is_const<LibObjT>::value,
1348 "Not available with `bt2::ConstStreamClass`.");
1350 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1352 internal::validateCreatedObjPtr(libObjPtr);
1353 return EventClass::Shared::createWithoutRef(libObjPtr);
1356 EventClass::Shared createEventClass(const std::uint64_t id) const
1358 static_assert(!std::is_const<LibObjT>::value,
1359 "Not available with `bt2::ConstStreamClass`.");
1361 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1363 internal::validateCreatedObjPtr(libObjPtr);
1364 return EventClass::Shared::createWithoutRef(libObjPtr);
1367 _TraceClass traceClass() const noexcept;
1369 std::uint64_t id() const noexcept
1371 return bt_stream_class_get_id(this->libObjPtr());
1374 void name(const char * const name) const
1376 static_assert(!std::is_const<LibObjT>::value,
1377 "Not available with `bt2::ConstStreamClass`.");
1379 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1381 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1382 throw MemoryError {};
1386 void name(const std::string& name) const
1388 this->name(name.data());
1391 nonstd::optional<bpstd::string_view> name() const noexcept
1393 const auto name = bt_stream_class_get_name(this->libObjPtr());
1399 return nonstd::nullopt;
1402 void assignsAutomaticEventClassId(const bool val) const noexcept
1404 static_assert(!std::is_const<LibObjT>::value,
1405 "Not available with `bt2::ConstStreamClass`.");
1407 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1408 static_cast<bt_bool>(val));
1411 bool assignsAutomaticEventClassId() const noexcept
1413 return static_cast<bool>(
1414 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1417 void assignsAutomaticStreamId(const bool val) const noexcept
1419 static_assert(!std::is_const<LibObjT>::value,
1420 "Not available with `bt2::ConstStreamClass`.");
1422 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1423 static_cast<bt_bool>(val));
1426 bool assignsAutomaticStreamId() const noexcept
1428 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1431 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1432 const bool withEndDefaultClkSnapshot) const noexcept
1434 static_assert(!std::is_const<LibObjT>::value,
1435 "Not available with `bt2::ConstStreamClass`.");
1437 bt_stream_class_set_supports_packets(this->libObjPtr(),
1438 static_cast<bt_bool>(supportsPackets),
1439 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1440 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1443 bool supportsPackets() const noexcept
1445 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1448 bool packetsHaveBeginningClockSnapshot() const noexcept
1450 return static_cast<bool>(
1451 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1454 bool packetsHaveEndClockSnapshot() const noexcept
1456 return static_cast<bool>(
1457 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1460 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1461 const bool withDefaultClkSnapshots) const noexcept
1463 static_assert(!std::is_const<LibObjT>::value,
1464 "Not available with `bt2::ConstStreamClass`.");
1466 bt_stream_class_set_supports_discarded_events(
1467 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1468 static_cast<bt_bool>(withDefaultClkSnapshots));
1471 bool supportsDiscardedEvents() const noexcept
1473 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1476 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1478 return static_cast<bool>(
1479 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1482 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1483 const bool withDefaultClkSnapshots) const noexcept
1485 static_assert(!std::is_const<LibObjT>::value,
1486 "Not available with `bt2::ConstStreamClass`.");
1488 bt_stream_class_set_supports_discarded_packets(
1489 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1490 static_cast<bt_bool>(withDefaultClkSnapshots));
1493 bool supportsDiscardedPackets() const noexcept
1495 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1498 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1500 return static_cast<bool>(
1501 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1504 void defaultClockClass(const ClockClass clkCls) const
1506 static_assert(!std::is_const<LibObjT>::value,
1507 "Not available with `bt2::ConstStreamClass`.");
1510 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1512 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1515 nonstd::optional<_ClockClass> defaultClockClass() const noexcept
1517 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1520 return _ClockClass {libObjPtr};
1523 return nonstd::nullopt;
1526 std::uint64_t length() const noexcept
1528 return bt_stream_class_get_event_class_count(this->libObjPtr());
1531 _EventClass operator[](const std::uint64_t index) const noexcept
1533 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1536 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1538 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1541 return _EventClass {libObjPtr};
1544 return nonstd::nullopt;
1547 void packetContextFieldClass(const StructureFieldClass fc) const
1549 static_assert(!std::is_const<LibObjT>::value,
1550 "Not available with `bt2::ConstStreamClass`.");
1553 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1555 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1556 throw MemoryError {};
1560 nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
1562 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1565 return _StructureFieldClass {libObjPtr};
1568 return nonstd::nullopt;
1571 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1573 static_assert(!std::is_const<LibObjT>::value,
1574 "Not available with `bt2::ConstStreamClass`.");
1577 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1579 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1580 throw MemoryError {};
1584 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1586 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1589 return _StructureFieldClass {libObjPtr};
1592 return nonstd::nullopt;
1595 template <typename LibValT>
1596 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1598 static_assert(!std::is_const<LibObjT>::value,
1599 "Not available with `bt2::ConstStreamClass`.");
1601 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1604 UserAttributes userAttributes() const noexcept
1606 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1609 Shared shared() const noexcept
1611 return Shared::createWithRef(*this);
1615 using StreamClass = CommonStreamClass<bt_stream_class>;
1616 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1618 namespace internal {
1620 struct StreamClassTypeDescr
1622 using Const = ConstStreamClass;
1623 using NonConst = StreamClass;
1627 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1632 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1636 } /* namespace internal */
1638 template <typename LibObjT>
1639 typename CommonEventClass<LibObjT>::_StreamClass
1640 CommonEventClass<LibObjT>::streamClass() const noexcept
1642 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1645 template <typename LibObjT>
1646 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1648 return Class {_Spec::cls(this->libObjPtr())};
1651 namespace internal {
1653 struct TraceClassRefFuncs final
1655 static void get(const bt_trace_class * const libObjPtr) noexcept
1657 bt_trace_class_get_ref(libObjPtr);
1660 static void put(const bt_trace_class * const libObjPtr) noexcept
1662 bt_trace_class_put_ref(libObjPtr);
1666 template <typename LibObjT>
1667 struct CommonTraceClassSpec;
1669 /* Functions specific to mutable stream classes */
1671 struct CommonTraceClassSpec<bt_trace_class> final
1673 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1674 const std::uint64_t index) noexcept
1676 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1679 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1680 const std::uint64_t id) noexcept
1682 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1685 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1687 return bt_trace_class_borrow_user_attributes(libObjPtr);
1691 /* Functions specific to constant stream classes */
1693 struct CommonTraceClassSpec<const bt_trace_class> final
1695 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1696 const std::uint64_t index) noexcept
1698 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1701 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1702 const std::uint64_t id) noexcept
1704 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1707 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1709 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1713 } /* namespace internal */
1715 template <typename LibObjT>
1716 class CommonTraceClass final : public BorrowedObject<LibObjT>
1719 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1720 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1721 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1722 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1724 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1725 CommonStreamClass<const bt_stream_class>>;
1728 using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1730 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1732 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1736 template <typename OtherLibObjT>
1737 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1738 _ThisBorrowedObject {traceClass}
1742 template <typename OtherLibObjT>
1743 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1745 _ThisBorrowedObject::operator=(traceClass);
1749 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1751 return CommonTraceClass<const bt_trace_class> {*this};
1754 Trace::Shared instantiate() const
1756 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1758 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1760 internal::validateCreatedObjPtr(libObjPtr);
1761 return Trace::Shared::createWithoutRef(libObjPtr);
1764 StreamClass::Shared createStreamClass() const
1766 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1768 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1770 internal::validateCreatedObjPtr(libObjPtr);
1771 return StreamClass::Shared::createWithoutRef(libObjPtr);
1774 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1776 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1778 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1780 internal::validateCreatedObjPtr(libObjPtr);
1781 return StreamClass::Shared::createWithoutRef(libObjPtr);
1784 FieldClass::Shared createBoolFieldClass() const
1786 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1788 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1790 internal::validateCreatedObjPtr(libObjPtr);
1791 return FieldClass::Shared::createWithoutRef(libObjPtr);
1794 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1796 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1798 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1800 internal::validateCreatedObjPtr(libObjPtr);
1801 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1804 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1806 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1808 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1810 internal::validateCreatedObjPtr(libObjPtr);
1811 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1814 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1816 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1818 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1820 internal::validateCreatedObjPtr(libObjPtr);
1821 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1824 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1826 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1828 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1830 internal::validateCreatedObjPtr(libObjPtr);
1831 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1834 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1836 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1838 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1840 internal::validateCreatedObjPtr(libObjPtr);
1841 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1844 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1846 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1848 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1850 internal::validateCreatedObjPtr(libObjPtr);
1851 return FieldClass::Shared::createWithoutRef(libObjPtr);
1854 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1856 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1858 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1860 internal::validateCreatedObjPtr(libObjPtr);
1861 return FieldClass::Shared::createWithoutRef(libObjPtr);
1864 FieldClass::Shared createStringFieldClass() const
1866 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1868 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1870 internal::validateCreatedObjPtr(libObjPtr);
1871 return FieldClass::Shared::createWithoutRef(libObjPtr);
1874 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1875 const std::uint64_t length) const
1877 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1879 const auto libObjPtr = bt_field_class_array_static_create(
1880 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1882 internal::validateCreatedObjPtr(libObjPtr);
1883 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1886 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1888 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1890 const auto libObjPtr = bt_field_class_array_dynamic_create(
1891 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1893 internal::validateCreatedObjPtr(libObjPtr);
1894 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1897 DynamicArrayWithLengthFieldClass::Shared
1898 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1899 const IntegerFieldClass lengthFieldClass) const
1901 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1903 const auto libObjPtr = bt_field_class_array_dynamic_create(
1904 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1906 internal::validateCreatedObjPtr(libObjPtr);
1907 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1910 StructureFieldClass::Shared createStructureFieldClass() const
1912 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1914 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1916 internal::validateCreatedObjPtr(libObjPtr);
1917 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1920 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1922 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1924 const auto libObjPtr = bt_field_class_option_without_selector_create(
1925 this->libObjPtr(), optionalFieldClass.libObjPtr());
1927 internal::validateCreatedObjPtr(libObjPtr);
1928 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1931 OptionWithBoolSelectorFieldClass::Shared
1932 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1933 const FieldClass selectorFieldClass) const
1935 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1937 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1938 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1940 internal::validateCreatedObjPtr(libObjPtr);
1941 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1944 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1945 createOptionWithUnsignedIntegerSelectorFieldClass(
1946 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1947 const ConstUnsignedIntegerRangeSet ranges) const
1949 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1951 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1952 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1953 ranges.libObjPtr());
1955 internal::validateCreatedObjPtr(libObjPtr);
1956 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1959 OptionWithSignedIntegerSelectorFieldClass::Shared
1960 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1961 const IntegerFieldClass selectorFieldClass,
1962 const ConstSignedIntegerRangeSet ranges) const
1964 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1966 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1967 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1968 ranges.libObjPtr());
1970 internal::validateCreatedObjPtr(libObjPtr);
1971 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1974 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1976 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1978 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1980 internal::validateCreatedObjPtr(libObjPtr);
1981 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1984 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1985 createVariantWithUnsignedIntegerSelectorFieldClass(
1986 const IntegerFieldClass selectorFieldClass) const
1988 return this->_createVariantWithIntegerSelectorFieldClass<
1989 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1992 VariantWithSignedIntegerSelectorFieldClass::Shared
1993 createVariantWithSignedIntegerSelectorFieldClass(
1994 const IntegerFieldClass selectorFieldClass) const
1996 return this->_createVariantWithIntegerSelectorFieldClass<
1997 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
2000 void assignsAutomaticStreamClassId(const bool val) const noexcept
2002 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2004 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
2005 static_cast<bt_bool>(val));
2008 bool assignsAutomaticStreamClassId() const noexcept
2010 return static_cast<bool>(
2011 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2014 std::uint64_t length() const noexcept
2016 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2019 _StreamClass operator[](const std::uint64_t index) const noexcept
2021 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2024 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
2026 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2029 return _StreamClass {libObjPtr};
2032 return nonstd::nullopt;
2035 template <typename LibValT>
2036 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
2038 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2040 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2043 UserAttributes userAttributes() const noexcept
2045 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2048 Shared shared() const noexcept
2050 return Shared::createWithRef(*this);
2054 template <typename ObjT>
2055 typename ObjT::Shared
2056 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
2058 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2060 const auto libObjPtr =
2061 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2063 internal::validateCreatedObjPtr(libObjPtr);
2064 return ObjT::Shared::createWithoutRef(libObjPtr);
2068 using TraceClass = CommonTraceClass<bt_trace_class>;
2069 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2071 namespace internal {
2073 struct TraceClassTypeDescr
2075 using Const = ConstTraceClass;
2076 using NonConst = TraceClass;
2080 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2085 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2089 } /* namespace internal */
2091 template <typename LibObjT>
2092 typename CommonStreamClass<LibObjT>::_TraceClass
2093 CommonStreamClass<LibObjT>::traceClass() const noexcept
2095 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2098 template <typename LibObjT>
2099 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
2101 return Class {_Spec::cls(this->libObjPtr())};
2104 } /* namespace bt2 */
2106 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */