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 _Stream = internal::DepStream<LibObjT>;
280 using _StructureField = internal::DepStructField<LibObjT>;
283 using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
285 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
289 template <typename OtherLibObjT>
290 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
294 template <typename OtherLibObjT>
295 CommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
297 _ThisBorrowedObject::operator=(packet);
301 CommonPacket<const bt_packet> asConst() const noexcept
303 return CommonPacket<const bt_packet> {*this};
306 _Stream stream() const noexcept;
308 nonstd::optional<_StructureField> contextField() const noexcept
310 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
313 return _StructureField {libObjPtr};
316 return nonstd::nullopt;
319 Shared shared() const noexcept
321 return Shared::createWithRef(*this);
325 using Packet = CommonPacket<bt_packet>;
326 using ConstPacket = CommonPacket<const bt_packet>;
330 struct PacketTypeDescr
332 using Const = ConstPacket;
333 using NonConst = Packet;
337 struct TypeDescr<Packet> : public PacketTypeDescr
342 struct TypeDescr<ConstPacket> : public PacketTypeDescr
346 } /* namespace internal */
348 template <typename LibObjT>
349 nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
350 CommonEvent<LibObjT>::packet() const noexcept
352 const auto libObjPtr = _Spec::packet(this->libObjPtr());
355 return _Packet {libObjPtr};
358 return nonstd::nullopt;
363 struct StreamRefFuncs final
365 static void get(const bt_stream * const libObjPtr) noexcept
367 bt_stream_get_ref(libObjPtr);
370 static void put(const bt_stream * const libObjPtr) noexcept
372 bt_stream_put_ref(libObjPtr);
376 template <typename LibObjT>
377 struct CommonStreamSpec;
379 /* Functions specific to mutable streams */
381 struct CommonStreamSpec<bt_stream> final
383 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
385 return bt_stream_borrow_class(libObjPtr);
388 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
390 return bt_stream_borrow_trace(libObjPtr);
393 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
395 return bt_stream_borrow_user_attributes(libObjPtr);
399 /* Functions specific to constant streams */
401 struct CommonStreamSpec<const bt_stream> final
403 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
405 return bt_stream_borrow_class_const(libObjPtr);
408 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
410 return bt_stream_borrow_trace_const(libObjPtr);
413 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
415 return bt_stream_borrow_user_attributes_const(libObjPtr);
419 } /* namespace internal */
421 template <typename LibObjT>
422 class CommonStream final : public BorrowedObject<LibObjT>
425 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
426 using typename BorrowedObject<LibObjT>::_LibObjPtr;
427 using _Spec = internal::CommonStreamSpec<LibObjT>;
428 using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
431 using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
432 using UserAttributes = internal::DepUserAttrs<LibObjT>;
434 using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
435 CommonStreamClass<const bt_stream_class>>;
437 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
441 template <typename OtherLibObjT>
442 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
446 template <typename OtherLibObjT>
447 CommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
449 _ThisBorrowedObject::operator=(stream);
453 CommonStream<const bt_stream> asConst() const noexcept
455 return CommonStream<const bt_stream> {*this};
458 Packet::Shared createPacket() const
460 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
462 const auto libObjPtr = bt_packet_create(this->libObjPtr());
464 internal::validateCreatedObjPtr(libObjPtr);
465 return Packet::Shared::createWithoutRef(libObjPtr);
468 Class cls() const noexcept;
469 _Trace trace() const noexcept;
471 std::uint64_t id() const noexcept
473 return bt_stream_get_id(this->libObjPtr());
476 void name(const char * const name) const
478 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
480 const auto status = bt_stream_set_name(this->libObjPtr(), name);
482 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
483 throw MemoryError {};
487 void name(const std::string& name) const
489 this->name(name.data());
492 nonstd::optional<bpstd::string_view> name() const noexcept
494 const auto name = bt_stream_get_name(this->libObjPtr());
500 return nonstd::nullopt;
503 template <typename LibValT>
504 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
506 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
508 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
511 UserAttributes userAttributes() const noexcept
513 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
516 Shared shared() const noexcept
518 return Shared::createWithRef(*this);
522 using Stream = CommonStream<bt_stream>;
523 using ConstStream = CommonStream<const bt_stream>;
527 struct StreamTypeDescr
529 using Const = ConstStream;
530 using NonConst = Stream;
534 struct TypeDescr<Stream> : public StreamTypeDescr
539 struct TypeDescr<ConstStream> : public StreamTypeDescr
543 } /* namespace internal */
545 template <typename LibObjT>
546 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
548 return _Stream {_Spec::stream(this->libObjPtr())};
551 template <typename LibObjT>
552 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
554 return _Stream {_Spec::stream(this->libObjPtr())};
559 struct TraceRefFuncs final
561 static void get(const bt_trace * const libObjPtr) noexcept
563 bt_trace_get_ref(libObjPtr);
566 static void put(const bt_trace * const libObjPtr) noexcept
568 bt_trace_put_ref(libObjPtr);
572 template <typename LibObjT>
573 struct CommonTraceSpec;
575 /* Functions specific to mutable traces */
577 struct CommonTraceSpec<bt_trace> final
579 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
581 return bt_trace_borrow_class(libObjPtr);
584 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
586 return bt_trace_borrow_stream_by_index(libObjPtr, index);
589 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
591 return bt_trace_borrow_stream_by_id(libObjPtr, id);
594 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
596 return bt_trace_borrow_user_attributes(libObjPtr);
600 /* Functions specific to constant traces */
602 struct CommonTraceSpec<const bt_trace> final
604 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
606 return bt_trace_borrow_class_const(libObjPtr);
609 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
610 const std::uint64_t index) noexcept
612 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
615 static const bt_stream *streamById(const bt_trace * const libObjPtr,
616 const std::uint64_t id) noexcept
618 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
621 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
623 return bt_trace_borrow_user_attributes_const(libObjPtr);
627 } /* namespace internal */
629 template <typename LibObjT>
630 class CommonTrace final : public BorrowedObject<LibObjT>
633 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
634 using typename BorrowedObject<LibObjT>::_LibObjPtr;
635 using _Spec = internal::CommonTraceSpec<LibObjT>;
636 using _Stream = internal::DepStream<LibObjT>;
639 using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
640 using UserAttributes = internal::DepUserAttrs<LibObjT>;
642 using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
643 CommonTraceClass<const bt_trace_class>>;
645 struct ConstEnvironmentEntry
647 bpstd::string_view name;
651 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
655 template <typename OtherLibObjT>
656 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
660 template <typename OtherLibObjT>
661 CommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
663 _ThisBorrowedObject::operator=(trace);
667 CommonTrace<const bt_trace> asConst() const noexcept
669 return CommonTrace<const bt_trace> {*this};
672 Class cls() const noexcept;
674 void name(const char * const name) const
676 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
678 const auto status = bt_trace_set_name(this->libObjPtr(), name);
680 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
681 throw MemoryError {};
685 void name(const std::string& name) const
687 this->name(name.data());
690 nonstd::optional<bpstd::string_view> name() const noexcept
692 const auto name = bt_trace_get_name(this->libObjPtr());
698 return nonstd::nullopt;
701 void uuid(const bt2_common::UuidView& uuid) const noexcept
703 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
706 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
708 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
711 return bt2_common::UuidView {uuid};
714 return nonstd::nullopt;
717 std::uint64_t length() const noexcept
719 return bt_trace_get_stream_count(this->libObjPtr());
722 _Stream operator[](const std::uint64_t index) const noexcept
724 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
727 nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
729 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
732 return _Stream {libObjPtr};
735 return nonstd::nullopt;
738 void environmentEntry(const char * const name, const std::int64_t val) const
740 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
742 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
744 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
745 throw MemoryError {};
749 void environmentEntry(const std::string& name, const std::int64_t val) const
751 this->environmentEntry(name.data(), val);
754 void environmentEntry(const char * const name, const char * const val) const
756 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
758 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
760 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
761 throw MemoryError {};
765 void environmentEntry(const std::string& name, const char * const val) const
767 this->environmentEntry(name.data(), val);
770 void environmentEntry(const char * const name, const std::string& val) const
772 this->environmentEntry(name, val.data());
775 void environmentEntry(const std::string& name, const std::string& val) const
777 this->environmentEntry(name.data(), val.data());
780 std::uint64_t environmentSize() const noexcept
782 return bt_trace_get_environment_entry_count(this->libObjPtr());
785 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
788 const bt_value *libObjPtr;
790 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
792 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
795 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
797 const auto libObjPtr =
798 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
801 return ConstValue {libObjPtr};
804 return nonstd::nullopt;
807 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
809 return this->environmentEntry(name.data());
812 template <typename LibValT>
813 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
815 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
817 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
820 UserAttributes userAttributes() const noexcept
822 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
825 Shared shared() const noexcept
827 return Shared::createWithRef(*this);
831 using Trace = CommonTrace<bt_trace>;
832 using ConstTrace = CommonTrace<const bt_trace>;
836 struct TraceTypeDescr
838 using Const = ConstTrace;
839 using NonConst = Trace;
843 struct TypeDescr<Trace> : public TraceTypeDescr
848 struct TypeDescr<ConstTrace> : public TraceTypeDescr
852 } /* namespace internal */
854 template <typename LibObjT>
855 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
857 return _Trace {_Spec::trace(this->libObjPtr())};
862 struct EventClassRefFuncs final
864 static void get(const bt_event_class * const libObjPtr) noexcept
866 bt_event_class_get_ref(libObjPtr);
869 static void put(const bt_event_class * const libObjPtr) noexcept
871 bt_event_class_put_ref(libObjPtr);
875 template <typename LibObjT>
876 struct CommonEventClassSpec;
878 /* Functions specific to mutable event classes */
880 struct CommonEventClassSpec<bt_event_class> final
882 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
884 return bt_event_class_borrow_stream_class(libObjPtr);
887 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
889 return bt_event_class_borrow_payload_field_class(libObjPtr);
892 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
894 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
897 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
899 return bt_event_class_borrow_user_attributes(libObjPtr);
903 /* Functions specific to constant event classes */
905 struct CommonEventClassSpec<const bt_event_class> final
907 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
909 return bt_event_class_borrow_stream_class_const(libObjPtr);
912 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
914 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
917 static const bt_field_class *
918 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
920 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
923 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
925 return bt_event_class_borrow_user_attributes_const(libObjPtr);
929 template <typename LibObjT>
930 using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
932 } /* namespace internal */
934 template <typename LibObjT>
935 class CommonEventClass final : public BorrowedObject<LibObjT>
938 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
939 using typename BorrowedObject<LibObjT>::_LibObjPtr;
940 using _Spec = internal::CommonEventClassSpec<LibObjT>;
941 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
943 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
944 CommonStreamClass<const bt_stream_class>>;
947 using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
948 using UserAttributes = internal::DepUserAttrs<LibObjT>;
952 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
953 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
954 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
955 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
956 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
957 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
958 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
959 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
960 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
961 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
962 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
963 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
964 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
965 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
966 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
969 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
973 template <typename OtherLibObjT>
974 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
975 _ThisBorrowedObject {eventClass}
979 template <typename OtherLibObjT>
980 CommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
982 _ThisBorrowedObject::operator=(eventClass);
986 CommonEventClass<const bt_event_class> asConst() const noexcept
988 return CommonEventClass<const bt_event_class> {*this};
991 _StreamClass streamClass() const noexcept;
993 std::uint64_t id() const noexcept
995 return bt_event_class_get_id(this->libObjPtr());
998 void name(const char * const name) const
1000 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1002 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1004 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1005 throw MemoryError {};
1009 void name(const std::string& name) const
1011 this->name(name.data());
1014 nonstd::optional<bpstd::string_view> name() const noexcept
1016 const auto name = bt_event_class_get_name(this->libObjPtr());
1022 return nonstd::nullopt;
1025 void logLevel(const LogLevel logLevel) const noexcept
1027 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1029 bt_event_class_set_log_level(this->libObjPtr(),
1030 static_cast<bt_event_class_log_level>(logLevel));
1033 nonstd::optional<LogLevel> logLevel() const noexcept
1035 bt_event_class_log_level libLogLevel;
1036 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1038 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1039 return static_cast<LogLevel>(libLogLevel);
1042 return nonstd::nullopt;
1045 void emfUri(const char * const emfUri) const
1047 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1049 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1051 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1052 throw MemoryError {};
1056 void emfUri(const std::string& emfUri) const
1058 this->emfUri(emfUri.data());
1061 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1063 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1069 return nonstd::nullopt;
1072 void payloadFieldClass(const StructureFieldClass fc) const
1074 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1077 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1079 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1080 throw MemoryError {};
1084 nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
1086 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1089 return _StructureFieldClass {libObjPtr};
1092 return nonstd::nullopt;
1095 void specificContextFieldClass(const StructureFieldClass fc) const
1097 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1100 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1102 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1103 throw MemoryError {};
1107 nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
1109 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1112 return _StructureFieldClass {libObjPtr};
1115 return nonstd::nullopt;
1118 template <typename LibValT>
1119 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1121 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
1123 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1126 UserAttributes userAttributes() const noexcept
1128 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1131 Shared shared() const noexcept
1133 return Shared::createWithRef(*this);
1137 using EventClass = CommonEventClass<bt_event_class>;
1138 using ConstEventClass = CommonEventClass<const bt_event_class>;
1140 namespace internal {
1142 struct EventClassTypeDescr
1144 using Const = ConstEventClass;
1145 using NonConst = EventClass;
1149 struct TypeDescr<EventClass> : public EventClassTypeDescr
1154 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1158 } /* namespace internal */
1160 template <typename LibObjT>
1161 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1163 return Class {_Spec::cls(this->libObjPtr())};
1166 namespace internal {
1168 struct StreamClassRefFuncs final
1170 static void get(const bt_stream_class * const libObjPtr) noexcept
1172 bt_stream_class_get_ref(libObjPtr);
1175 static void put(const bt_stream_class * const libObjPtr) noexcept
1177 bt_stream_class_put_ref(libObjPtr);
1181 template <typename LibObjT>
1182 struct CommonStreamClassSpec;
1184 /* Functions specific to mutable stream classes */
1186 struct CommonStreamClassSpec<bt_stream_class> final
1188 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1190 return bt_stream_class_borrow_trace_class(libObjPtr);
1193 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1194 const std::uint64_t index) noexcept
1196 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1199 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1200 const std::uint64_t id) noexcept
1202 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1205 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1207 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1210 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1212 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1215 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1217 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1220 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1222 return bt_stream_class_borrow_user_attributes(libObjPtr);
1226 /* Functions specific to constant stream classes */
1228 struct CommonStreamClassSpec<const bt_stream_class> final
1230 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1232 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1235 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1236 const std::uint64_t index) noexcept
1238 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1241 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1242 const std::uint64_t id) noexcept
1244 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1247 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1249 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1252 static const bt_field_class *
1253 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1255 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1258 static const bt_field_class *
1259 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1261 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1264 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1266 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1270 } /* namespace internal */
1272 template <typename LibObjT>
1273 class CommonStreamClass final : public BorrowedObject<LibObjT>
1276 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1277 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1278 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1279 using _StructureFieldClass = internal::DepStructFc<LibObjT>;
1281 using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
1282 CommonTraceClass<const bt_trace_class>>;
1284 using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
1285 CommonEventClass<const bt_event_class>>;
1287 using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
1290 using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1291 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1293 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
1294 _ThisBorrowedObject {libObjPtr}
1298 template <typename OtherLibObjT>
1299 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1300 _ThisBorrowedObject {streamClass}
1304 template <typename OtherLibObjT>
1305 CommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1307 _ThisBorrowedObject::operator=(streamClass);
1311 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1313 return CommonStreamClass<const bt_stream_class> {*this};
1316 Stream::Shared instantiate(const Trace trace) const
1318 static_assert(!std::is_const<LibObjT>::value,
1319 "Not available with `bt2::ConstStreamClass`.");
1321 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1323 internal::validateCreatedObjPtr(libObjPtr);
1324 return Stream::Shared::createWithoutRef(libObjPtr);
1327 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1329 static_assert(!std::is_const<LibObjT>::value,
1330 "Not available with `bt2::ConstStreamClass`.");
1332 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1334 internal::validateCreatedObjPtr(libObjPtr);
1335 return Stream::Shared::createWithoutRef(libObjPtr);
1338 EventClass::Shared createEventClass() const
1340 static_assert(!std::is_const<LibObjT>::value,
1341 "Not available with `bt2::ConstStreamClass`.");
1343 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1345 internal::validateCreatedObjPtr(libObjPtr);
1346 return EventClass::Shared::createWithoutRef(libObjPtr);
1349 EventClass::Shared createEventClass(const std::uint64_t id) const
1351 static_assert(!std::is_const<LibObjT>::value,
1352 "Not available with `bt2::ConstStreamClass`.");
1354 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1356 internal::validateCreatedObjPtr(libObjPtr);
1357 return EventClass::Shared::createWithoutRef(libObjPtr);
1360 _TraceClass traceClass() const noexcept;
1362 std::uint64_t id() const noexcept
1364 return bt_stream_class_get_id(this->libObjPtr());
1367 void name(const char * const name) const
1369 static_assert(!std::is_const<LibObjT>::value,
1370 "Not available with `bt2::ConstStreamClass`.");
1372 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1374 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1375 throw MemoryError {};
1379 void name(const std::string& name) const
1381 this->name(name.data());
1384 nonstd::optional<bpstd::string_view> name() const noexcept
1386 const auto name = bt_stream_class_get_name(this->libObjPtr());
1392 return nonstd::nullopt;
1395 void assignsAutomaticEventClassId(const bool val) const noexcept
1397 static_assert(!std::is_const<LibObjT>::value,
1398 "Not available with `bt2::ConstStreamClass`.");
1400 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1401 static_cast<bt_bool>(val));
1404 bool assignsAutomaticEventClassId() const noexcept
1406 return static_cast<bool>(
1407 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1410 void assignsAutomaticStreamId(const bool val) const noexcept
1412 static_assert(!std::is_const<LibObjT>::value,
1413 "Not available with `bt2::ConstStreamClass`.");
1415 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1416 static_cast<bt_bool>(val));
1419 bool assignsAutomaticStreamId() const noexcept
1421 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1424 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1425 const bool withEndDefaultClkSnapshot) const noexcept
1427 static_assert(!std::is_const<LibObjT>::value,
1428 "Not available with `bt2::ConstStreamClass`.");
1430 bt_stream_class_set_supports_packets(this->libObjPtr(),
1431 static_cast<bt_bool>(supportsPackets),
1432 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1433 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1436 bool supportsPackets() const noexcept
1438 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1441 bool packetsHaveBeginningClockSnapshot() const noexcept
1443 return static_cast<bool>(
1444 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1447 bool packetsHaveEndClockSnapshot() const noexcept
1449 return static_cast<bool>(
1450 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1453 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1454 const bool withDefaultClkSnapshots) const noexcept
1456 static_assert(!std::is_const<LibObjT>::value,
1457 "Not available with `bt2::ConstStreamClass`.");
1459 bt_stream_class_set_supports_discarded_events(
1460 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1461 static_cast<bt_bool>(withDefaultClkSnapshots));
1464 bool supportsDiscardedEvents() const noexcept
1466 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1469 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1471 return static_cast<bool>(
1472 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1475 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1476 const bool withDefaultClkSnapshots) const noexcept
1478 static_assert(!std::is_const<LibObjT>::value,
1479 "Not available with `bt2::ConstStreamClass`.");
1481 bt_stream_class_set_supports_discarded_packets(
1482 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1483 static_cast<bt_bool>(withDefaultClkSnapshots));
1486 bool supportsDiscardedPackets() const noexcept
1488 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1491 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1493 return static_cast<bool>(
1494 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1497 void defaultClockClass(const ClockClass clkCls) const
1499 static_assert(!std::is_const<LibObjT>::value,
1500 "Not available with `bt2::ConstStreamClass`.");
1503 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1505 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1508 nonstd::optional<_ClockClass> defaultClockClass() const noexcept
1510 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1513 return _ClockClass {libObjPtr};
1516 return nonstd::nullopt;
1519 std::uint64_t length() const noexcept
1521 return bt_stream_class_get_event_class_count(this->libObjPtr());
1524 _EventClass operator[](const std::uint64_t index) const noexcept
1526 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1529 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1531 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1534 return _EventClass {libObjPtr};
1537 return nonstd::nullopt;
1540 void packetContextFieldClass(const StructureFieldClass fc) const
1542 static_assert(!std::is_const<LibObjT>::value,
1543 "Not available with `bt2::ConstStreamClass`.");
1546 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1548 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1549 throw MemoryError {};
1553 nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
1555 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1558 return _StructureFieldClass {libObjPtr};
1561 return nonstd::nullopt;
1564 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1566 static_assert(!std::is_const<LibObjT>::value,
1567 "Not available with `bt2::ConstStreamClass`.");
1570 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1572 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1573 throw MemoryError {};
1577 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1579 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1582 return _StructureFieldClass {libObjPtr};
1585 return nonstd::nullopt;
1588 template <typename LibValT>
1589 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1591 static_assert(!std::is_const<LibObjT>::value,
1592 "Not available with `bt2::ConstStreamClass`.");
1594 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1597 UserAttributes userAttributes() const noexcept
1599 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1602 Shared shared() const noexcept
1604 return Shared::createWithRef(*this);
1608 using StreamClass = CommonStreamClass<bt_stream_class>;
1609 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1611 namespace internal {
1613 struct StreamClassTypeDescr
1615 using Const = ConstStreamClass;
1616 using NonConst = StreamClass;
1620 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1625 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1629 } /* namespace internal */
1631 template <typename LibObjT>
1632 typename CommonEventClass<LibObjT>::_StreamClass
1633 CommonEventClass<LibObjT>::streamClass() const noexcept
1635 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1638 template <typename LibObjT>
1639 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1641 return Class {_Spec::cls(this->libObjPtr())};
1644 namespace internal {
1646 struct TraceClassRefFuncs final
1648 static void get(const bt_trace_class * const libObjPtr) noexcept
1650 bt_trace_class_get_ref(libObjPtr);
1653 static void put(const bt_trace_class * const libObjPtr) noexcept
1655 bt_trace_class_put_ref(libObjPtr);
1659 template <typename LibObjT>
1660 struct CommonTraceClassSpec;
1662 /* Functions specific to mutable stream classes */
1664 struct CommonTraceClassSpec<bt_trace_class> final
1666 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1667 const std::uint64_t index) noexcept
1669 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1672 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1673 const std::uint64_t id) noexcept
1675 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1678 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1680 return bt_trace_class_borrow_user_attributes(libObjPtr);
1684 /* Functions specific to constant stream classes */
1686 struct CommonTraceClassSpec<const bt_trace_class> final
1688 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1689 const std::uint64_t index) noexcept
1691 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1694 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1695 const std::uint64_t id) noexcept
1697 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1700 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1702 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1706 } /* namespace internal */
1708 template <typename LibObjT>
1709 class CommonTraceClass final : public BorrowedObject<LibObjT>
1712 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1713 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1714 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1716 using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
1717 CommonStreamClass<const bt_stream_class>>;
1720 using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1721 using UserAttributes = internal::DepUserAttrs<LibObjT>;
1723 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1727 template <typename OtherLibObjT>
1728 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1729 _ThisBorrowedObject {traceClass}
1733 template <typename OtherLibObjT>
1734 CommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1736 _ThisBorrowedObject::operator=(traceClass);
1740 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1742 return CommonTraceClass<const bt_trace_class> {*this};
1745 Trace::Shared instantiate() const
1747 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1749 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1751 internal::validateCreatedObjPtr(libObjPtr);
1752 return Trace::Shared::createWithoutRef(libObjPtr);
1755 StreamClass::Shared createStreamClass() const
1757 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1759 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1761 internal::validateCreatedObjPtr(libObjPtr);
1762 return StreamClass::Shared::createWithoutRef(libObjPtr);
1765 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1767 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1769 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1771 internal::validateCreatedObjPtr(libObjPtr);
1772 return StreamClass::Shared::createWithoutRef(libObjPtr);
1775 FieldClass::Shared createBoolFieldClass() const
1777 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1779 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1781 internal::validateCreatedObjPtr(libObjPtr);
1782 return FieldClass::Shared::createWithoutRef(libObjPtr);
1785 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1787 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1789 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1791 internal::validateCreatedObjPtr(libObjPtr);
1792 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1795 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1797 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1799 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1801 internal::validateCreatedObjPtr(libObjPtr);
1802 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1805 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1807 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1809 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1811 internal::validateCreatedObjPtr(libObjPtr);
1812 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1815 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1817 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1819 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1821 internal::validateCreatedObjPtr(libObjPtr);
1822 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1825 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1827 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1829 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1831 internal::validateCreatedObjPtr(libObjPtr);
1832 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1835 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1837 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1839 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1841 internal::validateCreatedObjPtr(libObjPtr);
1842 return FieldClass::Shared::createWithoutRef(libObjPtr);
1845 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1847 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1849 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1851 internal::validateCreatedObjPtr(libObjPtr);
1852 return FieldClass::Shared::createWithoutRef(libObjPtr);
1855 FieldClass::Shared createStringFieldClass() const
1857 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1859 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1861 internal::validateCreatedObjPtr(libObjPtr);
1862 return FieldClass::Shared::createWithoutRef(libObjPtr);
1865 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1866 const std::uint64_t length) const
1868 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1870 const auto libObjPtr = bt_field_class_array_static_create(
1871 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1873 internal::validateCreatedObjPtr(libObjPtr);
1874 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1877 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1879 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1881 const auto libObjPtr = bt_field_class_array_dynamic_create(
1882 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1884 internal::validateCreatedObjPtr(libObjPtr);
1885 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1888 DynamicArrayWithLengthFieldClass::Shared
1889 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1890 const IntegerFieldClass lengthFieldClass) const
1892 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1894 const auto libObjPtr = bt_field_class_array_dynamic_create(
1895 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1897 internal::validateCreatedObjPtr(libObjPtr);
1898 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1901 StructureFieldClass::Shared createStructureFieldClass() const
1903 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1905 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1907 internal::validateCreatedObjPtr(libObjPtr);
1908 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1911 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1913 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1915 const auto libObjPtr = bt_field_class_option_without_selector_create(
1916 this->libObjPtr(), optionalFieldClass.libObjPtr());
1918 internal::validateCreatedObjPtr(libObjPtr);
1919 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1922 OptionWithBoolSelectorFieldClass::Shared
1923 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1924 const FieldClass selectorFieldClass) const
1926 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1928 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1929 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1931 internal::validateCreatedObjPtr(libObjPtr);
1932 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1935 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1936 createOptionWithUnsignedIntegerSelectorFieldClass(
1937 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1938 const ConstUnsignedIntegerRangeSet ranges) const
1940 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1942 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1943 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1944 ranges.libObjPtr());
1946 internal::validateCreatedObjPtr(libObjPtr);
1947 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1950 OptionWithSignedIntegerSelectorFieldClass::Shared
1951 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1952 const IntegerFieldClass selectorFieldClass,
1953 const ConstSignedIntegerRangeSet ranges) const
1955 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1957 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1958 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1959 ranges.libObjPtr());
1961 internal::validateCreatedObjPtr(libObjPtr);
1962 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1965 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1967 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1969 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1971 internal::validateCreatedObjPtr(libObjPtr);
1972 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1975 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1976 createVariantWithUnsignedIntegerSelectorFieldClass(
1977 const IntegerFieldClass selectorFieldClass) const
1979 return this->_createVariantWithIntegerSelectorFieldClass<
1980 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1983 VariantWithSignedIntegerSelectorFieldClass::Shared
1984 createVariantWithSignedIntegerSelectorFieldClass(
1985 const IntegerFieldClass selectorFieldClass) const
1987 return this->_createVariantWithIntegerSelectorFieldClass<
1988 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
1991 void assignsAutomaticStreamClassId(const bool val) const noexcept
1993 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
1995 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
1996 static_cast<bt_bool>(val));
1999 bool assignsAutomaticStreamClassId() const noexcept
2001 return static_cast<bool>(
2002 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2005 std::uint64_t length() const noexcept
2007 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2010 _StreamClass operator[](const std::uint64_t index) const noexcept
2012 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2015 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
2017 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2020 return _StreamClass {libObjPtr};
2023 return nonstd::nullopt;
2026 template <typename LibValT>
2027 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
2029 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2031 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2034 UserAttributes userAttributes() const noexcept
2036 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2039 Shared shared() const noexcept
2041 return Shared::createWithRef(*this);
2045 template <typename ObjT>
2046 typename ObjT::Shared
2047 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
2049 static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
2051 const auto libObjPtr =
2052 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2054 internal::validateCreatedObjPtr(libObjPtr);
2055 return ObjT::Shared::createWithoutRef(libObjPtr);
2059 using TraceClass = CommonTraceClass<bt_trace_class>;
2060 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2062 namespace internal {
2064 struct TraceClassTypeDescr
2066 using Const = ConstTraceClass;
2067 using NonConst = TraceClass;
2071 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2076 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2080 } /* namespace internal */
2082 template <typename LibObjT>
2083 typename CommonStreamClass<LibObjT>::_TraceClass
2084 CommonStreamClass<LibObjT>::traceClass() const noexcept
2086 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2089 template <typename LibObjT>
2090 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
2092 return Class {_Spec::cls(this->libObjPtr())};
2095 } /* namespace bt2 */
2097 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */