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 "clock-class.hpp"
19 #include "clock-snapshot.hpp"
20 #include "field-class.hpp"
22 #include "internal/borrowed-obj.hpp"
23 #include "internal/utils.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 internal::BorrowedObj<LibObjT>
130 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
131 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
132 using _ConstSpec = internal::CommonEventSpec<const bt_event>;
133 using _Spec = internal::CommonEventSpec<LibObjT>;
136 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
137 CommonPacket<bt_packet>>::type;
140 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
141 CommonStream<bt_stream>>::type;
143 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
144 ConstStructureField, StructureField>::type;
147 using Class = typename std::conditional<std::is_const<LibObjT>::value,
148 CommonEventClass<const bt_event_class>,
149 CommonEventClass<bt_event_class>>::type;
151 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
155 template <typename OtherLibObjT>
156 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObj {event}
160 template <typename OtherLibObjT>
161 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
163 _ThisBorrowedObj::operator=(event);
167 CommonEventClass<const bt_event_class> cls() const noexcept;
168 Class cls() noexcept;
169 CommonStream<const bt_stream> stream() const noexcept;
170 _Stream stream() noexcept;
171 nonstd::optional<CommonPacket<const bt_packet>> packet() const noexcept;
172 nonstd::optional<_Packet> packet() noexcept;
174 nonstd::optional<ConstStructureField> payloadField() const noexcept
176 const auto libObjPtr = _ConstSpec::payloadField(this->libObjPtr());
179 return ConstStructureField {libObjPtr};
182 return nonstd::nullopt;
185 nonstd::optional<_StructureField> payloadField() noexcept
187 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
190 return _StructureField {libObjPtr};
193 return nonstd::nullopt;
196 nonstd::optional<ConstStructureField> specificContextField() const noexcept
198 const auto libObjPtr = _ConstSpec::specificContextField(this->libObjPtr());
201 return ConstStructureField {libObjPtr};
204 return nonstd::nullopt;
207 nonstd::optional<_StructureField> specificContextField() noexcept
209 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
212 return _StructureField {libObjPtr};
215 return nonstd::nullopt;
218 nonstd::optional<ConstStructureField> commonContextField() const noexcept
220 const auto libObjPtr = _ConstSpec::commonContextField(this->libObjPtr());
223 return ConstStructureField {libObjPtr};
226 return nonstd::nullopt;
229 nonstd::optional<_StructureField> commonContextField() noexcept
231 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
234 return _StructureField {libObjPtr};
237 return nonstd::nullopt;
241 using Event = CommonEvent<bt_event>;
242 using ConstEvent = CommonEvent<const bt_event>;
246 struct EventTypeDescr
248 using Const = ConstEvent;
249 using NonConst = Event;
253 struct TypeDescr<Event> : public EventTypeDescr
258 struct TypeDescr<ConstEvent> : public EventTypeDescr
262 struct PacketRefFuncs final
264 static void get(const bt_packet * const libObjPtr)
266 bt_packet_get_ref(libObjPtr);
269 static void put(const bt_packet * const libObjPtr)
271 bt_packet_put_ref(libObjPtr);
275 template <typename LibObjT>
276 struct CommonPacketSpec;
278 /* Functions specific to mutable packets */
280 struct CommonPacketSpec<bt_packet> final
282 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
284 return bt_packet_borrow_stream(libObjPtr);
287 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
289 return bt_packet_borrow_context_field(libObjPtr);
293 /* Functions specific to constant packets */
295 struct CommonPacketSpec<const bt_packet> final
297 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
299 return bt_packet_borrow_stream_const(libObjPtr);
302 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
304 return bt_packet_borrow_context_field_const(libObjPtr);
308 } /* namespace internal */
310 template <typename LibObjT>
311 class CommonPacket final : public internal::BorrowedObj<LibObjT>
314 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
315 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
316 using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
317 using _Spec = internal::CommonPacketSpec<LibObjT>;
318 using _ThisCommonPacket = CommonPacket<LibObjT>;
321 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
322 CommonStream<bt_stream>>::type;
324 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
325 ConstStructureField, StructureField>::type;
328 using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
330 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
334 template <typename OtherLibObjT>
335 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObj {packet}
339 template <typename OtherLibObjT>
340 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
342 _ThisBorrowedObj::operator=(packet);
346 CommonStream<const bt_stream> stream() const noexcept;
347 _Stream stream() noexcept;
349 nonstd::optional<ConstStructureField> contextField() const noexcept
351 const auto libObjPtr = _ConstSpec::contextField(this->libObjPtr());
354 return ConstStructureField {libObjPtr};
357 return nonstd::nullopt;
360 nonstd::optional<_StructureField> contextField() noexcept
362 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
365 return _StructureField {libObjPtr};
368 return nonstd::nullopt;
371 Shared shared() const noexcept
373 return Shared::createWithRef(*this);
377 using Packet = CommonPacket<bt_packet>;
378 using ConstPacket = CommonPacket<const bt_packet>;
382 struct PacketTypeDescr
384 using Const = ConstPacket;
385 using NonConst = Packet;
389 struct TypeDescr<Packet> : public PacketTypeDescr
394 struct TypeDescr<ConstPacket> : public PacketTypeDescr
398 } /* namespace internal */
400 template <typename LibObjT>
401 nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
403 const auto libObjPtr = _ConstSpec::packet(this->libObjPtr());
406 return ConstPacket {libObjPtr};
409 return nonstd::nullopt;
412 template <typename LibObjT>
413 nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept
415 const auto libObjPtr = _Spec::packet(this->libObjPtr());
418 return _Packet {libObjPtr};
421 return nonstd::nullopt;
426 struct StreamRefFuncs final
428 static void get(const bt_stream * const libObjPtr)
430 bt_stream_get_ref(libObjPtr);
433 static void put(const bt_stream * const libObjPtr)
435 bt_stream_put_ref(libObjPtr);
439 template <typename LibObjT>
440 struct CommonStreamSpec;
442 /* Functions specific to mutable streams */
444 struct CommonStreamSpec<bt_stream> final
446 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
448 return bt_stream_borrow_class(libObjPtr);
451 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
453 return bt_stream_borrow_trace(libObjPtr);
456 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
458 return bt_stream_borrow_user_attributes(libObjPtr);
462 /* Functions specific to constant streams */
464 struct CommonStreamSpec<const bt_stream> final
466 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
468 return bt_stream_borrow_class_const(libObjPtr);
471 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
473 return bt_stream_borrow_trace_const(libObjPtr);
476 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
478 return bt_stream_borrow_user_attributes_const(libObjPtr);
482 } /* namespace internal */
484 template <typename LibObjT>
485 class CommonStream final : public internal::BorrowedObj<LibObjT>
488 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
489 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
490 using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
491 using _Spec = internal::CommonStreamSpec<LibObjT>;
492 using _ThisCommonStream = CommonStream<LibObjT>;
495 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
496 CommonTrace<bt_trace>>::type;
499 using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
501 using Class = typename std::conditional<std::is_const<LibObjT>::value,
502 CommonStreamClass<const bt_stream_class>,
503 CommonStreamClass<bt_stream_class>>::type;
505 using UserAttributes =
506 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
508 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
512 template <typename OtherLibObjT>
513 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObj {stream}
517 template <typename OtherLibObjT>
518 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
520 _ThisBorrowedObj::operator=(stream);
524 Packet::Shared createPacket()
526 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
528 const auto libObjPtr = bt_packet_create(this->libObjPtr());
530 internal::validateCreatedObjPtr(libObjPtr);
531 return Packet::Shared::createWithoutRef(libObjPtr);
534 CommonStreamClass<const bt_stream_class> cls() const noexcept;
535 Class cls() noexcept;
536 CommonTrace<const bt_trace> trace() const noexcept;
537 _Trace trace() noexcept;
539 std::uint64_t id() const noexcept
541 return bt_stream_get_id(this->libObjPtr());
544 void name(const char * const name)
546 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
548 const auto status = bt_stream_set_name(this->libObjPtr(), name);
550 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
551 throw MemoryError {};
555 void name(const std::string& name)
557 this->name(name.data());
560 nonstd::optional<bpstd::string_view> name() const noexcept
562 const auto name = bt_stream_get_name(this->libObjPtr());
568 return nonstd::nullopt;
571 template <typename LibValT>
572 void userAttributes(const CommonMapValue<LibValT> userAttrs)
574 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
576 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
579 ConstMapValue userAttributes() const noexcept
581 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
584 UserAttributes userAttributes() noexcept
586 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
589 Shared shared() const noexcept
591 return Shared::createWithRef(*this);
595 using Stream = CommonStream<bt_stream>;
596 using ConstStream = CommonStream<const bt_stream>;
600 struct StreamTypeDescr
602 using Const = ConstStream;
603 using NonConst = Stream;
607 struct TypeDescr<Stream> : public StreamTypeDescr
612 struct TypeDescr<ConstStream> : public StreamTypeDescr
616 } /* namespace internal */
618 template <typename LibObjT>
619 ConstStream CommonEvent<LibObjT>::stream() const noexcept
621 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
624 template <typename LibObjT>
625 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept
627 return _Stream {_Spec::stream(this->libObjPtr())};
630 template <typename LibObjT>
631 ConstStream CommonPacket<LibObjT>::stream() const noexcept
633 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
636 template <typename LibObjT>
637 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept
639 return _Stream {_Spec::stream(this->libObjPtr())};
644 struct TraceRefFuncs final
646 static void get(const bt_trace * const libObjPtr)
648 bt_trace_get_ref(libObjPtr);
651 static void put(const bt_trace * const libObjPtr)
653 bt_trace_put_ref(libObjPtr);
657 template <typename LibObjT>
658 struct CommonTraceSpec;
660 /* Functions specific to mutable traces */
662 struct CommonTraceSpec<bt_trace> final
664 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
666 return bt_trace_borrow_class(libObjPtr);
669 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
671 return bt_trace_borrow_stream_by_index(libObjPtr, index);
674 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
676 return bt_trace_borrow_stream_by_id(libObjPtr, id);
679 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
681 return bt_trace_borrow_user_attributes(libObjPtr);
685 /* Functions specific to constant traces */
687 struct CommonTraceSpec<const bt_trace> final
689 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
691 return bt_trace_borrow_class_const(libObjPtr);
694 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
695 const std::uint64_t index) noexcept
697 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
700 static const bt_stream *streamById(const bt_trace * const libObjPtr,
701 const std::uint64_t id) noexcept
703 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
706 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
708 return bt_trace_borrow_user_attributes_const(libObjPtr);
712 } /* namespace internal */
714 template <typename LibObjT>
715 class CommonTrace final : public internal::BorrowedObj<LibObjT>
717 /* Allow instantiate() to call `trace.libObjPtr()` */
718 friend class CommonStreamClass<bt_stream_class>;
721 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
722 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
723 using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
724 using _Spec = internal::CommonTraceSpec<LibObjT>;
725 using _ThisCommonTrace = CommonTrace<LibObjT>;
728 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
729 CommonStream<bt_stream>>::type;
732 using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
734 using Class = typename std::conditional<std::is_const<LibObjT>::value,
735 CommonTraceClass<const bt_trace_class>,
736 CommonTraceClass<bt_trace_class>>::type;
738 using UserAttributes =
739 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
741 struct ConstEnvironmentEntry
743 bpstd::string_view name;
747 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
751 template <typename OtherLibObjT>
752 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObj {trace}
756 template <typename OtherLibObjT>
757 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
759 _ThisBorrowedObj::operator=(trace);
763 CommonTraceClass<const bt_trace_class> cls() const noexcept;
764 Class cls() noexcept;
766 void name(const char * const name)
768 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
770 const auto status = bt_trace_set_name(this->libObjPtr(), name);
772 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
773 throw MemoryError {};
777 void name(const std::string& name)
779 this->name(name.data());
782 nonstd::optional<bpstd::string_view> name() const noexcept
784 const auto name = bt_trace_get_name(this->libObjPtr());
790 return nonstd::nullopt;
793 void uuid(const bt2_common::UuidView& uuid) noexcept
795 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
798 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
800 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
803 return bt2_common::UuidView {uuid};
806 return nonstd::nullopt;
809 std::uint64_t size() const noexcept
811 return bt_trace_get_stream_count(this->libObjPtr());
814 ConstStream operator[](const std::uint64_t index) const noexcept
816 return ConstStream {_ConstSpec::streamByIndex(this->libObjPtr(), index)};
819 _Stream operator[](const std::uint64_t index) noexcept
821 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
824 nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept
826 const auto libObjPtr = _ConstSpec::streamById(this->libObjPtr(), id);
829 return ConstStream {libObjPtr};
832 return nonstd::nullopt;
835 nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept
837 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
840 return _Stream {libObjPtr};
843 return nonstd::nullopt;
846 void environmentEntry(const char * const name, const std::int64_t val)
848 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
850 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
852 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
853 throw MemoryError {};
857 void environmentEntry(const std::string& name, const std::int64_t val)
859 this->environmentEntry(name.data(), val);
862 void environmentEntry(const char * const name, const char * const val)
864 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
866 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
868 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
869 throw MemoryError {};
873 void environmentEntry(const std::string& name, const char * const val)
875 this->environmentEntry(name.data(), val);
878 void environmentEntry(const char * const name, const std::string& val)
880 this->environmentEntry(name, val.data());
883 void environmentEntry(const std::string& name, const std::string& val)
885 this->environmentEntry(name.data(), val.data());
888 std::uint64_t environmentSize() const noexcept
890 return bt_trace_get_environment_entry_count(this->libObjPtr());
893 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
896 const bt_value *libObjPtr;
898 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
900 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
903 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
905 const auto libObjPtr =
906 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
909 return ConstValue {libObjPtr};
912 return nonstd::nullopt;
915 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
917 return this->environmentEntry(name.data());
920 template <typename LibValT>
921 void userAttributes(const CommonMapValue<LibValT> userAttrs)
923 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
925 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
928 ConstMapValue userAttributes() const noexcept
930 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
933 UserAttributes userAttributes() noexcept
935 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
938 Shared shared() const noexcept
940 return Shared::createWithRef(*this);
944 using Trace = CommonTrace<bt_trace>;
945 using ConstTrace = CommonTrace<const bt_trace>;
949 struct TraceTypeDescr
951 using Const = ConstTrace;
952 using NonConst = Trace;
956 struct TypeDescr<Trace> : public TraceTypeDescr
961 struct TypeDescr<ConstTrace> : public TraceTypeDescr
965 } /* namespace internal */
967 template <typename LibObjT>
968 ConstTrace CommonStream<LibObjT>::trace() const noexcept
970 return ConstTrace {_ConstSpec::trace(this->libObjPtr())};
973 template <typename LibObjT>
974 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept
976 return _Trace {_Spec::trace(this->libObjPtr())};
981 struct EventClassRefFuncs final
983 static void get(const bt_event_class * const libObjPtr)
985 bt_event_class_get_ref(libObjPtr);
988 static void put(const bt_event_class * const libObjPtr)
990 bt_event_class_put_ref(libObjPtr);
994 template <typename LibObjT>
995 struct CommonEventClassSpec;
997 /* Functions specific to mutable event classes */
999 struct CommonEventClassSpec<bt_event_class> final
1001 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
1003 return bt_event_class_borrow_stream_class(libObjPtr);
1006 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
1008 return bt_event_class_borrow_payload_field_class(libObjPtr);
1011 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
1013 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
1016 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
1018 return bt_event_class_borrow_user_attributes(libObjPtr);
1022 /* Functions specific to constant event classes */
1024 struct CommonEventClassSpec<const bt_event_class> final
1026 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
1028 return bt_event_class_borrow_stream_class_const(libObjPtr);
1031 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
1033 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
1036 static const bt_field_class *
1037 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
1039 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
1042 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
1044 return bt_event_class_borrow_user_attributes_const(libObjPtr);
1048 } /* namespace internal */
1050 template <typename LibObjT>
1051 class CommonEventClass final : public internal::BorrowedObj<LibObjT>
1054 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1055 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1056 using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
1057 using _Spec = internal::CommonEventClassSpec<LibObjT>;
1058 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
1060 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1061 CommonStreamClass<const bt_stream_class>,
1062 CommonStreamClass<bt_stream_class>>::type;
1064 using _StructureFieldClass =
1065 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1066 StructureFieldClass>::type;
1070 internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
1072 using UserAttributes =
1073 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1077 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
1078 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
1079 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
1080 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
1081 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
1082 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
1083 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
1084 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
1085 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
1086 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
1087 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
1088 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
1089 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
1090 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
1091 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
1094 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1098 template <typename OtherLibObjT>
1099 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
1100 _ThisBorrowedObj {eventClass}
1104 template <typename OtherLibObjT>
1105 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
1107 _ThisBorrowedObj::operator=(eventClass);
1111 CommonStreamClass<const bt_stream_class> streamClass() const noexcept;
1112 _StreamClass streamClass() noexcept;
1114 std::uint64_t id() const noexcept
1116 return bt_event_class_get_id(this->libObjPtr());
1119 void name(const char * const name)
1121 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1123 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1125 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1126 throw MemoryError {};
1130 void name(const std::string& name)
1132 this->name(name.data());
1135 nonstd::optional<bpstd::string_view> name() const noexcept
1137 const auto name = bt_event_class_get_name(this->libObjPtr());
1143 return nonstd::nullopt;
1146 void logLevel(const LogLevel logLevel) noexcept
1148 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1150 bt_event_class_set_log_level(this->libObjPtr(),
1151 static_cast<bt_event_class_log_level>(logLevel));
1154 nonstd::optional<LogLevel> logLevel() const noexcept
1156 bt_event_class_log_level libLogLevel;
1157 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1159 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1160 return static_cast<LogLevel>(libLogLevel);
1163 return nonstd::nullopt;
1166 void emfUri(const char * const emfUri)
1168 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1170 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1172 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1173 throw MemoryError {};
1177 void emfUri(const std::string& emfUri)
1179 this->emfUri(emfUri.data());
1182 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1184 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1190 return nonstd::nullopt;
1193 void payloadFieldClass(const StructureFieldClass fc)
1195 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1198 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1200 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1201 throw MemoryError {};
1205 nonstd::optional<ConstStructureFieldClass> payloadFieldClass() const noexcept
1207 const auto libObjPtr = _ConstSpec::payloadFieldClass(this->libObjPtr());
1210 return ConstStructureFieldClass {libObjPtr};
1213 return nonstd::nullopt;
1216 nonstd::optional<_StructureFieldClass> payloadFieldClass() noexcept
1218 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1221 return _StructureFieldClass {libObjPtr};
1224 return nonstd::nullopt;
1227 void specificContextFieldClass(const StructureFieldClass fc)
1229 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1232 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1234 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1235 throw MemoryError {};
1239 nonstd::optional<ConstStructureFieldClass> specificContextFieldClass() const noexcept
1241 const auto libObjPtr = _ConstSpec::specificContextFieldClass(this->libObjPtr());
1244 return ConstStructureFieldClass {libObjPtr};
1247 return nonstd::nullopt;
1250 nonstd::optional<_StructureFieldClass> specificContextFieldClass() noexcept
1252 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1255 return _StructureFieldClass {libObjPtr};
1258 return nonstd::nullopt;
1261 template <typename LibValT>
1262 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1264 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1266 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1269 ConstMapValue userAttributes() const noexcept
1271 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1274 UserAttributes userAttributes() noexcept
1276 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1279 Shared shared() const noexcept
1281 return Shared::createWithRef(*this);
1285 using EventClass = CommonEventClass<bt_event_class>;
1286 using ConstEventClass = CommonEventClass<const bt_event_class>;
1288 namespace internal {
1290 struct EventClassTypeDescr
1292 using Const = ConstEventClass;
1293 using NonConst = EventClass;
1297 struct TypeDescr<EventClass> : public EventClassTypeDescr
1302 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1306 } /* namespace internal */
1308 template <typename LibObjT>
1309 ConstEventClass CommonEvent<LibObjT>::cls() const noexcept
1311 return ConstEventClass {_ConstSpec::cls(this->libObjPtr())};
1314 template <typename LibObjT>
1315 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() noexcept
1317 return Class {_Spec::cls(this->libObjPtr())};
1320 namespace internal {
1322 struct StreamClassRefFuncs final
1324 static void get(const bt_stream_class * const libObjPtr)
1326 bt_stream_class_get_ref(libObjPtr);
1329 static void put(const bt_stream_class * const libObjPtr)
1331 bt_stream_class_put_ref(libObjPtr);
1335 template <typename LibObjT>
1336 struct CommonStreamClassSpec;
1338 /* Functions specific to mutable stream classes */
1340 struct CommonStreamClassSpec<bt_stream_class> final
1342 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1344 return bt_stream_class_borrow_trace_class(libObjPtr);
1347 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1348 const std::uint64_t index) noexcept
1350 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1353 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1354 const std::uint64_t id) noexcept
1356 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1359 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1361 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1364 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1366 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1369 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1371 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1374 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1376 return bt_stream_class_borrow_user_attributes(libObjPtr);
1380 /* Functions specific to constant stream classes */
1382 struct CommonStreamClassSpec<const bt_stream_class> final
1384 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1386 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1389 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1390 const std::uint64_t index) noexcept
1392 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1395 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1396 const std::uint64_t id) noexcept
1398 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1401 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1403 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1406 static const bt_field_class *
1407 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1409 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1412 static const bt_field_class *
1413 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1415 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1418 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1420 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1424 } /* namespace internal */
1426 template <typename LibObjT>
1427 class CommonStreamClass final : public internal::BorrowedObj<LibObjT>
1430 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1431 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1432 using _ConstSpec = internal::CommonStreamClassSpec<const bt_stream_class>;
1433 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1434 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1436 using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
1437 CommonTraceClass<const bt_trace_class>,
1438 CommonTraceClass<bt_trace_class>>::type;
1440 using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
1441 CommonEventClass<const bt_event_class>,
1442 CommonEventClass<bt_event_class>>::type;
1444 using _StructureFieldClass =
1445 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1446 StructureFieldClass>::type;
1449 typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
1453 internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1455 using UserAttributes =
1456 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1458 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1462 template <typename OtherLibObjT>
1463 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1464 _ThisBorrowedObj {streamClass}
1468 template <typename OtherLibObjT>
1469 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1471 _ThisBorrowedObj::operator=(streamClass);
1475 Stream::Shared instantiate(const Trace trace)
1477 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1479 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1481 internal::validateCreatedObjPtr(libObjPtr);
1482 return Stream::Shared::createWithoutRef(libObjPtr);
1485 Stream::Shared instantiate(const Trace trace, const std::uint64_t id)
1487 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1489 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1491 internal::validateCreatedObjPtr(libObjPtr);
1492 return Stream::Shared::createWithoutRef(libObjPtr);
1495 EventClass::Shared createEventClass()
1497 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1499 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1501 internal::validateCreatedObjPtr(libObjPtr);
1502 return EventClass::Shared::createWithoutRef(libObjPtr);
1505 EventClass::Shared createEventClass(const std::uint64_t id)
1507 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1509 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1511 internal::validateCreatedObjPtr(libObjPtr);
1512 return EventClass::Shared::createWithoutRef(libObjPtr);
1515 CommonTraceClass<const bt_trace_class> traceClass() const noexcept;
1516 _TraceClass traceClass() noexcept;
1518 std::uint64_t id() const noexcept
1520 return bt_stream_class_get_id(this->libObjPtr());
1523 void name(const char * const name)
1525 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1527 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1529 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1530 throw MemoryError {};
1534 void name(const std::string& name)
1536 this->name(name.data());
1539 nonstd::optional<bpstd::string_view> name() const noexcept
1541 const auto name = bt_stream_class_get_name(this->libObjPtr());
1547 return nonstd::nullopt;
1550 void assignsAutomaticEventClassId(const bool val) noexcept
1552 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1554 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1555 static_cast<bt_bool>(val));
1558 bool assignsAutomaticEventClassId() const noexcept
1560 return static_cast<bool>(
1561 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1564 void assignsAutomaticStreamId(const bool val) noexcept
1566 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1568 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1569 static_cast<bt_bool>(val));
1572 bool assignsAutomaticStreamId() const noexcept
1574 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1577 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1578 const bool withEndDefaultClkSnapshot) noexcept
1580 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1582 bt_stream_class_set_supports_packets(this->libObjPtr(),
1583 static_cast<bt_bool>(supportsPackets),
1584 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1585 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1588 bool supportsPackets() const noexcept
1590 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1593 bool packetsHaveBeginningClockSnapshot() const noexcept
1595 return static_cast<bool>(
1596 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1599 bool packetsHaveEndClockSnapshot() const noexcept
1601 return static_cast<bool>(
1602 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1605 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1606 const bool withDefaultClkSnapshots) noexcept
1608 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1610 bt_stream_class_set_supports_discarded_events(
1611 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1612 static_cast<bt_bool>(withDefaultClkSnapshots));
1615 bool supportsDiscardedEvents() const noexcept
1617 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1620 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1622 return static_cast<bool>(
1623 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1626 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1627 const bool withDefaultClkSnapshots) noexcept
1629 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1631 bt_stream_class_set_supports_discarded_packets(
1632 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1633 static_cast<bt_bool>(withDefaultClkSnapshots));
1636 bool supportsDiscardedPackets() const noexcept
1638 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1641 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1643 return static_cast<bool>(
1644 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1647 void defaultClockClass(const ClockClass clkCls)
1649 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1652 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1654 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1657 nonstd::optional<ConstClockClass> defaultClockClass() const noexcept
1659 const auto libObjPtr = _ConstSpec::defaultClockClass(this->libObjPtr());
1662 return ConstClockClass {libObjPtr};
1665 return nonstd::nullopt;
1668 nonstd::optional<_ClockClass> defaultClockClass() noexcept
1670 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1673 return _ClockClass {libObjPtr};
1676 return nonstd::nullopt;
1679 std::uint64_t size() const noexcept
1681 return bt_stream_class_get_event_class_count(this->libObjPtr());
1684 ConstEventClass operator[](const std::uint64_t index) const noexcept
1686 return ConstEventClass {_ConstSpec::eventClassByIndex(this->libObjPtr(), index)};
1689 _EventClass operator[](const std::uint64_t index) noexcept
1691 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1694 nonstd::optional<ConstEventClass> eventClassById(const std::uint64_t id) const noexcept
1696 const auto libObjPtr = _ConstSpec::eventClassById(this->libObjPtr(), id);
1699 return ConstEventClass {libObjPtr};
1702 return nonstd::nullopt;
1705 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) noexcept
1707 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1710 return _EventClass {libObjPtr};
1713 return nonstd::nullopt;
1716 void packetContextFieldClass(const StructureFieldClass fc)
1718 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1721 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1723 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1724 throw MemoryError {};
1728 nonstd::optional<ConstStructureFieldClass> packetContextFieldClass() const noexcept
1730 const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->libObjPtr());
1733 return ConstStructureFieldClass {libObjPtr};
1736 return nonstd::nullopt;
1739 nonstd::optional<_StructureFieldClass> packetContextFieldClass() noexcept
1741 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1744 return _StructureFieldClass {libObjPtr};
1747 return nonstd::nullopt;
1750 void eventCommonContextFieldClass(const StructureFieldClass fc)
1752 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1755 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1757 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1758 throw MemoryError {};
1762 nonstd::optional<ConstStructureFieldClass> eventCommonContextFieldClass() const noexcept
1764 const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->libObjPtr());
1767 return ConstStructureFieldClass {libObjPtr};
1770 return nonstd::nullopt;
1773 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() noexcept
1775 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1778 return _StructureFieldClass {libObjPtr};
1781 return nonstd::nullopt;
1784 template <typename LibValT>
1785 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1787 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1789 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1792 ConstMapValue userAttributes() const noexcept
1794 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1797 UserAttributes userAttributes() noexcept
1799 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1802 Shared shared() const noexcept
1804 return Shared::createWithRef(*this);
1808 using StreamClass = CommonStreamClass<bt_stream_class>;
1809 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1811 namespace internal {
1813 struct StreamClassTypeDescr
1815 using Const = ConstStreamClass;
1816 using NonConst = StreamClass;
1820 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1825 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1829 } /* namespace internal */
1831 template <typename LibObjT>
1832 ConstStreamClass CommonEventClass<LibObjT>::streamClass() const noexcept
1834 return ConstStreamClass {_ConstSpec::streamClass(this->libObjPtr())};
1837 template <typename LibObjT>
1838 typename CommonEventClass<LibObjT>::_StreamClass CommonEventClass<LibObjT>::streamClass() noexcept
1840 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1843 template <typename LibObjT>
1844 ConstStreamClass CommonStream<LibObjT>::cls() const noexcept
1846 return ConstStreamClass {_ConstSpec::cls(this->libObjPtr())};
1849 template <typename LibObjT>
1850 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() noexcept
1852 return Class {_Spec::cls(this->libObjPtr())};
1855 namespace internal {
1857 struct TraceClassRefFuncs final
1859 static void get(const bt_trace_class * const libObjPtr)
1861 bt_trace_class_get_ref(libObjPtr);
1864 static void put(const bt_trace_class * const libObjPtr)
1866 bt_trace_class_put_ref(libObjPtr);
1870 template <typename LibObjT>
1871 struct CommonTraceClassSpec;
1873 /* Functions specific to mutable stream classes */
1875 struct CommonTraceClassSpec<bt_trace_class> final
1877 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1878 const std::uint64_t index) noexcept
1880 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1883 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1884 const std::uint64_t id) noexcept
1886 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1889 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1891 return bt_trace_class_borrow_user_attributes(libObjPtr);
1895 /* Functions specific to constant stream classes */
1897 struct CommonTraceClassSpec<const bt_trace_class> final
1899 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1900 const std::uint64_t index) noexcept
1902 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1905 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1906 const std::uint64_t id) noexcept
1908 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1911 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1913 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1917 } /* namespace internal */
1919 template <typename LibObjT>
1920 class CommonTraceClass final : public internal::BorrowedObj<LibObjT>
1923 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1924 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1925 using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>;
1926 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1927 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1929 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1930 CommonStreamClass<const bt_stream_class>,
1931 CommonStreamClass<bt_stream_class>>::type;
1935 internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1937 using UserAttributes =
1938 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1940 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1944 template <typename OtherLibObjT>
1945 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1946 _ThisBorrowedObj {traceClass}
1950 template <typename OtherLibObjT>
1951 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1953 _ThisBorrowedObj::operator=(traceClass);
1957 Trace::Shared instantiate()
1959 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1961 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1963 internal::validateCreatedObjPtr(libObjPtr);
1964 return Trace::Shared::createWithoutRef(libObjPtr);
1967 StreamClass::Shared createStreamClass()
1969 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1971 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1973 internal::validateCreatedObjPtr(libObjPtr);
1974 return StreamClass::Shared::createWithoutRef(libObjPtr);
1977 StreamClass::Shared createStreamClass(const std::uint64_t id)
1979 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1981 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1983 internal::validateCreatedObjPtr(libObjPtr);
1984 return StreamClass::Shared::createWithoutRef(libObjPtr);
1987 FieldClass::Shared createBoolFieldClass()
1989 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1991 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1993 internal::validateCreatedObjPtr(libObjPtr);
1994 return FieldClass::Shared::createWithoutRef(libObjPtr);
1997 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length)
1999 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2001 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
2003 internal::validateCreatedObjPtr(libObjPtr);
2004 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2007 IntegerFieldClass::Shared createUnsignedIntegerFieldClass()
2009 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2011 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
2013 internal::validateCreatedObjPtr(libObjPtr);
2014 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2017 IntegerFieldClass::Shared createSignedIntegerFieldClass()
2019 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2021 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
2023 internal::validateCreatedObjPtr(libObjPtr);
2024 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2027 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass()
2029 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2031 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
2033 internal::validateCreatedObjPtr(libObjPtr);
2034 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2037 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass()
2039 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2041 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
2043 internal::validateCreatedObjPtr(libObjPtr);
2044 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2047 FieldClass::Shared createSinglePrecisionRealFieldClass()
2049 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2051 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
2053 internal::validateCreatedObjPtr(libObjPtr);
2054 return FieldClass::Shared::createWithoutRef(libObjPtr);
2057 FieldClass::Shared createDoublePrecisionRealFieldClass()
2059 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2061 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
2063 internal::validateCreatedObjPtr(libObjPtr);
2064 return FieldClass::Shared::createWithoutRef(libObjPtr);
2067 FieldClass::Shared createStringFieldClass()
2069 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2071 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
2073 internal::validateCreatedObjPtr(libObjPtr);
2074 return FieldClass::Shared::createWithoutRef(libObjPtr);
2077 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
2078 const std::uint64_t length)
2080 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2082 const auto libObjPtr = bt_field_class_array_static_create(
2083 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
2085 internal::validateCreatedObjPtr(libObjPtr);
2086 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2089 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass)
2091 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2093 const auto libObjPtr = bt_field_class_array_dynamic_create(
2094 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
2096 internal::validateCreatedObjPtr(libObjPtr);
2097 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2100 DynamicArrayWithLengthFieldClass::Shared
2101 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
2102 const IntegerFieldClass lengthFieldClass)
2104 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2106 const auto libObjPtr = bt_field_class_array_dynamic_create(
2107 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
2109 internal::validateCreatedObjPtr(libObjPtr);
2110 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
2113 StructureFieldClass::Shared createStructureFieldClass()
2115 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2117 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
2119 internal::validateCreatedObjPtr(libObjPtr);
2120 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
2123 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass)
2125 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2127 const auto libObjPtr = bt_field_class_option_without_selector_create(
2128 this->libObjPtr(), optionalFieldClass.libObjPtr());
2130 internal::validateCreatedObjPtr(libObjPtr);
2131 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
2134 OptionWithBoolSelectorFieldClass::Shared
2135 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
2136 const FieldClass selectorFieldClass)
2138 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2140 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
2141 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
2143 internal::validateCreatedObjPtr(libObjPtr);
2144 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2147 OptionWithUnsignedIntegerSelectorFieldClass::Shared
2148 createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2149 const IntegerFieldClass selectorFieldClass,
2150 const ConstUnsignedIntegerRangeSet ranges)
2152 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2154 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
2155 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2156 ranges.libObjPtr());
2158 internal::validateCreatedObjPtr(libObjPtr);
2159 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2162 OptionWithSignedIntegerSelectorFieldClass::Shared
2163 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2164 const IntegerFieldClass selectorFieldClass,
2165 const ConstSignedIntegerRangeSet ranges)
2167 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2169 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
2170 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2171 ranges.libObjPtr());
2173 internal::validateCreatedObjPtr(libObjPtr);
2174 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2177 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass()
2179 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2181 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
2183 internal::validateCreatedObjPtr(libObjPtr);
2184 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2187 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2188 createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2190 return this->_createVariantWithIntegerSelectorFieldClass<
2191 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
2194 VariantWithSignedIntegerSelectorFieldClass::Shared
2195 createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2197 return this->_createVariantWithIntegerSelectorFieldClass<
2198 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
2201 void assignsAutomaticStreamClassId(const bool val) noexcept
2203 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2205 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
2206 static_cast<bt_bool>(val));
2209 bool assignsAutomaticStreamClassId() const noexcept
2211 return static_cast<bool>(
2212 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2215 std::uint64_t size() const noexcept
2217 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2220 ConstStreamClass operator[](const std::uint64_t index) const noexcept
2222 return ConstStreamClass {_ConstSpec::streamClassByIndex(this->libObjPtr(), index)};
2225 _StreamClass operator[](const std::uint64_t index) noexcept
2227 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2230 nonstd::optional<ConstStreamClass> streamClassById(const std::uint64_t id) const noexcept
2232 const auto libObjPtr = _ConstSpec::streamClassById(this->libObjPtr(), id);
2235 return ConstStreamClass {libObjPtr};
2238 return nonstd::nullopt;
2241 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) noexcept
2243 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2246 return _StreamClass {libObjPtr};
2249 return nonstd::nullopt;
2252 template <typename LibValT>
2253 void userAttributes(const CommonMapValue<LibValT> userAttrs)
2255 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2257 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2260 ConstMapValue userAttributes() const noexcept
2262 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
2265 UserAttributes userAttributes() noexcept
2267 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2270 Shared shared() const noexcept
2272 return Shared::createWithRef(*this);
2276 template <typename ObjT>
2277 typename ObjT::Shared
2278 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2280 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2282 const auto libObjPtr =
2283 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2285 internal::validateCreatedObjPtr(libObjPtr);
2286 return ObjT::Shared::createWithoutRef(libObjPtr);
2290 using TraceClass = CommonTraceClass<bt_trace_class>;
2291 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2293 namespace internal {
2295 struct TraceClassTypeDescr
2297 using Const = ConstTraceClass;
2298 using NonConst = TraceClass;
2302 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2307 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2311 } /* namespace internal */
2313 template <typename LibObjT>
2314 ConstTraceClass CommonStreamClass<LibObjT>::traceClass() const noexcept
2316 return ConstTraceClass {_ConstSpec::traceClass(this->libObjPtr())};
2319 template <typename LibObjT>
2320 typename CommonStreamClass<LibObjT>::_TraceClass CommonStreamClass<LibObjT>::traceClass() noexcept
2322 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2325 template <typename LibObjT>
2326 ConstTraceClass CommonTrace<LibObjT>::cls() const noexcept
2328 return ConstTraceClass {_ConstSpec::cls(this->libObjPtr())};
2331 template <typename LibObjT>
2332 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() noexcept
2334 return Class {_Spec::cls(this->libObjPtr())};
2337 } /* namespace bt2 */
2339 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */