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 } /* namespace internal */
126 template <typename LibObjT>
127 class CommonEvent final : public BorrowedObject<LibObjT>
130 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
131 using typename BorrowedObject<LibObjT>::_LibObjPtr;
132 using _Spec = internal::CommonEventSpec<LibObjT>;
135 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
136 CommonPacket<bt_packet>>::type;
139 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
140 CommonStream<bt_stream>>::type;
142 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
143 ConstStructureField, StructureField>::type;
146 using Class = typename std::conditional<std::is_const<LibObjT>::value,
147 CommonEventClass<const bt_event_class>,
148 CommonEventClass<bt_event_class>>::type;
150 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
154 template <typename OtherLibObjT>
155 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
159 template <typename OtherLibObjT>
160 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
162 _ThisBorrowedObject::operator=(event);
166 CommonEvent<const bt_event> asConst() const noexcept
168 return CommonEvent<const bt_event> {*this};
171 Class cls() const noexcept;
172 _Stream stream() const noexcept;
173 nonstd::optional<_Packet> packet() const noexcept;
175 nonstd::optional<_StructureField> payloadField() const noexcept
177 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
180 return _StructureField {libObjPtr};
183 return nonstd::nullopt;
186 nonstd::optional<_StructureField> specificContextField() const noexcept
188 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
191 return _StructureField {libObjPtr};
194 return nonstd::nullopt;
197 nonstd::optional<_StructureField> commonContextField() const noexcept
199 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
202 return _StructureField {libObjPtr};
205 return nonstd::nullopt;
209 using Event = CommonEvent<bt_event>;
210 using ConstEvent = CommonEvent<const bt_event>;
214 struct EventTypeDescr
216 using Const = ConstEvent;
217 using NonConst = Event;
221 struct TypeDescr<Event> : public EventTypeDescr
226 struct TypeDescr<ConstEvent> : public EventTypeDescr
230 struct PacketRefFuncs final
232 static void get(const bt_packet * const libObjPtr) noexcept
234 bt_packet_get_ref(libObjPtr);
237 static void put(const bt_packet * const libObjPtr) noexcept
239 bt_packet_put_ref(libObjPtr);
243 template <typename LibObjT>
244 struct CommonPacketSpec;
246 /* Functions specific to mutable packets */
248 struct CommonPacketSpec<bt_packet> final
250 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
252 return bt_packet_borrow_stream(libObjPtr);
255 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
257 return bt_packet_borrow_context_field(libObjPtr);
261 /* Functions specific to constant packets */
263 struct CommonPacketSpec<const bt_packet> final
265 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
267 return bt_packet_borrow_stream_const(libObjPtr);
270 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
272 return bt_packet_borrow_context_field_const(libObjPtr);
276 } /* namespace internal */
278 template <typename LibObjT>
279 class CommonPacket final : public BorrowedObject<LibObjT>
282 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
283 using typename BorrowedObject<LibObjT>::_LibObjPtr;
284 using _Spec = internal::CommonPacketSpec<LibObjT>;
285 using _ThisCommonPacket = CommonPacket<LibObjT>;
288 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
289 CommonStream<bt_stream>>::type;
291 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
292 ConstStructureField, StructureField>::type;
295 using Shared = SharedObject<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
297 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
301 template <typename OtherLibObjT>
302 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
306 template <typename OtherLibObjT>
307 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
309 _ThisBorrowedObject::operator=(packet);
313 CommonPacket<const bt_packet> asConst() const noexcept
315 return CommonPacket<const bt_packet> {*this};
318 _Stream stream() const noexcept;
320 nonstd::optional<_StructureField> contextField() const noexcept
322 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
325 return _StructureField {libObjPtr};
328 return nonstd::nullopt;
331 Shared shared() const noexcept
333 return Shared::createWithRef(*this);
337 using Packet = CommonPacket<bt_packet>;
338 using ConstPacket = CommonPacket<const bt_packet>;
342 struct PacketTypeDescr
344 using Const = ConstPacket;
345 using NonConst = Packet;
349 struct TypeDescr<Packet> : public PacketTypeDescr
354 struct TypeDescr<ConstPacket> : public PacketTypeDescr
358 } /* namespace internal */
360 template <typename LibObjT>
361 nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
362 CommonEvent<LibObjT>::packet() const noexcept
364 const auto libObjPtr = _Spec::packet(this->libObjPtr());
367 return _Packet {libObjPtr};
370 return nonstd::nullopt;
375 struct StreamRefFuncs final
377 static void get(const bt_stream * const libObjPtr) noexcept
379 bt_stream_get_ref(libObjPtr);
382 static void put(const bt_stream * const libObjPtr) noexcept
384 bt_stream_put_ref(libObjPtr);
388 template <typename LibObjT>
389 struct CommonStreamSpec;
391 /* Functions specific to mutable streams */
393 struct CommonStreamSpec<bt_stream> final
395 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
397 return bt_stream_borrow_class(libObjPtr);
400 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
402 return bt_stream_borrow_trace(libObjPtr);
405 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
407 return bt_stream_borrow_user_attributes(libObjPtr);
411 /* Functions specific to constant streams */
413 struct CommonStreamSpec<const bt_stream> final
415 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
417 return bt_stream_borrow_class_const(libObjPtr);
420 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
422 return bt_stream_borrow_trace_const(libObjPtr);
425 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
427 return bt_stream_borrow_user_attributes_const(libObjPtr);
431 } /* namespace internal */
433 template <typename LibObjT>
434 class CommonStream final : public BorrowedObject<LibObjT>
437 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
438 using typename BorrowedObject<LibObjT>::_LibObjPtr;
439 using _Spec = internal::CommonStreamSpec<LibObjT>;
440 using _ThisCommonStream = CommonStream<LibObjT>;
443 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
444 CommonTrace<bt_trace>>::type;
447 using Shared = SharedObject<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
449 using Class = typename std::conditional<std::is_const<LibObjT>::value,
450 CommonStreamClass<const bt_stream_class>,
451 CommonStreamClass<bt_stream_class>>::type;
453 using UserAttributes =
454 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
456 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
460 template <typename OtherLibObjT>
461 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
465 template <typename OtherLibObjT>
466 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
468 _ThisBorrowedObject::operator=(stream);
472 CommonStream<const bt_stream> asConst() const noexcept
474 return CommonStream<const bt_stream> {*this};
477 Packet::Shared createPacket() const
479 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
481 const auto libObjPtr = bt_packet_create(this->libObjPtr());
483 internal::validateCreatedObjPtr(libObjPtr);
484 return Packet::Shared::createWithoutRef(libObjPtr);
487 Class cls() const noexcept;
488 _Trace trace() const noexcept;
490 std::uint64_t id() const noexcept
492 return bt_stream_get_id(this->libObjPtr());
495 void name(const char * const name) const
497 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
499 const auto status = bt_stream_set_name(this->libObjPtr(), name);
501 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
502 throw MemoryError {};
506 void name(const std::string& name) const
508 this->name(name.data());
511 nonstd::optional<bpstd::string_view> name() const noexcept
513 const auto name = bt_stream_get_name(this->libObjPtr());
519 return nonstd::nullopt;
522 template <typename LibValT>
523 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
525 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
527 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
530 UserAttributes userAttributes() const noexcept
532 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
535 Shared shared() const noexcept
537 return Shared::createWithRef(*this);
541 using Stream = CommonStream<bt_stream>;
542 using ConstStream = CommonStream<const bt_stream>;
546 struct StreamTypeDescr
548 using Const = ConstStream;
549 using NonConst = Stream;
553 struct TypeDescr<Stream> : public StreamTypeDescr
558 struct TypeDescr<ConstStream> : public StreamTypeDescr
562 } /* namespace internal */
564 template <typename LibObjT>
565 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
567 return _Stream {_Spec::stream(this->libObjPtr())};
570 template <typename LibObjT>
571 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
573 return _Stream {_Spec::stream(this->libObjPtr())};
578 struct TraceRefFuncs final
580 static void get(const bt_trace * const libObjPtr) noexcept
582 bt_trace_get_ref(libObjPtr);
585 static void put(const bt_trace * const libObjPtr) noexcept
587 bt_trace_put_ref(libObjPtr);
591 template <typename LibObjT>
592 struct CommonTraceSpec;
594 /* Functions specific to mutable traces */
596 struct CommonTraceSpec<bt_trace> final
598 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
600 return bt_trace_borrow_class(libObjPtr);
603 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
605 return bt_trace_borrow_stream_by_index(libObjPtr, index);
608 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
610 return bt_trace_borrow_stream_by_id(libObjPtr, id);
613 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
615 return bt_trace_borrow_user_attributes(libObjPtr);
619 /* Functions specific to constant traces */
621 struct CommonTraceSpec<const bt_trace> final
623 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
625 return bt_trace_borrow_class_const(libObjPtr);
628 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
629 const std::uint64_t index) noexcept
631 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
634 static const bt_stream *streamById(const bt_trace * const libObjPtr,
635 const std::uint64_t id) noexcept
637 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
640 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
642 return bt_trace_borrow_user_attributes_const(libObjPtr);
646 } /* namespace internal */
648 template <typename LibObjT>
649 class CommonTrace final : public BorrowedObject<LibObjT>
652 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
653 using typename BorrowedObject<LibObjT>::_LibObjPtr;
654 using _Spec = internal::CommonTraceSpec<LibObjT>;
655 using _ThisCommonTrace = CommonTrace<LibObjT>;
658 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
659 CommonStream<bt_stream>>::type;
662 using Shared = SharedObject<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
664 using Class = typename std::conditional<std::is_const<LibObjT>::value,
665 CommonTraceClass<const bt_trace_class>,
666 CommonTraceClass<bt_trace_class>>::type;
668 using UserAttributes =
669 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
671 struct ConstEnvironmentEntry
673 bpstd::string_view name;
677 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
681 template <typename OtherLibObjT>
682 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
686 template <typename OtherLibObjT>
687 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
689 _ThisBorrowedObject::operator=(trace);
693 CommonTrace<const bt_trace> asConst() const noexcept
695 return CommonTrace<const bt_trace> {*this};
698 Class cls() const noexcept;
700 void name(const char * const name) const
702 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
704 const auto status = bt_trace_set_name(this->libObjPtr(), name);
706 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
707 throw MemoryError {};
711 void name(const std::string& name) const
713 this->name(name.data());
716 nonstd::optional<bpstd::string_view> name() const noexcept
718 const auto name = bt_trace_get_name(this->libObjPtr());
724 return nonstd::nullopt;
727 void uuid(const bt2_common::UuidView& uuid) const noexcept
729 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
732 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
734 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
737 return bt2_common::UuidView {uuid};
740 return nonstd::nullopt;
743 std::uint64_t length() const noexcept
745 return bt_trace_get_stream_count(this->libObjPtr());
748 _Stream operator[](const std::uint64_t index) const noexcept
750 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
753 nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
755 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
758 return _Stream {libObjPtr};
761 return nonstd::nullopt;
764 void environmentEntry(const char * const name, const std::int64_t val) const
766 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
768 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
770 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
771 throw MemoryError {};
775 void environmentEntry(const std::string& name, const std::int64_t val) const
777 this->environmentEntry(name.data(), val);
780 void environmentEntry(const char * const name, const char * const val) const
782 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
784 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
786 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
787 throw MemoryError {};
791 void environmentEntry(const std::string& name, const char * const val) const
793 this->environmentEntry(name.data(), val);
796 void environmentEntry(const char * const name, const std::string& val) const
798 this->environmentEntry(name, val.data());
801 void environmentEntry(const std::string& name, const std::string& val) const
803 this->environmentEntry(name.data(), val.data());
806 std::uint64_t environmentSize() const noexcept
808 return bt_trace_get_environment_entry_count(this->libObjPtr());
811 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
814 const bt_value *libObjPtr;
816 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
818 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
821 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
823 const auto libObjPtr =
824 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
827 return ConstValue {libObjPtr};
830 return nonstd::nullopt;
833 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
835 return this->environmentEntry(name.data());
838 template <typename LibValT>
839 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
841 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
843 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
846 UserAttributes userAttributes() const noexcept
848 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
851 Shared shared() const noexcept
853 return Shared::createWithRef(*this);
857 using Trace = CommonTrace<bt_trace>;
858 using ConstTrace = CommonTrace<const bt_trace>;
862 struct TraceTypeDescr
864 using Const = ConstTrace;
865 using NonConst = Trace;
869 struct TypeDescr<Trace> : public TraceTypeDescr
874 struct TypeDescr<ConstTrace> : public TraceTypeDescr
878 } /* namespace internal */
880 template <typename LibObjT>
881 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
883 return _Trace {_Spec::trace(this->libObjPtr())};
888 struct EventClassRefFuncs final
890 static void get(const bt_event_class * const libObjPtr) noexcept
892 bt_event_class_get_ref(libObjPtr);
895 static void put(const bt_event_class * const libObjPtr) noexcept
897 bt_event_class_put_ref(libObjPtr);
901 template <typename LibObjT>
902 struct CommonEventClassSpec;
904 /* Functions specific to mutable event classes */
906 struct CommonEventClassSpec<bt_event_class> final
908 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
910 return bt_event_class_borrow_stream_class(libObjPtr);
913 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
915 return bt_event_class_borrow_payload_field_class(libObjPtr);
918 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
920 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
923 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
925 return bt_event_class_borrow_user_attributes(libObjPtr);
929 /* Functions specific to constant event classes */
931 struct CommonEventClassSpec<const bt_event_class> final
933 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
935 return bt_event_class_borrow_stream_class_const(libObjPtr);
938 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
940 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
943 static const bt_field_class *
944 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
946 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
949 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
951 return bt_event_class_borrow_user_attributes_const(libObjPtr);
955 } /* namespace internal */
957 template <typename LibObjT>
958 class CommonEventClass final : public BorrowedObject<LibObjT>
961 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
962 using typename BorrowedObject<LibObjT>::_LibObjPtr;
963 using _Spec = internal::CommonEventClassSpec<LibObjT>;
964 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
966 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
967 CommonStreamClass<const bt_stream_class>,
968 CommonStreamClass<bt_stream_class>>::type;
970 using _StructureFieldClass =
971 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
972 StructureFieldClass>::type;
975 using Shared = SharedObject<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
977 using UserAttributes =
978 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
982 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
983 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
984 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
985 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
986 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
987 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
988 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
989 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
990 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
991 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
992 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
993 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
994 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
995 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
996 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
999 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1003 template <typename OtherLibObjT>
1004 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
1005 _ThisBorrowedObject {eventClass}
1009 template <typename OtherLibObjT>
1010 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
1012 _ThisBorrowedObject::operator=(eventClass);
1016 CommonEventClass<const bt_event_class> asConst() const noexcept
1018 return CommonEventClass<const bt_event_class> {*this};
1021 _StreamClass streamClass() const noexcept;
1023 std::uint64_t id() const noexcept
1025 return bt_event_class_get_id(this->libObjPtr());
1028 void name(const char * const name) const
1030 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1032 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1034 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1035 throw MemoryError {};
1039 void name(const std::string& name) const
1041 this->name(name.data());
1044 nonstd::optional<bpstd::string_view> name() const noexcept
1046 const auto name = bt_event_class_get_name(this->libObjPtr());
1052 return nonstd::nullopt;
1055 void logLevel(const LogLevel logLevel) const noexcept
1057 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1059 bt_event_class_set_log_level(this->libObjPtr(),
1060 static_cast<bt_event_class_log_level>(logLevel));
1063 nonstd::optional<LogLevel> logLevel() const noexcept
1065 bt_event_class_log_level libLogLevel;
1066 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1068 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1069 return static_cast<LogLevel>(libLogLevel);
1072 return nonstd::nullopt;
1075 void emfUri(const char * const emfUri) const
1077 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1079 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1081 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1082 throw MemoryError {};
1086 void emfUri(const std::string& emfUri) const
1088 this->emfUri(emfUri.data());
1091 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1093 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1099 return nonstd::nullopt;
1102 void payloadFieldClass(const StructureFieldClass fc) const
1104 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1107 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1109 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1110 throw MemoryError {};
1114 nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
1116 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1119 return _StructureFieldClass {libObjPtr};
1122 return nonstd::nullopt;
1125 void specificContextFieldClass(const StructureFieldClass fc) const
1127 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1130 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1132 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1133 throw MemoryError {};
1137 nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
1139 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1142 return _StructureFieldClass {libObjPtr};
1145 return nonstd::nullopt;
1148 template <typename LibValT>
1149 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1151 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1153 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1156 UserAttributes userAttributes() const noexcept
1158 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1161 Shared shared() const noexcept
1163 return Shared::createWithRef(*this);
1167 using EventClass = CommonEventClass<bt_event_class>;
1168 using ConstEventClass = CommonEventClass<const bt_event_class>;
1170 namespace internal {
1172 struct EventClassTypeDescr
1174 using Const = ConstEventClass;
1175 using NonConst = EventClass;
1179 struct TypeDescr<EventClass> : public EventClassTypeDescr
1184 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1188 } /* namespace internal */
1190 template <typename LibObjT>
1191 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1193 return Class {_Spec::cls(this->libObjPtr())};
1196 namespace internal {
1198 struct StreamClassRefFuncs final
1200 static void get(const bt_stream_class * const libObjPtr) noexcept
1202 bt_stream_class_get_ref(libObjPtr);
1205 static void put(const bt_stream_class * const libObjPtr) noexcept
1207 bt_stream_class_put_ref(libObjPtr);
1211 template <typename LibObjT>
1212 struct CommonStreamClassSpec;
1214 /* Functions specific to mutable stream classes */
1216 struct CommonStreamClassSpec<bt_stream_class> final
1218 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1220 return bt_stream_class_borrow_trace_class(libObjPtr);
1223 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1224 const std::uint64_t index) noexcept
1226 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1229 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1230 const std::uint64_t id) noexcept
1232 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1235 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1237 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1240 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1242 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1245 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1247 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1250 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1252 return bt_stream_class_borrow_user_attributes(libObjPtr);
1256 /* Functions specific to constant stream classes */
1258 struct CommonStreamClassSpec<const bt_stream_class> final
1260 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1262 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1265 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1266 const std::uint64_t index) noexcept
1268 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1271 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1272 const std::uint64_t id) noexcept
1274 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1277 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1279 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1282 static const bt_field_class *
1283 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1285 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1288 static const bt_field_class *
1289 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1291 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1294 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1296 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1300 } /* namespace internal */
1302 template <typename LibObjT>
1303 class CommonStreamClass final : public BorrowedObject<LibObjT>
1306 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1307 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1308 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1309 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1311 using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
1312 CommonTraceClass<const bt_trace_class>,
1313 CommonTraceClass<bt_trace_class>>::type;
1315 using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
1316 CommonEventClass<const bt_event_class>,
1317 CommonEventClass<bt_event_class>>::type;
1319 using _StructureFieldClass =
1320 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1321 StructureFieldClass>::type;
1324 typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
1327 using Shared = SharedObject<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1329 using UserAttributes =
1330 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1332 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
1333 _ThisBorrowedObject {libObjPtr}
1337 template <typename OtherLibObjT>
1338 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1339 _ThisBorrowedObject {streamClass}
1343 template <typename OtherLibObjT>
1344 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1346 _ThisBorrowedObject::operator=(streamClass);
1350 CommonStreamClass<const bt_stream_class> asConst() const noexcept
1352 return CommonStreamClass<const bt_stream_class> {*this};
1355 Stream::Shared instantiate(const Trace trace) const
1357 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1359 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1361 internal::validateCreatedObjPtr(libObjPtr);
1362 return Stream::Shared::createWithoutRef(libObjPtr);
1365 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1367 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1369 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1371 internal::validateCreatedObjPtr(libObjPtr);
1372 return Stream::Shared::createWithoutRef(libObjPtr);
1375 EventClass::Shared createEventClass() const
1377 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1379 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1381 internal::validateCreatedObjPtr(libObjPtr);
1382 return EventClass::Shared::createWithoutRef(libObjPtr);
1385 EventClass::Shared createEventClass(const std::uint64_t id) const
1387 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1389 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1391 internal::validateCreatedObjPtr(libObjPtr);
1392 return EventClass::Shared::createWithoutRef(libObjPtr);
1395 _TraceClass traceClass() const noexcept;
1397 std::uint64_t id() const noexcept
1399 return bt_stream_class_get_id(this->libObjPtr());
1402 void name(const char * const name) const
1404 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1406 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1408 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1409 throw MemoryError {};
1413 void name(const std::string& name) const
1415 this->name(name.data());
1418 nonstd::optional<bpstd::string_view> name() const noexcept
1420 const auto name = bt_stream_class_get_name(this->libObjPtr());
1426 return nonstd::nullopt;
1429 void assignsAutomaticEventClassId(const bool val) const noexcept
1431 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1433 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1434 static_cast<bt_bool>(val));
1437 bool assignsAutomaticEventClassId() const noexcept
1439 return static_cast<bool>(
1440 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1443 void assignsAutomaticStreamId(const bool val) const noexcept
1445 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1447 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1448 static_cast<bt_bool>(val));
1451 bool assignsAutomaticStreamId() const noexcept
1453 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1456 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1457 const bool withEndDefaultClkSnapshot) const noexcept
1459 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1461 bt_stream_class_set_supports_packets(this->libObjPtr(),
1462 static_cast<bt_bool>(supportsPackets),
1463 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1464 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1467 bool supportsPackets() const noexcept
1469 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1472 bool packetsHaveBeginningClockSnapshot() const noexcept
1474 return static_cast<bool>(
1475 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1478 bool packetsHaveEndClockSnapshot() const noexcept
1480 return static_cast<bool>(
1481 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1484 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1485 const bool withDefaultClkSnapshots) const noexcept
1487 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1489 bt_stream_class_set_supports_discarded_events(
1490 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1491 static_cast<bt_bool>(withDefaultClkSnapshots));
1494 bool supportsDiscardedEvents() const noexcept
1496 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1499 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1501 return static_cast<bool>(
1502 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1505 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1506 const bool withDefaultClkSnapshots) const noexcept
1508 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1510 bt_stream_class_set_supports_discarded_packets(
1511 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1512 static_cast<bt_bool>(withDefaultClkSnapshots));
1515 bool supportsDiscardedPackets() const noexcept
1517 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1520 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1522 return static_cast<bool>(
1523 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1526 void defaultClockClass(const ClockClass clkCls) const
1528 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1531 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1533 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1536 nonstd::optional<_ClockClass> defaultClockClass() const noexcept
1538 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1541 return _ClockClass {libObjPtr};
1544 return nonstd::nullopt;
1547 std::uint64_t length() const noexcept
1549 return bt_stream_class_get_event_class_count(this->libObjPtr());
1552 _EventClass operator[](const std::uint64_t index) const noexcept
1554 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1557 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1559 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1562 return _EventClass {libObjPtr};
1565 return nonstd::nullopt;
1568 void packetContextFieldClass(const StructureFieldClass fc) const
1570 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1573 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1575 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1576 throw MemoryError {};
1580 nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
1582 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1585 return _StructureFieldClass {libObjPtr};
1588 return nonstd::nullopt;
1591 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1593 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1596 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1598 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1599 throw MemoryError {};
1603 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1605 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1608 return _StructureFieldClass {libObjPtr};
1611 return nonstd::nullopt;
1614 template <typename LibValT>
1615 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
1617 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1619 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1622 UserAttributes userAttributes() const noexcept
1624 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1627 Shared shared() const noexcept
1629 return Shared::createWithRef(*this);
1633 using StreamClass = CommonStreamClass<bt_stream_class>;
1634 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1636 namespace internal {
1638 struct StreamClassTypeDescr
1640 using Const = ConstStreamClass;
1641 using NonConst = StreamClass;
1645 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1650 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1654 } /* namespace internal */
1656 template <typename LibObjT>
1657 typename CommonEventClass<LibObjT>::_StreamClass
1658 CommonEventClass<LibObjT>::streamClass() const noexcept
1660 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1663 template <typename LibObjT>
1664 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1666 return Class {_Spec::cls(this->libObjPtr())};
1669 namespace internal {
1671 struct TraceClassRefFuncs final
1673 static void get(const bt_trace_class * const libObjPtr) noexcept
1675 bt_trace_class_get_ref(libObjPtr);
1678 static void put(const bt_trace_class * const libObjPtr) noexcept
1680 bt_trace_class_put_ref(libObjPtr);
1684 template <typename LibObjT>
1685 struct CommonTraceClassSpec;
1687 /* Functions specific to mutable stream classes */
1689 struct CommonTraceClassSpec<bt_trace_class> final
1691 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1692 const std::uint64_t index) noexcept
1694 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1697 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1698 const std::uint64_t id) noexcept
1700 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1703 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1705 return bt_trace_class_borrow_user_attributes(libObjPtr);
1709 /* Functions specific to constant stream classes */
1711 struct CommonTraceClassSpec<const bt_trace_class> final
1713 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1714 const std::uint64_t index) noexcept
1716 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1719 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1720 const std::uint64_t id) noexcept
1722 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1725 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1727 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1731 } /* namespace internal */
1733 template <typename LibObjT>
1734 class CommonTraceClass final : public BorrowedObject<LibObjT>
1737 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1738 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1739 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1740 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1742 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1743 CommonStreamClass<const bt_stream_class>,
1744 CommonStreamClass<bt_stream_class>>::type;
1747 using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1749 using UserAttributes =
1750 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1752 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1756 template <typename OtherLibObjT>
1757 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1758 _ThisBorrowedObject {traceClass}
1762 template <typename OtherLibObjT>
1763 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1765 _ThisBorrowedObject::operator=(traceClass);
1769 CommonTraceClass<const bt_trace_class> asConst() const noexcept
1771 return CommonTraceClass<const bt_trace_class> {*this};
1774 Trace::Shared instantiate() const
1776 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1778 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1780 internal::validateCreatedObjPtr(libObjPtr);
1781 return Trace::Shared::createWithoutRef(libObjPtr);
1784 StreamClass::Shared createStreamClass() const
1786 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1788 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1790 internal::validateCreatedObjPtr(libObjPtr);
1791 return StreamClass::Shared::createWithoutRef(libObjPtr);
1794 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1796 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1798 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1800 internal::validateCreatedObjPtr(libObjPtr);
1801 return StreamClass::Shared::createWithoutRef(libObjPtr);
1804 FieldClass::Shared createBoolFieldClass() const
1806 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1808 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1810 internal::validateCreatedObjPtr(libObjPtr);
1811 return FieldClass::Shared::createWithoutRef(libObjPtr);
1814 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1816 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1818 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1820 internal::validateCreatedObjPtr(libObjPtr);
1821 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1824 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1826 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1828 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1830 internal::validateCreatedObjPtr(libObjPtr);
1831 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1834 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1836 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1838 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1840 internal::validateCreatedObjPtr(libObjPtr);
1841 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1844 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1846 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1848 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1850 internal::validateCreatedObjPtr(libObjPtr);
1851 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1854 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1856 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1858 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1860 internal::validateCreatedObjPtr(libObjPtr);
1861 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1864 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1866 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1868 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1870 internal::validateCreatedObjPtr(libObjPtr);
1871 return FieldClass::Shared::createWithoutRef(libObjPtr);
1874 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1876 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1878 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1880 internal::validateCreatedObjPtr(libObjPtr);
1881 return FieldClass::Shared::createWithoutRef(libObjPtr);
1884 FieldClass::Shared createStringFieldClass() const
1886 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1888 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1890 internal::validateCreatedObjPtr(libObjPtr);
1891 return FieldClass::Shared::createWithoutRef(libObjPtr);
1894 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1895 const std::uint64_t length) const
1897 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1899 const auto libObjPtr = bt_field_class_array_static_create(
1900 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1902 internal::validateCreatedObjPtr(libObjPtr);
1903 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1906 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1908 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1910 const auto libObjPtr = bt_field_class_array_dynamic_create(
1911 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1913 internal::validateCreatedObjPtr(libObjPtr);
1914 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1917 DynamicArrayWithLengthFieldClass::Shared
1918 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1919 const IntegerFieldClass lengthFieldClass) const
1921 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1923 const auto libObjPtr = bt_field_class_array_dynamic_create(
1924 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1926 internal::validateCreatedObjPtr(libObjPtr);
1927 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1930 StructureFieldClass::Shared createStructureFieldClass() const
1932 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1934 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1936 internal::validateCreatedObjPtr(libObjPtr);
1937 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1940 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1942 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1944 const auto libObjPtr = bt_field_class_option_without_selector_create(
1945 this->libObjPtr(), optionalFieldClass.libObjPtr());
1947 internal::validateCreatedObjPtr(libObjPtr);
1948 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1951 OptionWithBoolSelectorFieldClass::Shared
1952 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1953 const FieldClass selectorFieldClass) const
1955 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1957 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1958 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1960 internal::validateCreatedObjPtr(libObjPtr);
1961 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1964 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1965 createOptionWithUnsignedIntegerSelectorFieldClass(
1966 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1967 const ConstUnsignedIntegerRangeSet ranges) const
1969 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1971 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1972 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1973 ranges.libObjPtr());
1975 internal::validateCreatedObjPtr(libObjPtr);
1976 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1979 OptionWithSignedIntegerSelectorFieldClass::Shared
1980 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1981 const IntegerFieldClass selectorFieldClass,
1982 const ConstSignedIntegerRangeSet ranges) const
1984 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1986 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1987 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1988 ranges.libObjPtr());
1990 internal::validateCreatedObjPtr(libObjPtr);
1991 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1994 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1996 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1998 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
2000 internal::validateCreatedObjPtr(libObjPtr);
2001 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2004 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2005 createVariantWithUnsignedIntegerSelectorFieldClass(
2006 const IntegerFieldClass selectorFieldClass) const
2008 return this->_createVariantWithIntegerSelectorFieldClass<
2009 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
2012 VariantWithSignedIntegerSelectorFieldClass::Shared
2013 createVariantWithSignedIntegerSelectorFieldClass(
2014 const IntegerFieldClass selectorFieldClass) const
2016 return this->_createVariantWithIntegerSelectorFieldClass<
2017 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
2020 void assignsAutomaticStreamClassId(const bool val) const noexcept
2022 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2024 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
2025 static_cast<bt_bool>(val));
2028 bool assignsAutomaticStreamClassId() const noexcept
2030 return static_cast<bool>(
2031 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2034 std::uint64_t length() const noexcept
2036 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2039 _StreamClass operator[](const std::uint64_t index) const noexcept
2041 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2044 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
2046 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2049 return _StreamClass {libObjPtr};
2052 return nonstd::nullopt;
2055 template <typename LibValT>
2056 void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
2058 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2060 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2063 UserAttributes userAttributes() const noexcept
2065 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2068 Shared shared() const noexcept
2070 return Shared::createWithRef(*this);
2074 template <typename ObjT>
2075 typename ObjT::Shared
2076 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
2078 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2080 const auto libObjPtr =
2081 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2083 internal::validateCreatedObjPtr(libObjPtr);
2084 return ObjT::Shared::createWithoutRef(libObjPtr);
2088 using TraceClass = CommonTraceClass<bt_trace_class>;
2089 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2091 namespace internal {
2093 struct TraceClassTypeDescr
2095 using Const = ConstTraceClass;
2096 using NonConst = TraceClass;
2100 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2105 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2109 } /* namespace internal */
2111 template <typename LibObjT>
2112 typename CommonStreamClass<LibObjT>::_TraceClass
2113 CommonStreamClass<LibObjT>::traceClass() const noexcept
2115 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2118 template <typename LibObjT>
2119 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
2121 return Class {_Spec::cls(this->libObjPtr())};
2124 } /* namespace bt2 */
2126 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */