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
10 #include <type_traits>
12 #include <babeltrace2/babeltrace.h>
14 #include "internal/borrowed-obj.hpp"
15 #include "cpp-common/optional.hpp"
16 #include "cpp-common/string_view.hpp"
17 #include "clock-class.hpp"
18 #include "clock-snapshot.hpp"
19 #include "field-class.hpp"
22 #include "internal/utils.hpp"
26 template <typename LibObjT>
29 template <typename LibObjT>
32 template <typename LibObjT>
35 template <typename LibObjT>
38 template <typename LibObjT>
39 class CommonEventClass;
41 template <typename LibObjT>
42 class CommonStreamClass;
44 template <typename LibObjT>
45 class CommonTraceClass;
49 template <typename LibObjT>
50 struct CommonEventSpec;
52 /* Functions specific to mutable events */
54 struct CommonEventSpec<bt_event> final
56 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
58 return bt_event_borrow_class(libObjPtr);
61 static bt_stream *stream(bt_event * const libObjPtr) noexcept
63 return bt_event_borrow_stream(libObjPtr);
66 static bt_packet *packet(bt_event * const libObjPtr) noexcept
68 return bt_event_borrow_packet(libObjPtr);
71 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
73 return bt_event_borrow_payload_field(libObjPtr);
76 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
78 return bt_event_borrow_specific_context_field(libObjPtr);
81 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
83 return bt_event_borrow_common_context_field(libObjPtr);
87 /* Functions specific to constant events */
89 struct CommonEventSpec<const bt_event> final
91 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
93 return bt_event_borrow_class_const(libObjPtr);
96 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
98 return bt_event_borrow_stream_const(libObjPtr);
101 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
103 return bt_event_borrow_packet_const(libObjPtr);
106 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
108 return bt_event_borrow_payload_field_const(libObjPtr);
111 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
113 return bt_event_borrow_specific_context_field_const(libObjPtr);
116 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
118 return bt_event_borrow_common_context_field_const(libObjPtr);
122 } /* namespace internal */
124 template <typename LibObjT>
125 class CommonEvent final : public internal::BorrowedObj<LibObjT>
128 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
129 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
130 using _ConstSpec = internal::CommonEventSpec<const bt_event>;
131 using _Spec = internal::CommonEventSpec<LibObjT>;
134 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
135 CommonPacket<bt_packet>>::type;
138 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
139 CommonStream<bt_stream>>::type;
141 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
142 ConstStructureField, StructureField>::type;
145 using Class = typename std::conditional<std::is_const<LibObjT>::value,
146 CommonEventClass<const bt_event_class>,
147 CommonEventClass<bt_event_class>>::type;
149 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
153 template <typename OtherLibObjT>
154 CommonEvent(const CommonEvent<OtherLibObjT>& event) noexcept : _ThisBorrowedObj {event}
158 template <typename OtherLibObjT>
159 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT>& event) noexcept
161 _ThisBorrowedObj::operator=(event);
165 CommonEventClass<const bt_event_class> cls() const noexcept;
166 Class cls() noexcept;
167 CommonStream<const bt_stream> stream() const noexcept;
168 _Stream stream() noexcept;
169 nonstd::optional<CommonPacket<const bt_packet>> packet() const noexcept;
170 nonstd::optional<_Packet> packet() noexcept;
172 nonstd::optional<ConstStructureField> payloadField() const noexcept
174 const auto libObjPtr = _ConstSpec::payloadField(this->libObjPtr());
177 return ConstStructureField {libObjPtr};
180 return nonstd::nullopt;
183 nonstd::optional<_StructureField> payloadField() noexcept
185 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
188 return _StructureField {libObjPtr};
191 return nonstd::nullopt;
194 nonstd::optional<ConstStructureField> specificContextField() const noexcept
196 const auto libObjPtr = _ConstSpec::specificContextField(this->libObjPtr());
199 return ConstStructureField {libObjPtr};
202 return nonstd::nullopt;
205 nonstd::optional<_StructureField> specificContextField() noexcept
207 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
210 return _StructureField {libObjPtr};
213 return nonstd::nullopt;
216 nonstd::optional<ConstStructureField> commonContextField() const noexcept
218 const auto libObjPtr = _ConstSpec::commonContextField(this->libObjPtr());
221 return ConstStructureField {libObjPtr};
224 return nonstd::nullopt;
227 nonstd::optional<_StructureField> commonContextField() noexcept
229 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
232 return _StructureField {libObjPtr};
235 return nonstd::nullopt;
239 using Event = CommonEvent<bt_event>;
240 using ConstEvent = CommonEvent<const bt_event>;
244 struct EventTypeDescr
246 using Const = ConstEvent;
247 using NonConst = Event;
251 struct TypeDescr<Event> : public EventTypeDescr
256 struct TypeDescr<ConstEvent> : public EventTypeDescr
260 struct PacketRefFuncs final
262 static void get(const bt_packet * const libObjPtr)
264 bt_packet_get_ref(libObjPtr);
267 static void put(const bt_packet * const libObjPtr)
269 bt_packet_put_ref(libObjPtr);
273 template <typename LibObjT>
274 struct CommonPacketSpec;
276 /* Functions specific to mutable packets */
278 struct CommonPacketSpec<bt_packet> final
280 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
282 return bt_packet_borrow_stream(libObjPtr);
285 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
287 return bt_packet_borrow_context_field(libObjPtr);
291 /* Functions specific to constant packets */
293 struct CommonPacketSpec<const bt_packet> final
295 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
297 return bt_packet_borrow_stream_const(libObjPtr);
300 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
302 return bt_packet_borrow_context_field_const(libObjPtr);
306 } /* namespace internal */
308 template <typename LibObjT>
309 class CommonPacket final : public internal::BorrowedObj<LibObjT>
312 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
313 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
314 using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
315 using _Spec = internal::CommonPacketSpec<LibObjT>;
316 using _ThisCommonPacket = CommonPacket<LibObjT>;
319 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
320 CommonStream<bt_stream>>::type;
322 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
323 ConstStructureField, StructureField>::type;
326 using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
328 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
332 template <typename OtherLibObjT>
333 CommonPacket(const CommonPacket<OtherLibObjT>& packet) noexcept : _ThisBorrowedObj {packet}
337 template <typename OtherLibObjT>
338 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT>& packet) noexcept
340 _ThisBorrowedObj::operator=(packet);
344 CommonStream<const bt_stream> stream() const noexcept;
345 _Stream stream() noexcept;
347 nonstd::optional<ConstStructureField> contextField() const noexcept
349 const auto libObjPtr = _ConstSpec::contextField(this->libObjPtr());
352 return ConstStructureField {libObjPtr};
355 return nonstd::nullopt;
358 nonstd::optional<_StructureField> contextField() noexcept
360 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
363 return _StructureField {libObjPtr};
366 return nonstd::nullopt;
369 Shared shared() const noexcept
371 return Shared::createWithRef(*this);
375 using Packet = CommonPacket<bt_packet>;
376 using ConstPacket = CommonPacket<const bt_packet>;
380 struct PacketTypeDescr
382 using Const = ConstPacket;
383 using NonConst = Packet;
387 struct TypeDescr<Packet> : public PacketTypeDescr
392 struct TypeDescr<ConstPacket> : public PacketTypeDescr
396 } /* namespace internal */
398 template <typename LibObjT>
399 nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
401 const auto libObjPtr = _ConstSpec::packet(this->libObjPtr());
404 return ConstPacket {libObjPtr};
407 return nonstd::nullopt;
410 template <typename LibObjT>
411 nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept
413 const auto libObjPtr = _Spec::packet(this->libObjPtr());
416 return _Packet {libObjPtr};
419 return nonstd::nullopt;
424 struct StreamRefFuncs final
426 static void get(const bt_stream * const libObjPtr)
428 bt_stream_get_ref(libObjPtr);
431 static void put(const bt_stream * const libObjPtr)
433 bt_stream_put_ref(libObjPtr);
437 template <typename LibObjT>
438 struct CommonStreamSpec;
440 /* Functions specific to mutable streams */
442 struct CommonStreamSpec<bt_stream> final
444 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
446 return bt_stream_borrow_class(libObjPtr);
449 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
451 return bt_stream_borrow_trace(libObjPtr);
454 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
456 return bt_stream_borrow_user_attributes(libObjPtr);
460 /* Functions specific to constant streams */
462 struct CommonStreamSpec<const bt_stream> final
464 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
466 return bt_stream_borrow_class_const(libObjPtr);
469 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
471 return bt_stream_borrow_trace_const(libObjPtr);
474 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
476 return bt_stream_borrow_user_attributes_const(libObjPtr);
480 } /* namespace internal */
482 template <typename LibObjT>
483 class CommonStream final : public internal::BorrowedObj<LibObjT>
486 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
487 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
488 using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
489 using _Spec = internal::CommonStreamSpec<LibObjT>;
490 using _ThisCommonStream = CommonStream<LibObjT>;
493 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
494 CommonTrace<bt_trace>>::type;
497 using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
499 using Class = typename std::conditional<std::is_const<LibObjT>::value,
500 CommonStreamClass<const bt_stream_class>,
501 CommonStreamClass<bt_stream_class>>::type;
503 using UserAttributes =
504 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
506 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
510 template <typename OtherLibObjT>
511 CommonStream(const CommonStream<OtherLibObjT>& stream) noexcept : _ThisBorrowedObj {stream}
515 template <typename OtherLibObjT>
516 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT>& stream) noexcept
518 _ThisBorrowedObj::operator=(stream);
522 Packet::Shared createPacket()
524 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
526 const auto libObjPtr = bt_packet_create(this->libObjPtr());
528 internal::validateCreatedObjPtr(libObjPtr);
529 return Packet::Shared::createWithoutRef(libObjPtr);
532 CommonStreamClass<const bt_stream_class> cls() const noexcept;
533 Class cls() noexcept;
534 CommonTrace<const bt_trace> trace() const noexcept;
535 _Trace trace() noexcept;
537 std::uint64_t id() const noexcept
539 return bt_stream_get_id(this->libObjPtr());
542 void name(const char * const name)
544 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
546 const auto status = bt_stream_set_name(this->libObjPtr(), name);
548 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
549 throw MemoryError {};
553 void name(const std::string& name)
555 this->name(name.data());
558 nonstd::optional<bpstd::string_view> name() const noexcept
560 const auto name = bt_stream_get_name(this->libObjPtr());
566 return nonstd::nullopt;
569 template <typename LibValT>
570 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
572 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
574 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
577 ConstMapValue userAttributes() const noexcept
579 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
582 UserAttributes userAttributes() noexcept
584 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
587 Shared shared() const noexcept
589 return Shared::createWithRef(*this);
593 using Stream = CommonStream<bt_stream>;
594 using ConstStream = CommonStream<const bt_stream>;
598 struct StreamTypeDescr
600 using Const = ConstStream;
601 using NonConst = Stream;
605 struct TypeDescr<Stream> : public StreamTypeDescr
610 struct TypeDescr<ConstStream> : public StreamTypeDescr
614 } /* namespace internal */
616 template <typename LibObjT>
617 ConstStream CommonEvent<LibObjT>::stream() const noexcept
619 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
622 template <typename LibObjT>
623 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept
625 return _Stream {_Spec::stream(this->libObjPtr())};
628 template <typename LibObjT>
629 ConstStream CommonPacket<LibObjT>::stream() const noexcept
631 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
634 template <typename LibObjT>
635 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept
637 return _Stream {_Spec::stream(this->libObjPtr())};
642 struct TraceRefFuncs final
644 static void get(const bt_trace * const libObjPtr)
646 bt_trace_get_ref(libObjPtr);
649 static void put(const bt_trace * const libObjPtr)
651 bt_trace_put_ref(libObjPtr);
655 template <typename LibObjT>
656 struct CommonTraceSpec;
658 /* Functions specific to mutable traces */
660 struct CommonTraceSpec<bt_trace> final
662 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
664 return bt_trace_borrow_class(libObjPtr);
667 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
669 return bt_trace_borrow_stream_by_index(libObjPtr, index);
672 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
674 return bt_trace_borrow_stream_by_id(libObjPtr, id);
677 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
679 return bt_trace_borrow_user_attributes(libObjPtr);
683 /* Functions specific to constant traces */
685 struct CommonTraceSpec<const bt_trace> final
687 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
689 return bt_trace_borrow_class_const(libObjPtr);
692 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
693 const std::uint64_t index) noexcept
695 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
698 static const bt_stream *streamById(const bt_trace * const libObjPtr,
699 const std::uint64_t id) noexcept
701 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
704 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
706 return bt_trace_borrow_user_attributes_const(libObjPtr);
710 } /* namespace internal */
712 template <typename LibObjT>
713 class CommonTrace final : public internal::BorrowedObj<LibObjT>
715 /* Allow instantiate() to call `trace.libObjPtr()` */
716 friend class CommonStreamClass<bt_stream_class>;
719 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
720 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
721 using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
722 using _Spec = internal::CommonTraceSpec<LibObjT>;
723 using _ThisCommonTrace = CommonTrace<LibObjT>;
726 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
727 CommonStream<bt_stream>>::type;
730 using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
732 using Class = typename std::conditional<std::is_const<LibObjT>::value,
733 CommonTraceClass<const bt_trace_class>,
734 CommonTraceClass<bt_trace_class>>::type;
736 using UserAttributes =
737 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
739 struct ConstEnvironmentEntry
741 bpstd::string_view name;
745 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
749 template <typename OtherLibObjT>
750 CommonTrace(const CommonTrace<OtherLibObjT>& trace) noexcept : _ThisBorrowedObj {trace}
754 template <typename OtherLibObjT>
755 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT>& trace) noexcept
757 _ThisBorrowedObj::operator=(trace);
761 CommonTraceClass<const bt_trace_class> cls() const noexcept;
762 Class cls() noexcept;
764 void name(const char * const name)
766 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
768 const auto status = bt_trace_set_name(this->libObjPtr(), name);
770 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
771 throw MemoryError {};
775 void name(const std::string& name)
777 this->name(name.data());
780 nonstd::optional<bpstd::string_view> name() const noexcept
782 const auto name = bt_trace_get_name(this->libObjPtr());
788 return nonstd::nullopt;
791 void uuid(const std::uint8_t * const uuid) noexcept
793 bt_trace_set_uuid(this->libObjPtr(), uuid);
796 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
798 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
801 return bt2_common::UuidView {uuid};
804 return nonstd::nullopt;
807 std::uint64_t size() const noexcept
809 return bt_trace_get_stream_count(this->libObjPtr());
812 ConstStream operator[](const std::uint64_t index) const noexcept
814 return ConstStream {_ConstSpec::streamByIndex(this->libObjPtr(), index)};
817 _Stream operator[](const std::uint64_t index) noexcept
819 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
822 nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept
824 const auto libObjPtr = _ConstSpec::streamById(this->libObjPtr(), id);
827 return ConstStream {libObjPtr};
830 return nonstd::nullopt;
833 nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept
835 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
838 return _Stream {libObjPtr};
841 return nonstd::nullopt;
844 void environmentEntry(const char * const name, const std::int64_t val)
846 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
848 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
850 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
851 throw MemoryError {};
855 void environmentEntry(const std::string& name, const std::int64_t val)
857 this->environmentEntry(name.data(), val);
860 void environmentEntry(const char * const name, const char * const val)
862 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
864 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
866 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
867 throw MemoryError {};
871 void environmentEntry(const std::string& name, const char * const val)
873 this->environmentEntry(name.data(), val);
876 void environmentEntry(const char * const name, const std::string& val)
878 this->environmentEntry(name, val.data());
881 void environmentEntry(const std::string& name, const std::string& val)
883 this->environmentEntry(name.data(), val.data());
886 std::uint64_t environmentSize() const noexcept
888 return bt_trace_get_environment_entry_count(this->libObjPtr());
891 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
894 const bt_value *libObjPtr;
896 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
898 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
901 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
903 const auto libObjPtr =
904 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
907 return ConstValue {libObjPtr};
910 return nonstd::nullopt;
913 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
915 return this->environmentEntry(name.data());
918 template <typename LibValT>
919 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
921 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
923 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
926 ConstMapValue userAttributes() const noexcept
928 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
931 UserAttributes userAttributes() noexcept
933 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
936 Shared shared() const noexcept
938 return Shared::createWithRef(*this);
942 using Trace = CommonTrace<bt_trace>;
943 using ConstTrace = CommonTrace<const bt_trace>;
947 struct TraceTypeDescr
949 using Const = ConstTrace;
950 using NonConst = Trace;
954 struct TypeDescr<Trace> : public TraceTypeDescr
959 struct TypeDescr<ConstTrace> : public TraceTypeDescr
963 } /* namespace internal */
965 template <typename LibObjT>
966 ConstTrace CommonStream<LibObjT>::trace() const noexcept
968 return ConstTrace {_ConstSpec::trace(this->libObjPtr())};
971 template <typename LibObjT>
972 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept
974 return _Trace {_Spec::trace(this->libObjPtr())};
979 struct EventClassRefFuncs final
981 static void get(const bt_event_class * const libObjPtr)
983 bt_event_class_get_ref(libObjPtr);
986 static void put(const bt_event_class * const libObjPtr)
988 bt_event_class_put_ref(libObjPtr);
992 template <typename LibObjT>
993 struct CommonEventClassSpec;
995 /* Functions specific to mutable event classes */
997 struct CommonEventClassSpec<bt_event_class> final
999 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
1001 return bt_event_class_borrow_stream_class(libObjPtr);
1004 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
1006 return bt_event_class_borrow_payload_field_class(libObjPtr);
1009 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
1011 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
1014 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
1016 return bt_event_class_borrow_user_attributes(libObjPtr);
1020 /* Functions specific to constant event classes */
1022 struct CommonEventClassSpec<const bt_event_class> final
1024 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
1026 return bt_event_class_borrow_stream_class_const(libObjPtr);
1029 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
1031 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
1034 static const bt_field_class *
1035 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
1037 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
1040 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
1042 return bt_event_class_borrow_user_attributes_const(libObjPtr);
1046 } /* namespace internal */
1048 template <typename LibObjT>
1049 class CommonEventClass final : public internal::BorrowedObj<LibObjT>
1052 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1053 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1054 using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
1055 using _Spec = internal::CommonEventClassSpec<LibObjT>;
1056 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
1058 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1059 CommonStreamClass<const bt_stream_class>,
1060 CommonStreamClass<bt_stream_class>>::type;
1062 using _StructureFieldClass =
1063 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1064 StructureFieldClass>::type;
1068 internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
1070 using UserAttributes =
1071 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1075 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
1076 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
1077 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
1078 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
1079 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
1080 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
1081 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
1082 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
1083 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
1084 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
1085 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
1086 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
1087 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
1088 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
1089 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
1092 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1096 template <typename OtherLibObjT>
1097 CommonEventClass(const CommonEventClass<OtherLibObjT>& eventClass) noexcept :
1098 _ThisBorrowedObj {eventClass}
1102 template <typename OtherLibObjT>
1103 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT>& eventClass) noexcept
1105 _ThisBorrowedObj::operator=(eventClass);
1109 CommonStreamClass<const bt_stream_class> streamClass() const noexcept;
1110 _StreamClass streamClass() noexcept;
1112 std::uint64_t id() const noexcept
1114 return bt_event_class_get_id(this->libObjPtr());
1117 void name(const char * const name)
1119 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1121 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1123 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1124 throw MemoryError {};
1128 void name(const std::string& name)
1130 this->name(name.data());
1133 nonstd::optional<bpstd::string_view> name() const noexcept
1135 const auto name = bt_event_class_get_name(this->libObjPtr());
1141 return nonstd::nullopt;
1144 void logLevel(const LogLevel logLevel) noexcept
1146 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1148 bt_event_class_set_log_level(this->libObjPtr(),
1149 static_cast<bt_event_class_log_level>(logLevel));
1152 nonstd::optional<LogLevel> logLevel() const noexcept
1154 bt_event_class_log_level libLogLevel;
1155 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1157 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1158 return static_cast<LogLevel>(libLogLevel);
1161 return nonstd::nullopt;
1164 void emfUri(const char * const emfUri)
1166 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1168 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1170 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1171 throw MemoryError {};
1175 void emfUri(const std::string& emfUri)
1177 this->emfUri(emfUri.data());
1180 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1182 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1188 return nonstd::nullopt;
1191 void payloadFieldClass(const StructureFieldClass& fc)
1193 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1196 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1198 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1199 throw MemoryError {};
1203 nonstd::optional<ConstStructureFieldClass> payloadFieldClass() const noexcept
1205 const auto libObjPtr = _ConstSpec::payloadFieldClass(this->libObjPtr());
1208 return ConstStructureFieldClass {libObjPtr};
1211 return nonstd::nullopt;
1214 nonstd::optional<_StructureFieldClass> payloadFieldClass() noexcept
1216 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1219 return _StructureFieldClass {libObjPtr};
1222 return nonstd::nullopt;
1225 void specificContextFieldClass(const StructureFieldClass& fc)
1227 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1230 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1232 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1233 throw MemoryError {};
1237 nonstd::optional<ConstStructureFieldClass> specificContextFieldClass() const noexcept
1239 const auto libObjPtr = _ConstSpec::specificContextFieldClass(this->libObjPtr());
1242 return ConstStructureFieldClass {libObjPtr};
1245 return nonstd::nullopt;
1248 nonstd::optional<_StructureFieldClass> specificContextFieldClass() noexcept
1250 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1253 return _StructureFieldClass {libObjPtr};
1256 return nonstd::nullopt;
1259 template <typename LibValT>
1260 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
1262 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1264 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1267 ConstMapValue userAttributes() const noexcept
1269 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1272 UserAttributes userAttributes() noexcept
1274 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1277 Shared shared() const noexcept
1279 return Shared::createWithRef(*this);
1283 using EventClass = CommonEventClass<bt_event_class>;
1284 using ConstEventClass = CommonEventClass<const bt_event_class>;
1286 namespace internal {
1288 struct EventClassTypeDescr
1290 using Const = ConstEventClass;
1291 using NonConst = EventClass;
1295 struct TypeDescr<EventClass> : public EventClassTypeDescr
1300 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1304 } /* namespace internal */
1306 template <typename LibObjT>
1307 ConstEventClass CommonEvent<LibObjT>::cls() const noexcept
1309 return ConstEventClass {_ConstSpec::cls(this->libObjPtr())};
1312 template <typename LibObjT>
1313 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() noexcept
1315 return Class {_Spec::cls(this->libObjPtr())};
1318 namespace internal {
1320 struct StreamClassRefFuncs final
1322 static void get(const bt_stream_class * const libObjPtr)
1324 bt_stream_class_get_ref(libObjPtr);
1327 static void put(const bt_stream_class * const libObjPtr)
1329 bt_stream_class_put_ref(libObjPtr);
1333 template <typename LibObjT>
1334 struct CommonStreamClassSpec;
1336 /* Functions specific to mutable stream classes */
1338 struct CommonStreamClassSpec<bt_stream_class> final
1340 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1342 return bt_stream_class_borrow_trace_class(libObjPtr);
1345 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1346 const std::uint64_t index) noexcept
1348 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1351 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1352 const std::uint64_t id) noexcept
1354 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1357 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1359 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1362 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1364 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1367 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1369 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1372 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1374 return bt_stream_class_borrow_user_attributes(libObjPtr);
1378 /* Functions specific to constant stream classes */
1380 struct CommonStreamClassSpec<const bt_stream_class> final
1382 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1384 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1387 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1388 const std::uint64_t index) noexcept
1390 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1393 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1394 const std::uint64_t id) noexcept
1396 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1399 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1401 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1404 static const bt_field_class *
1405 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1407 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1410 static const bt_field_class *
1411 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1413 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1416 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1418 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1422 } /* namespace internal */
1424 template <typename LibObjT>
1425 class CommonStreamClass final : public internal::BorrowedObj<LibObjT>
1428 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1429 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1430 using _ConstSpec = internal::CommonStreamClassSpec<const bt_stream_class>;
1431 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1432 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1434 using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
1435 CommonTraceClass<const bt_trace_class>,
1436 CommonTraceClass<bt_trace_class>>::type;
1438 using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
1439 CommonEventClass<const bt_event_class>,
1440 CommonEventClass<bt_event_class>>::type;
1442 using _StructureFieldClass =
1443 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1444 StructureFieldClass>::type;
1447 typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
1451 internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1453 using UserAttributes =
1454 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1456 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1460 template <typename OtherLibObjT>
1461 CommonStreamClass(const CommonStreamClass<OtherLibObjT>& streamClass) noexcept :
1462 _ThisBorrowedObj {streamClass}
1466 template <typename OtherLibObjT>
1467 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT>& streamClass) noexcept
1469 _ThisBorrowedObj::operator=(streamClass);
1473 Stream::Shared instantiate(const Trace& trace)
1475 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1477 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1479 internal::validateCreatedObjPtr(libObjPtr);
1480 return Stream::Shared::createWithoutRef(libObjPtr);
1483 Stream::Shared instantiate(const Trace& trace, const std::uint64_t id)
1485 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1487 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1489 internal::validateCreatedObjPtr(libObjPtr);
1490 return Stream::Shared::createWithoutRef(libObjPtr);
1493 EventClass::Shared createEventClass()
1495 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1497 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1499 internal::validateCreatedObjPtr(libObjPtr);
1500 return EventClass::Shared::createWithoutRef(libObjPtr);
1503 EventClass::Shared createEventClass(const std::uint64_t id)
1505 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1507 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1509 internal::validateCreatedObjPtr(libObjPtr);
1510 return EventClass::Shared::createWithoutRef(libObjPtr);
1513 CommonTraceClass<const bt_trace_class> traceClass() const noexcept;
1514 _TraceClass traceClass() noexcept;
1516 std::uint64_t id() const noexcept
1518 return bt_stream_class_get_id(this->libObjPtr());
1521 void name(const char * const name)
1523 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1525 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1527 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1528 throw MemoryError {};
1532 void name(const std::string& name)
1534 this->name(name.data());
1537 nonstd::optional<bpstd::string_view> name() const noexcept
1539 const auto name = bt_stream_class_get_name(this->libObjPtr());
1545 return nonstd::nullopt;
1548 void assignsAutomaticEventClassId(const bool val) noexcept
1550 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1552 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1553 static_cast<bt_bool>(val));
1556 bool assignsAutomaticEventClassId() const noexcept
1558 return static_cast<bool>(
1559 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1562 void assignsAutomaticStreamId(const bool val) noexcept
1564 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1566 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1567 static_cast<bt_bool>(val));
1570 bool assignsAutomaticStreamId() const noexcept
1572 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1575 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1576 const bool withEndDefaultClkSnapshot) noexcept
1578 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1580 bt_stream_class_set_supports_packets(this->libObjPtr(),
1581 static_cast<bt_bool>(supportsPackets),
1582 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1583 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1586 bool supportsPackets() const noexcept
1588 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1591 bool packetsHaveBeginningClockSnapshot() const noexcept
1593 return static_cast<bool>(
1594 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1597 bool packetsHaveEndClockSnapshot() const noexcept
1599 return static_cast<bool>(
1600 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1603 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1604 const bool withDefaultClkSnapshots) noexcept
1606 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1608 bt_stream_class_set_supports_discarded_events(
1609 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1610 static_cast<bt_bool>(withDefaultClkSnapshots));
1613 bool supportsDiscardedEvents() const noexcept
1615 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1618 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1620 return static_cast<bool>(
1621 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1624 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1625 const bool withDefaultClkSnapshots) noexcept
1627 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1629 bt_stream_class_set_supports_discarded_packets(
1630 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1631 static_cast<bt_bool>(withDefaultClkSnapshots));
1634 bool supportsDiscardedPackets() const noexcept
1636 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1639 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1641 return static_cast<bool>(
1642 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1645 void defaultClockClass(const ClockClass& clkCls)
1647 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1650 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1652 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1655 nonstd::optional<ConstClockClass> defaultClockClass() const noexcept
1657 const auto libObjPtr = _ConstSpec::defaultClockClass(this->libObjPtr());
1660 return ConstClockClass {libObjPtr};
1663 return nonstd::nullopt;
1666 nonstd::optional<_ClockClass> defaultClockClass() noexcept
1668 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1671 return _ClockClass {libObjPtr};
1674 return nonstd::nullopt;
1677 std::uint64_t size() const noexcept
1679 return bt_stream_class_get_event_class_count(this->libObjPtr());
1682 ConstEventClass operator[](const std::uint64_t index) const noexcept
1684 return ConstEventClass {_ConstSpec::eventClassByIndex(this->libObjPtr(), index)};
1687 _EventClass operator[](const std::uint64_t index) noexcept
1689 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1692 nonstd::optional<ConstEventClass> eventClassById(const std::uint64_t id) const noexcept
1694 const auto libObjPtr = _ConstSpec::eventClassById(this->libObjPtr(), id);
1697 return ConstEventClass {libObjPtr};
1700 return nonstd::nullopt;
1703 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) noexcept
1705 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1708 return _EventClass {libObjPtr};
1711 return nonstd::nullopt;
1714 void packetContextFieldClass(const StructureFieldClass& fc)
1716 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1719 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1721 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1722 throw MemoryError {};
1726 nonstd::optional<ConstStructureFieldClass> packetContextFieldClass() const noexcept
1728 const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->libObjPtr());
1731 return ConstStructureFieldClass {libObjPtr};
1734 return nonstd::nullopt;
1737 nonstd::optional<_StructureFieldClass> packetContextFieldClass() noexcept
1739 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1742 return _StructureFieldClass {libObjPtr};
1745 return nonstd::nullopt;
1748 void eventCommonContextFieldClass(const StructureFieldClass& fc)
1750 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1753 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1755 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1756 throw MemoryError {};
1760 nonstd::optional<ConstStructureFieldClass> eventCommonContextFieldClass() const noexcept
1762 const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->libObjPtr());
1765 return ConstStructureFieldClass {libObjPtr};
1768 return nonstd::nullopt;
1771 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() noexcept
1773 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1776 return _StructureFieldClass {libObjPtr};
1779 return nonstd::nullopt;
1782 template <typename LibValT>
1783 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
1785 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1787 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1790 ConstMapValue userAttributes() const noexcept
1792 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1795 UserAttributes userAttributes() noexcept
1797 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1800 Shared shared() const noexcept
1802 return Shared::createWithRef(*this);
1806 using StreamClass = CommonStreamClass<bt_stream_class>;
1807 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1809 namespace internal {
1811 struct StreamClassTypeDescr
1813 using Const = ConstStreamClass;
1814 using NonConst = StreamClass;
1818 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1823 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1827 } /* namespace internal */
1829 template <typename LibObjT>
1830 ConstStreamClass CommonEventClass<LibObjT>::streamClass() const noexcept
1832 return ConstStreamClass {_ConstSpec::streamClass(this->libObjPtr())};
1835 template <typename LibObjT>
1836 typename CommonEventClass<LibObjT>::_StreamClass CommonEventClass<LibObjT>::streamClass() noexcept
1838 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1841 template <typename LibObjT>
1842 ConstStreamClass CommonStream<LibObjT>::cls() const noexcept
1844 return ConstStreamClass {_ConstSpec::cls(this->libObjPtr())};
1847 template <typename LibObjT>
1848 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() noexcept
1850 return Class {_Spec::cls(this->libObjPtr())};
1853 namespace internal {
1855 struct TraceClassRefFuncs final
1857 static void get(const bt_trace_class * const libObjPtr)
1859 bt_trace_class_get_ref(libObjPtr);
1862 static void put(const bt_trace_class * const libObjPtr)
1864 bt_trace_class_put_ref(libObjPtr);
1868 template <typename LibObjT>
1869 struct CommonTraceClassSpec;
1871 /* Functions specific to mutable stream classes */
1873 struct CommonTraceClassSpec<bt_trace_class> final
1875 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1876 const std::uint64_t index) noexcept
1878 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1881 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1882 const std::uint64_t id) noexcept
1884 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1887 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1889 return bt_trace_class_borrow_user_attributes(libObjPtr);
1893 /* Functions specific to constant stream classes */
1895 struct CommonTraceClassSpec<const bt_trace_class> final
1897 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1898 const std::uint64_t index) noexcept
1900 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1903 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1904 const std::uint64_t id) noexcept
1906 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1909 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1911 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1915 } /* namespace internal */
1917 template <typename LibObjT>
1918 class CommonTraceClass final : public internal::BorrowedObj<LibObjT>
1921 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1922 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1923 using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>;
1924 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1925 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1927 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1928 CommonStreamClass<const bt_stream_class>,
1929 CommonStreamClass<bt_stream_class>>::type;
1933 internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1935 using UserAttributes =
1936 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1938 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1942 template <typename OtherLibObjT>
1943 CommonTraceClass(const CommonTraceClass<OtherLibObjT>& traceClass) noexcept :
1944 _ThisBorrowedObj {traceClass}
1948 template <typename OtherLibObjT>
1949 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT>& traceClass) noexcept
1951 _ThisBorrowedObj::operator=(traceClass);
1955 Trace::Shared instantiate(const Trace& trace)
1957 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1959 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1961 internal::validateCreatedObjPtr(libObjPtr);
1962 return Trace::Shared::createWithoutRef(libObjPtr);
1965 StreamClass::Shared createStreamClass()
1967 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1969 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1971 internal::validateCreatedObjPtr(libObjPtr);
1972 return StreamClass::Shared::createWithoutRef(libObjPtr);
1975 StreamClass::Shared createStreamClass(const std::uint64_t id)
1977 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1979 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1981 internal::validateCreatedObjPtr(libObjPtr);
1982 return StreamClass::Shared::createWithoutRef(libObjPtr);
1985 FieldClass::Shared createBoolFieldClass()
1987 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1989 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1991 internal::validateCreatedObjPtr(libObjPtr);
1992 return FieldClass::Shared::createWithoutRef(libObjPtr);
1995 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length)
1997 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1999 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
2001 internal::validateCreatedObjPtr(libObjPtr);
2002 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2005 IntegerFieldClass::Shared createUnsignedIntegerFieldClass()
2007 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2009 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
2011 internal::validateCreatedObjPtr(libObjPtr);
2012 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2015 IntegerFieldClass::Shared createSignedIntegerFieldClass()
2017 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2019 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
2021 internal::validateCreatedObjPtr(libObjPtr);
2022 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2025 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass()
2027 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2029 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
2031 internal::validateCreatedObjPtr(libObjPtr);
2032 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2035 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass()
2037 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2039 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
2041 internal::validateCreatedObjPtr(libObjPtr);
2042 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2045 FieldClass::Shared createSinglePrecisionRealFieldClass()
2047 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2049 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
2051 internal::validateCreatedObjPtr(libObjPtr);
2052 return FieldClass::Shared::createWithoutRef(libObjPtr);
2055 FieldClass::Shared createDoublePrecisionRealFieldClass()
2057 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2059 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
2061 internal::validateCreatedObjPtr(libObjPtr);
2062 return FieldClass::Shared::createWithoutRef(libObjPtr);
2065 FieldClass::Shared createStringFieldClass()
2067 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2069 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
2071 internal::validateCreatedObjPtr(libObjPtr);
2072 return FieldClass::Shared::createWithoutRef(libObjPtr);
2075 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass& elementFieldClass,
2076 const std::uint64_t length)
2078 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2080 const auto libObjPtr = bt_field_class_array_static_create(
2081 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
2083 internal::validateCreatedObjPtr(libObjPtr);
2084 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2087 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass& elementFieldClass)
2089 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2091 const auto libObjPtr = bt_field_class_array_dynamic_create(
2092 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
2094 internal::validateCreatedObjPtr(libObjPtr);
2095 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2098 DynamicArrayWithLengthFieldClass::Shared
2099 createDynamicArrayFieldClass(const FieldClass& elementFieldClass,
2100 const IntegerFieldClass& lengthFieldClass)
2102 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2104 const auto libObjPtr = bt_field_class_array_dynamic_create(
2105 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
2107 internal::validateCreatedObjPtr(libObjPtr);
2108 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
2111 StructureFieldClass::Shared createStructureFieldClass()
2113 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2115 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
2117 internal::validateCreatedObjPtr(libObjPtr);
2118 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
2121 OptionFieldClass::Shared createOptionFieldClass(const FieldClass& optionalFieldClass)
2123 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2125 const auto libObjPtr = bt_field_class_option_without_selector_create(
2126 this->libObjPtr(), optionalFieldClass.libObjPtr());
2128 internal::validateCreatedObjPtr(libObjPtr);
2129 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
2132 OptionWithBoolSelectorFieldClass::Shared
2133 createOptionWithBoolSelectorFieldClass(const FieldClass& optionalFieldClass,
2134 const FieldClass& selectorFieldClass)
2136 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2138 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
2139 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
2141 internal::validateCreatedObjPtr(libObjPtr);
2142 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2145 OptionWithUnsignedIntegerSelectorFieldClass::Shared
2146 createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass& optionalFieldClass,
2147 const IntegerFieldClass& selectorFieldClass,
2148 const ConstUnsignedIntegerRangeSet& ranges)
2150 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2152 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
2153 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2154 ranges.libObjPtr());
2156 internal::validateCreatedObjPtr(libObjPtr);
2157 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2160 OptionWithSignedIntegerSelectorFieldClass::Shared
2161 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass& optionalFieldClass,
2162 const IntegerFieldClass& selectorFieldClass,
2163 const ConstSignedIntegerRangeSet& ranges)
2165 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2167 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
2168 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2169 ranges.libObjPtr());
2171 internal::validateCreatedObjPtr(libObjPtr);
2172 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2175 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass()
2177 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2179 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
2181 internal::validateCreatedObjPtr(libObjPtr);
2182 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2185 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2186 createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
2188 return VariantWithUnsignedIntegerSelectorFieldClass {
2189 this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}
2193 VariantWithSignedIntegerSelectorFieldClass::Shared
2194 createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
2196 return VariantWithSignedIntegerSelectorFieldClass {
2197 this->_createVariantWithIntegerSelectorFieldClass(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);
2277 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
2279 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2281 const auto libObjPtr =
2282 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2284 internal::validateCreatedObjPtr(libObjPtr);
2289 using TraceClass = CommonTraceClass<bt_trace_class>;
2290 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2292 namespace internal {
2294 struct TraceClassTypeDescr
2296 using Const = ConstTraceClass;
2297 using NonConst = TraceClass;
2301 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2306 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2310 } /* namespace internal */
2312 template <typename LibObjT>
2313 ConstTraceClass CommonStreamClass<LibObjT>::traceClass() const noexcept
2315 return ConstTraceClass {_ConstSpec::traceClass(this->libObjPtr())};
2318 template <typename LibObjT>
2319 typename CommonStreamClass<LibObjT>::_TraceClass CommonStreamClass<LibObjT>::traceClass() noexcept
2321 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2324 template <typename LibObjT>
2325 ConstTraceClass CommonTrace<LibObjT>::cls() const noexcept
2327 return ConstTraceClass {_ConstSpec::cls(this->libObjPtr())};
2330 template <typename LibObjT>
2331 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() noexcept
2333 return Class {_Spec::cls(this->libObjPtr())};
2336 } /* namespace bt2 */
2338 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */