2 * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
11 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "cpp-common/optional.hpp"
16 #include "cpp-common/string_view.hpp"
18 #include "borrowed-obj.hpp"
19 #include "clock-class.hpp"
20 #include "field-class.hpp"
22 #include "internal/utils.hpp"
27 template <typename LibObjT>
30 template <typename LibObjT>
33 template <typename LibObjT>
36 template <typename LibObjT>
39 template <typename LibObjT>
40 class CommonEventClass;
42 template <typename LibObjT>
43 class CommonStreamClass;
45 template <typename LibObjT>
46 class CommonTraceClass;
50 template <typename LibObjT>
51 struct CommonEventSpec;
53 /* Functions specific to mutable events */
55 struct CommonEventSpec<bt_event> final
57 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
59 return bt_event_borrow_class(libObjPtr);
62 static bt_stream *stream(bt_event * const libObjPtr) noexcept
64 return bt_event_borrow_stream(libObjPtr);
67 static bt_packet *packet(bt_event * const libObjPtr) noexcept
69 return bt_event_borrow_packet(libObjPtr);
72 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
74 return bt_event_borrow_payload_field(libObjPtr);
77 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
79 return bt_event_borrow_specific_context_field(libObjPtr);
82 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
84 return bt_event_borrow_common_context_field(libObjPtr);
88 /* Functions specific to constant events */
90 struct CommonEventSpec<const bt_event> final
92 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
94 return bt_event_borrow_class_const(libObjPtr);
97 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
99 return bt_event_borrow_stream_const(libObjPtr);
102 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
104 return bt_event_borrow_packet_const(libObjPtr);
107 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
109 return bt_event_borrow_payload_field_const(libObjPtr);
112 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
114 return bt_event_borrow_specific_context_field_const(libObjPtr);
117 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
119 return bt_event_borrow_common_context_field_const(libObjPtr);
123 } /* namespace internal */
125 template <typename LibObjT>
126 class CommonEvent final : public BorrowedObj<LibObjT>
129 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
130 using typename BorrowedObj<LibObjT>::_LibObjPtr;
131 using _ConstSpec = internal::CommonEventSpec<const bt_event>;
132 using _Spec = internal::CommonEventSpec<LibObjT>;
135 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
136 CommonPacket<bt_packet>>::type;
139 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
140 CommonStream<bt_stream>>::type;
142 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
143 ConstStructureField, StructureField>::type;
146 using Class = typename std::conditional<std::is_const<LibObjT>::value,
147 CommonEventClass<const bt_event_class>,
148 CommonEventClass<bt_event_class>>::type;
150 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
154 template <typename OtherLibObjT>
155 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObj {event}
159 template <typename OtherLibObjT>
160 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
162 _ThisBorrowedObj::operator=(event);
166 CommonEventClass<const bt_event_class> cls() const noexcept;
167 Class cls() noexcept;
168 CommonStream<const bt_stream> stream() const noexcept;
169 _Stream stream() noexcept;
170 nonstd::optional<CommonPacket<const bt_packet>> packet() const noexcept;
171 nonstd::optional<_Packet> packet() noexcept;
173 nonstd::optional<ConstStructureField> payloadField() const noexcept
175 const auto libObjPtr = _ConstSpec::payloadField(this->libObjPtr());
178 return ConstStructureField {libObjPtr};
181 return nonstd::nullopt;
184 nonstd::optional<_StructureField> payloadField() noexcept
186 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
189 return _StructureField {libObjPtr};
192 return nonstd::nullopt;
195 nonstd::optional<ConstStructureField> specificContextField() const noexcept
197 const auto libObjPtr = _ConstSpec::specificContextField(this->libObjPtr());
200 return ConstStructureField {libObjPtr};
203 return nonstd::nullopt;
206 nonstd::optional<_StructureField> specificContextField() noexcept
208 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
211 return _StructureField {libObjPtr};
214 return nonstd::nullopt;
217 nonstd::optional<ConstStructureField> commonContextField() const noexcept
219 const auto libObjPtr = _ConstSpec::commonContextField(this->libObjPtr());
222 return ConstStructureField {libObjPtr};
225 return nonstd::nullopt;
228 nonstd::optional<_StructureField> commonContextField() noexcept
230 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
233 return _StructureField {libObjPtr};
236 return nonstd::nullopt;
240 using Event = CommonEvent<bt_event>;
241 using ConstEvent = CommonEvent<const bt_event>;
245 struct EventTypeDescr
247 using Const = ConstEvent;
248 using NonConst = Event;
252 struct TypeDescr<Event> : public EventTypeDescr
257 struct TypeDescr<ConstEvent> : public EventTypeDescr
261 struct PacketRefFuncs final
263 static void get(const bt_packet * const libObjPtr)
265 bt_packet_get_ref(libObjPtr);
268 static void put(const bt_packet * const libObjPtr)
270 bt_packet_put_ref(libObjPtr);
274 template <typename LibObjT>
275 struct CommonPacketSpec;
277 /* Functions specific to mutable packets */
279 struct CommonPacketSpec<bt_packet> final
281 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
283 return bt_packet_borrow_stream(libObjPtr);
286 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
288 return bt_packet_borrow_context_field(libObjPtr);
292 /* Functions specific to constant packets */
294 struct CommonPacketSpec<const bt_packet> final
296 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
298 return bt_packet_borrow_stream_const(libObjPtr);
301 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
303 return bt_packet_borrow_context_field_const(libObjPtr);
307 } /* namespace internal */
309 template <typename LibObjT>
310 class CommonPacket final : public BorrowedObj<LibObjT>
313 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
314 using typename BorrowedObj<LibObjT>::_LibObjPtr;
315 using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
316 using _Spec = internal::CommonPacketSpec<LibObjT>;
317 using _ThisCommonPacket = CommonPacket<LibObjT>;
320 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
321 CommonStream<bt_stream>>::type;
323 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
324 ConstStructureField, StructureField>::type;
327 using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
329 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
333 template <typename OtherLibObjT>
334 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObj {packet}
338 template <typename OtherLibObjT>
339 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
341 _ThisBorrowedObj::operator=(packet);
345 CommonStream<const bt_stream> stream() const noexcept;
346 _Stream stream() noexcept;
348 nonstd::optional<ConstStructureField> contextField() const noexcept
350 const auto libObjPtr = _ConstSpec::contextField(this->libObjPtr());
353 return ConstStructureField {libObjPtr};
356 return nonstd::nullopt;
359 nonstd::optional<_StructureField> contextField() noexcept
361 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
364 return _StructureField {libObjPtr};
367 return nonstd::nullopt;
370 Shared shared() const noexcept
372 return Shared::createWithRef(*this);
376 using Packet = CommonPacket<bt_packet>;
377 using ConstPacket = CommonPacket<const bt_packet>;
381 struct PacketTypeDescr
383 using Const = ConstPacket;
384 using NonConst = Packet;
388 struct TypeDescr<Packet> : public PacketTypeDescr
393 struct TypeDescr<ConstPacket> : public PacketTypeDescr
397 } /* namespace internal */
399 template <typename LibObjT>
400 nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
402 const auto libObjPtr = _ConstSpec::packet(this->libObjPtr());
405 return ConstPacket {libObjPtr};
408 return nonstd::nullopt;
411 template <typename LibObjT>
412 nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept
414 const auto libObjPtr = _Spec::packet(this->libObjPtr());
417 return _Packet {libObjPtr};
420 return nonstd::nullopt;
425 struct StreamRefFuncs final
427 static void get(const bt_stream * const libObjPtr)
429 bt_stream_get_ref(libObjPtr);
432 static void put(const bt_stream * const libObjPtr)
434 bt_stream_put_ref(libObjPtr);
438 template <typename LibObjT>
439 struct CommonStreamSpec;
441 /* Functions specific to mutable streams */
443 struct CommonStreamSpec<bt_stream> final
445 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
447 return bt_stream_borrow_class(libObjPtr);
450 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
452 return bt_stream_borrow_trace(libObjPtr);
455 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
457 return bt_stream_borrow_user_attributes(libObjPtr);
461 /* Functions specific to constant streams */
463 struct CommonStreamSpec<const bt_stream> final
465 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
467 return bt_stream_borrow_class_const(libObjPtr);
470 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
472 return bt_stream_borrow_trace_const(libObjPtr);
475 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
477 return bt_stream_borrow_user_attributes_const(libObjPtr);
481 } /* namespace internal */
483 template <typename LibObjT>
484 class CommonStream final : public BorrowedObj<LibObjT>
487 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
488 using typename BorrowedObj<LibObjT>::_LibObjPtr;
489 using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
490 using _Spec = internal::CommonStreamSpec<LibObjT>;
491 using _ThisCommonStream = CommonStream<LibObjT>;
494 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
495 CommonTrace<bt_trace>>::type;
498 using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
500 using Class = typename std::conditional<std::is_const<LibObjT>::value,
501 CommonStreamClass<const bt_stream_class>,
502 CommonStreamClass<bt_stream_class>>::type;
504 using UserAttributes =
505 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
507 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
511 template <typename OtherLibObjT>
512 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObj {stream}
516 template <typename OtherLibObjT>
517 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
519 _ThisBorrowedObj::operator=(stream);
523 Packet::Shared createPacket()
525 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
527 const auto libObjPtr = bt_packet_create(this->libObjPtr());
529 internal::validateCreatedObjPtr(libObjPtr);
530 return Packet::Shared::createWithoutRef(libObjPtr);
533 CommonStreamClass<const bt_stream_class> cls() const noexcept;
534 Class cls() noexcept;
535 CommonTrace<const bt_trace> trace() const noexcept;
536 _Trace trace() noexcept;
538 std::uint64_t id() const noexcept
540 return bt_stream_get_id(this->libObjPtr());
543 void name(const char * const name)
545 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
547 const auto status = bt_stream_set_name(this->libObjPtr(), name);
549 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
550 throw MemoryError {};
554 void name(const std::string& name)
556 this->name(name.data());
559 nonstd::optional<bpstd::string_view> name() const noexcept
561 const auto name = bt_stream_get_name(this->libObjPtr());
567 return nonstd::nullopt;
570 template <typename LibValT>
571 void userAttributes(const CommonMapValue<LibValT> userAttrs)
573 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
575 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
578 ConstMapValue userAttributes() const noexcept
580 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
583 UserAttributes userAttributes() noexcept
585 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
588 Shared shared() const noexcept
590 return Shared::createWithRef(*this);
594 using Stream = CommonStream<bt_stream>;
595 using ConstStream = CommonStream<const bt_stream>;
599 struct StreamTypeDescr
601 using Const = ConstStream;
602 using NonConst = Stream;
606 struct TypeDescr<Stream> : public StreamTypeDescr
611 struct TypeDescr<ConstStream> : public StreamTypeDescr
615 } /* namespace internal */
617 template <typename LibObjT>
618 ConstStream CommonEvent<LibObjT>::stream() const noexcept
620 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
623 template <typename LibObjT>
624 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept
626 return _Stream {_Spec::stream(this->libObjPtr())};
629 template <typename LibObjT>
630 ConstStream CommonPacket<LibObjT>::stream() const noexcept
632 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
635 template <typename LibObjT>
636 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept
638 return _Stream {_Spec::stream(this->libObjPtr())};
643 struct TraceRefFuncs final
645 static void get(const bt_trace * const libObjPtr)
647 bt_trace_get_ref(libObjPtr);
650 static void put(const bt_trace * const libObjPtr)
652 bt_trace_put_ref(libObjPtr);
656 template <typename LibObjT>
657 struct CommonTraceSpec;
659 /* Functions specific to mutable traces */
661 struct CommonTraceSpec<bt_trace> final
663 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
665 return bt_trace_borrow_class(libObjPtr);
668 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
670 return bt_trace_borrow_stream_by_index(libObjPtr, index);
673 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
675 return bt_trace_borrow_stream_by_id(libObjPtr, id);
678 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
680 return bt_trace_borrow_user_attributes(libObjPtr);
684 /* Functions specific to constant traces */
686 struct CommonTraceSpec<const bt_trace> final
688 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
690 return bt_trace_borrow_class_const(libObjPtr);
693 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
694 const std::uint64_t index) noexcept
696 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
699 static const bt_stream *streamById(const bt_trace * const libObjPtr,
700 const std::uint64_t id) noexcept
702 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
705 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
707 return bt_trace_borrow_user_attributes_const(libObjPtr);
711 } /* namespace internal */
713 template <typename LibObjT>
714 class CommonTrace final : public BorrowedObj<LibObjT>
716 /* Allow instantiate() to call `trace.libObjPtr()` */
717 friend class CommonStreamClass<bt_stream_class>;
720 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
721 using typename BorrowedObj<LibObjT>::_LibObjPtr;
722 using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
723 using _Spec = internal::CommonTraceSpec<LibObjT>;
724 using _ThisCommonTrace = CommonTrace<LibObjT>;
727 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
728 CommonStream<bt_stream>>::type;
731 using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
733 using Class = typename std::conditional<std::is_const<LibObjT>::value,
734 CommonTraceClass<const bt_trace_class>,
735 CommonTraceClass<bt_trace_class>>::type;
737 using UserAttributes =
738 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
740 struct ConstEnvironmentEntry
742 bpstd::string_view name;
746 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
750 template <typename OtherLibObjT>
751 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObj {trace}
755 template <typename OtherLibObjT>
756 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
758 _ThisBorrowedObj::operator=(trace);
762 CommonTraceClass<const bt_trace_class> cls() const noexcept;
763 Class cls() noexcept;
765 void name(const char * const name)
767 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
769 const auto status = bt_trace_set_name(this->libObjPtr(), name);
771 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
772 throw MemoryError {};
776 void name(const std::string& name)
778 this->name(name.data());
781 nonstd::optional<bpstd::string_view> name() const noexcept
783 const auto name = bt_trace_get_name(this->libObjPtr());
789 return nonstd::nullopt;
792 void uuid(const bt2_common::UuidView& uuid) noexcept
794 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
797 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
799 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
802 return bt2_common::UuidView {uuid};
805 return nonstd::nullopt;
808 std::uint64_t size() const noexcept
810 return bt_trace_get_stream_count(this->libObjPtr());
813 ConstStream operator[](const std::uint64_t index) const noexcept
815 return ConstStream {_ConstSpec::streamByIndex(this->libObjPtr(), index)};
818 _Stream operator[](const std::uint64_t index) noexcept
820 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
823 nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept
825 const auto libObjPtr = _ConstSpec::streamById(this->libObjPtr(), id);
828 return ConstStream {libObjPtr};
831 return nonstd::nullopt;
834 nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept
836 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
839 return _Stream {libObjPtr};
842 return nonstd::nullopt;
845 void environmentEntry(const char * const name, const std::int64_t val)
847 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
849 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
851 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
852 throw MemoryError {};
856 void environmentEntry(const std::string& name, const std::int64_t val)
858 this->environmentEntry(name.data(), val);
861 void environmentEntry(const char * const name, const char * const val)
863 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
865 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
867 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
868 throw MemoryError {};
872 void environmentEntry(const std::string& name, const char * const val)
874 this->environmentEntry(name.data(), val);
877 void environmentEntry(const char * const name, const std::string& val)
879 this->environmentEntry(name, val.data());
882 void environmentEntry(const std::string& name, const std::string& val)
884 this->environmentEntry(name.data(), val.data());
887 std::uint64_t environmentSize() const noexcept
889 return bt_trace_get_environment_entry_count(this->libObjPtr());
892 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
895 const bt_value *libObjPtr;
897 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
899 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
902 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
904 const auto libObjPtr =
905 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
908 return ConstValue {libObjPtr};
911 return nonstd::nullopt;
914 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
916 return this->environmentEntry(name.data());
919 template <typename LibValT>
920 void userAttributes(const CommonMapValue<LibValT> userAttrs)
922 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
924 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
927 ConstMapValue userAttributes() const noexcept
929 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
932 UserAttributes userAttributes() noexcept
934 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
937 Shared shared() const noexcept
939 return Shared::createWithRef(*this);
943 using Trace = CommonTrace<bt_trace>;
944 using ConstTrace = CommonTrace<const bt_trace>;
948 struct TraceTypeDescr
950 using Const = ConstTrace;
951 using NonConst = Trace;
955 struct TypeDescr<Trace> : public TraceTypeDescr
960 struct TypeDescr<ConstTrace> : public TraceTypeDescr
964 } /* namespace internal */
966 template <typename LibObjT>
967 ConstTrace CommonStream<LibObjT>::trace() const noexcept
969 return ConstTrace {_ConstSpec::trace(this->libObjPtr())};
972 template <typename LibObjT>
973 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept
975 return _Trace {_Spec::trace(this->libObjPtr())};
980 struct EventClassRefFuncs final
982 static void get(const bt_event_class * const libObjPtr)
984 bt_event_class_get_ref(libObjPtr);
987 static void put(const bt_event_class * const libObjPtr)
989 bt_event_class_put_ref(libObjPtr);
993 template <typename LibObjT>
994 struct CommonEventClassSpec;
996 /* Functions specific to mutable event classes */
998 struct CommonEventClassSpec<bt_event_class> final
1000 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
1002 return bt_event_class_borrow_stream_class(libObjPtr);
1005 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
1007 return bt_event_class_borrow_payload_field_class(libObjPtr);
1010 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
1012 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
1015 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
1017 return bt_event_class_borrow_user_attributes(libObjPtr);
1021 /* Functions specific to constant event classes */
1023 struct CommonEventClassSpec<const bt_event_class> final
1025 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
1027 return bt_event_class_borrow_stream_class_const(libObjPtr);
1030 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
1032 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
1035 static const bt_field_class *
1036 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
1038 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
1041 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
1043 return bt_event_class_borrow_user_attributes_const(libObjPtr);
1047 } /* namespace internal */
1049 template <typename LibObjT>
1050 class CommonEventClass final : public BorrowedObj<LibObjT>
1053 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
1054 using typename BorrowedObj<LibObjT>::_LibObjPtr;
1055 using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
1056 using _Spec = internal::CommonEventClassSpec<LibObjT>;
1057 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
1059 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1060 CommonStreamClass<const bt_stream_class>,
1061 CommonStreamClass<bt_stream_class>>::type;
1063 using _StructureFieldClass =
1064 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1065 StructureFieldClass>::type;
1069 internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
1071 using UserAttributes =
1072 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1076 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
1077 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
1078 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
1079 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
1080 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
1081 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
1082 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
1083 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
1084 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
1085 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
1086 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
1087 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
1088 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
1089 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
1090 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
1093 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1097 template <typename OtherLibObjT>
1098 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
1099 _ThisBorrowedObj {eventClass}
1103 template <typename OtherLibObjT>
1104 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
1106 _ThisBorrowedObj::operator=(eventClass);
1110 CommonStreamClass<const bt_stream_class> streamClass() const noexcept;
1111 _StreamClass streamClass() noexcept;
1113 std::uint64_t id() const noexcept
1115 return bt_event_class_get_id(this->libObjPtr());
1118 void name(const char * const name)
1120 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1122 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1124 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1125 throw MemoryError {};
1129 void name(const std::string& name)
1131 this->name(name.data());
1134 nonstd::optional<bpstd::string_view> name() const noexcept
1136 const auto name = bt_event_class_get_name(this->libObjPtr());
1142 return nonstd::nullopt;
1145 void logLevel(const LogLevel logLevel) noexcept
1147 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1149 bt_event_class_set_log_level(this->libObjPtr(),
1150 static_cast<bt_event_class_log_level>(logLevel));
1153 nonstd::optional<LogLevel> logLevel() const noexcept
1155 bt_event_class_log_level libLogLevel;
1156 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1158 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1159 return static_cast<LogLevel>(libLogLevel);
1162 return nonstd::nullopt;
1165 void emfUri(const char * const emfUri)
1167 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1169 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1171 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1172 throw MemoryError {};
1176 void emfUri(const std::string& emfUri)
1178 this->emfUri(emfUri.data());
1181 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1183 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1189 return nonstd::nullopt;
1192 void payloadFieldClass(const StructureFieldClass fc)
1194 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1197 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1199 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1200 throw MemoryError {};
1204 nonstd::optional<ConstStructureFieldClass> payloadFieldClass() const noexcept
1206 const auto libObjPtr = _ConstSpec::payloadFieldClass(this->libObjPtr());
1209 return ConstStructureFieldClass {libObjPtr};
1212 return nonstd::nullopt;
1215 nonstd::optional<_StructureFieldClass> payloadFieldClass() noexcept
1217 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1220 return _StructureFieldClass {libObjPtr};
1223 return nonstd::nullopt;
1226 void specificContextFieldClass(const StructureFieldClass fc)
1228 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1231 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1233 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1234 throw MemoryError {};
1238 nonstd::optional<ConstStructureFieldClass> specificContextFieldClass() const noexcept
1240 const auto libObjPtr = _ConstSpec::specificContextFieldClass(this->libObjPtr());
1243 return ConstStructureFieldClass {libObjPtr};
1246 return nonstd::nullopt;
1249 nonstd::optional<_StructureFieldClass> specificContextFieldClass() noexcept
1251 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1254 return _StructureFieldClass {libObjPtr};
1257 return nonstd::nullopt;
1260 template <typename LibValT>
1261 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1263 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1265 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1268 ConstMapValue userAttributes() const noexcept
1270 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1273 UserAttributes userAttributes() noexcept
1275 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1278 Shared shared() const noexcept
1280 return Shared::createWithRef(*this);
1284 using EventClass = CommonEventClass<bt_event_class>;
1285 using ConstEventClass = CommonEventClass<const bt_event_class>;
1287 namespace internal {
1289 struct EventClassTypeDescr
1291 using Const = ConstEventClass;
1292 using NonConst = EventClass;
1296 struct TypeDescr<EventClass> : public EventClassTypeDescr
1301 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1305 } /* namespace internal */
1307 template <typename LibObjT>
1308 ConstEventClass CommonEvent<LibObjT>::cls() const noexcept
1310 return ConstEventClass {_ConstSpec::cls(this->libObjPtr())};
1313 template <typename LibObjT>
1314 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() noexcept
1316 return Class {_Spec::cls(this->libObjPtr())};
1319 namespace internal {
1321 struct StreamClassRefFuncs final
1323 static void get(const bt_stream_class * const libObjPtr)
1325 bt_stream_class_get_ref(libObjPtr);
1328 static void put(const bt_stream_class * const libObjPtr)
1330 bt_stream_class_put_ref(libObjPtr);
1334 template <typename LibObjT>
1335 struct CommonStreamClassSpec;
1337 /* Functions specific to mutable stream classes */
1339 struct CommonStreamClassSpec<bt_stream_class> final
1341 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1343 return bt_stream_class_borrow_trace_class(libObjPtr);
1346 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1347 const std::uint64_t index) noexcept
1349 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1352 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1353 const std::uint64_t id) noexcept
1355 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1358 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1360 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1363 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1365 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1368 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1370 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1373 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1375 return bt_stream_class_borrow_user_attributes(libObjPtr);
1379 /* Functions specific to constant stream classes */
1381 struct CommonStreamClassSpec<const bt_stream_class> final
1383 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1385 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1388 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1389 const std::uint64_t index) noexcept
1391 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1394 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1395 const std::uint64_t id) noexcept
1397 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1400 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1402 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1405 static const bt_field_class *
1406 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1408 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1411 static const bt_field_class *
1412 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1414 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1417 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1419 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1423 } /* namespace internal */
1425 template <typename LibObjT>
1426 class CommonStreamClass final : public BorrowedObj<LibObjT>
1429 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
1430 using typename BorrowedObj<LibObjT>::_LibObjPtr;
1431 using _ConstSpec = internal::CommonStreamClassSpec<const bt_stream_class>;
1432 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1433 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1435 using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
1436 CommonTraceClass<const bt_trace_class>,
1437 CommonTraceClass<bt_trace_class>>::type;
1439 using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
1440 CommonEventClass<const bt_event_class>,
1441 CommonEventClass<bt_event_class>>::type;
1443 using _StructureFieldClass =
1444 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1445 StructureFieldClass>::type;
1448 typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
1452 internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1454 using UserAttributes =
1455 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1457 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1461 template <typename OtherLibObjT>
1462 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1463 _ThisBorrowedObj {streamClass}
1467 template <typename OtherLibObjT>
1468 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1470 _ThisBorrowedObj::operator=(streamClass);
1474 Stream::Shared instantiate(const Trace trace)
1476 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1478 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1480 internal::validateCreatedObjPtr(libObjPtr);
1481 return Stream::Shared::createWithoutRef(libObjPtr);
1484 Stream::Shared instantiate(const Trace trace, const std::uint64_t id)
1486 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1488 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1490 internal::validateCreatedObjPtr(libObjPtr);
1491 return Stream::Shared::createWithoutRef(libObjPtr);
1494 EventClass::Shared createEventClass()
1496 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1498 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1500 internal::validateCreatedObjPtr(libObjPtr);
1501 return EventClass::Shared::createWithoutRef(libObjPtr);
1504 EventClass::Shared createEventClass(const std::uint64_t id)
1506 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1508 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1510 internal::validateCreatedObjPtr(libObjPtr);
1511 return EventClass::Shared::createWithoutRef(libObjPtr);
1514 CommonTraceClass<const bt_trace_class> traceClass() const noexcept;
1515 _TraceClass traceClass() noexcept;
1517 std::uint64_t id() const noexcept
1519 return bt_stream_class_get_id(this->libObjPtr());
1522 void name(const char * const name)
1524 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1526 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1528 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1529 throw MemoryError {};
1533 void name(const std::string& name)
1535 this->name(name.data());
1538 nonstd::optional<bpstd::string_view> name() const noexcept
1540 const auto name = bt_stream_class_get_name(this->libObjPtr());
1546 return nonstd::nullopt;
1549 void assignsAutomaticEventClassId(const bool val) noexcept
1551 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1553 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1554 static_cast<bt_bool>(val));
1557 bool assignsAutomaticEventClassId() const noexcept
1559 return static_cast<bool>(
1560 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1563 void assignsAutomaticStreamId(const bool val) noexcept
1565 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1567 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1568 static_cast<bt_bool>(val));
1571 bool assignsAutomaticStreamId() const noexcept
1573 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1576 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1577 const bool withEndDefaultClkSnapshot) noexcept
1579 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1581 bt_stream_class_set_supports_packets(this->libObjPtr(),
1582 static_cast<bt_bool>(supportsPackets),
1583 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1584 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1587 bool supportsPackets() const noexcept
1589 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1592 bool packetsHaveBeginningClockSnapshot() const noexcept
1594 return static_cast<bool>(
1595 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1598 bool packetsHaveEndClockSnapshot() const noexcept
1600 return static_cast<bool>(
1601 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1604 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1605 const bool withDefaultClkSnapshots) noexcept
1607 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1609 bt_stream_class_set_supports_discarded_events(
1610 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1611 static_cast<bt_bool>(withDefaultClkSnapshots));
1614 bool supportsDiscardedEvents() const noexcept
1616 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1619 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1621 return static_cast<bool>(
1622 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1625 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1626 const bool withDefaultClkSnapshots) noexcept
1628 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1630 bt_stream_class_set_supports_discarded_packets(
1631 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1632 static_cast<bt_bool>(withDefaultClkSnapshots));
1635 bool supportsDiscardedPackets() const noexcept
1637 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1640 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1642 return static_cast<bool>(
1643 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1646 void defaultClockClass(const ClockClass clkCls)
1648 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1651 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1653 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1656 nonstd::optional<ConstClockClass> defaultClockClass() const noexcept
1658 const auto libObjPtr = _ConstSpec::defaultClockClass(this->libObjPtr());
1661 return ConstClockClass {libObjPtr};
1664 return nonstd::nullopt;
1667 nonstd::optional<_ClockClass> defaultClockClass() noexcept
1669 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1672 return _ClockClass {libObjPtr};
1675 return nonstd::nullopt;
1678 std::uint64_t size() const noexcept
1680 return bt_stream_class_get_event_class_count(this->libObjPtr());
1683 ConstEventClass operator[](const std::uint64_t index) const noexcept
1685 return ConstEventClass {_ConstSpec::eventClassByIndex(this->libObjPtr(), index)};
1688 _EventClass operator[](const std::uint64_t index) noexcept
1690 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1693 nonstd::optional<ConstEventClass> eventClassById(const std::uint64_t id) const noexcept
1695 const auto libObjPtr = _ConstSpec::eventClassById(this->libObjPtr(), id);
1698 return ConstEventClass {libObjPtr};
1701 return nonstd::nullopt;
1704 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) noexcept
1706 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1709 return _EventClass {libObjPtr};
1712 return nonstd::nullopt;
1715 void packetContextFieldClass(const StructureFieldClass fc)
1717 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1720 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1722 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1723 throw MemoryError {};
1727 nonstd::optional<ConstStructureFieldClass> packetContextFieldClass() const noexcept
1729 const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->libObjPtr());
1732 return ConstStructureFieldClass {libObjPtr};
1735 return nonstd::nullopt;
1738 nonstd::optional<_StructureFieldClass> packetContextFieldClass() noexcept
1740 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1743 return _StructureFieldClass {libObjPtr};
1746 return nonstd::nullopt;
1749 void eventCommonContextFieldClass(const StructureFieldClass fc)
1751 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1754 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1756 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1757 throw MemoryError {};
1761 nonstd::optional<ConstStructureFieldClass> eventCommonContextFieldClass() const noexcept
1763 const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->libObjPtr());
1766 return ConstStructureFieldClass {libObjPtr};
1769 return nonstd::nullopt;
1772 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() noexcept
1774 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1777 return _StructureFieldClass {libObjPtr};
1780 return nonstd::nullopt;
1783 template <typename LibValT>
1784 void userAttributes(const CommonMapValue<LibValT> userAttrs)
1786 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1788 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1791 ConstMapValue userAttributes() const noexcept
1793 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
1796 UserAttributes userAttributes() noexcept
1798 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1801 Shared shared() const noexcept
1803 return Shared::createWithRef(*this);
1807 using StreamClass = CommonStreamClass<bt_stream_class>;
1808 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1810 namespace internal {
1812 struct StreamClassTypeDescr
1814 using Const = ConstStreamClass;
1815 using NonConst = StreamClass;
1819 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1824 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1828 } /* namespace internal */
1830 template <typename LibObjT>
1831 ConstStreamClass CommonEventClass<LibObjT>::streamClass() const noexcept
1833 return ConstStreamClass {_ConstSpec::streamClass(this->libObjPtr())};
1836 template <typename LibObjT>
1837 typename CommonEventClass<LibObjT>::_StreamClass CommonEventClass<LibObjT>::streamClass() noexcept
1839 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1842 template <typename LibObjT>
1843 ConstStreamClass CommonStream<LibObjT>::cls() const noexcept
1845 return ConstStreamClass {_ConstSpec::cls(this->libObjPtr())};
1848 template <typename LibObjT>
1849 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() noexcept
1851 return Class {_Spec::cls(this->libObjPtr())};
1854 namespace internal {
1856 struct TraceClassRefFuncs final
1858 static void get(const bt_trace_class * const libObjPtr)
1860 bt_trace_class_get_ref(libObjPtr);
1863 static void put(const bt_trace_class * const libObjPtr)
1865 bt_trace_class_put_ref(libObjPtr);
1869 template <typename LibObjT>
1870 struct CommonTraceClassSpec;
1872 /* Functions specific to mutable stream classes */
1874 struct CommonTraceClassSpec<bt_trace_class> final
1876 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1877 const std::uint64_t index) noexcept
1879 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1882 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1883 const std::uint64_t id) noexcept
1885 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1888 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1890 return bt_trace_class_borrow_user_attributes(libObjPtr);
1894 /* Functions specific to constant stream classes */
1896 struct CommonTraceClassSpec<const bt_trace_class> final
1898 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1899 const std::uint64_t index) noexcept
1901 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1904 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1905 const std::uint64_t id) noexcept
1907 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1910 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1912 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1916 } /* namespace internal */
1918 template <typename LibObjT>
1919 class CommonTraceClass final : public BorrowedObj<LibObjT>
1922 using typename BorrowedObj<LibObjT>::_ThisBorrowedObj;
1923 using typename BorrowedObj<LibObjT>::_LibObjPtr;
1924 using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>;
1925 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1926 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1928 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1929 CommonStreamClass<const bt_stream_class>,
1930 CommonStreamClass<bt_stream_class>>::type;
1934 internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1936 using UserAttributes =
1937 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1939 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1943 template <typename OtherLibObjT>
1944 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1945 _ThisBorrowedObj {traceClass}
1949 template <typename OtherLibObjT>
1950 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1952 _ThisBorrowedObj::operator=(traceClass);
1956 Trace::Shared instantiate()
1958 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1960 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1962 internal::validateCreatedObjPtr(libObjPtr);
1963 return Trace::Shared::createWithoutRef(libObjPtr);
1966 StreamClass::Shared createStreamClass()
1968 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1970 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1972 internal::validateCreatedObjPtr(libObjPtr);
1973 return StreamClass::Shared::createWithoutRef(libObjPtr);
1976 StreamClass::Shared createStreamClass(const std::uint64_t id)
1978 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1980 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1982 internal::validateCreatedObjPtr(libObjPtr);
1983 return StreamClass::Shared::createWithoutRef(libObjPtr);
1986 FieldClass::Shared createBoolFieldClass()
1988 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1990 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1992 internal::validateCreatedObjPtr(libObjPtr);
1993 return FieldClass::Shared::createWithoutRef(libObjPtr);
1996 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length)
1998 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2000 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
2002 internal::validateCreatedObjPtr(libObjPtr);
2003 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2006 IntegerFieldClass::Shared createUnsignedIntegerFieldClass()
2008 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2010 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
2012 internal::validateCreatedObjPtr(libObjPtr);
2013 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2016 IntegerFieldClass::Shared createSignedIntegerFieldClass()
2018 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2020 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
2022 internal::validateCreatedObjPtr(libObjPtr);
2023 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2026 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass()
2028 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2030 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
2032 internal::validateCreatedObjPtr(libObjPtr);
2033 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2036 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass()
2038 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2040 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
2042 internal::validateCreatedObjPtr(libObjPtr);
2043 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2046 FieldClass::Shared createSinglePrecisionRealFieldClass()
2048 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2050 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
2052 internal::validateCreatedObjPtr(libObjPtr);
2053 return FieldClass::Shared::createWithoutRef(libObjPtr);
2056 FieldClass::Shared createDoublePrecisionRealFieldClass()
2058 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2060 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
2062 internal::validateCreatedObjPtr(libObjPtr);
2063 return FieldClass::Shared::createWithoutRef(libObjPtr);
2066 FieldClass::Shared createStringFieldClass()
2068 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2070 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
2072 internal::validateCreatedObjPtr(libObjPtr);
2073 return FieldClass::Shared::createWithoutRef(libObjPtr);
2076 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
2077 const std::uint64_t length)
2079 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2081 const auto libObjPtr = bt_field_class_array_static_create(
2082 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
2084 internal::validateCreatedObjPtr(libObjPtr);
2085 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2088 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass)
2090 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2092 const auto libObjPtr = bt_field_class_array_dynamic_create(
2093 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
2095 internal::validateCreatedObjPtr(libObjPtr);
2096 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2099 DynamicArrayWithLengthFieldClass::Shared
2100 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
2101 const IntegerFieldClass lengthFieldClass)
2103 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2105 const auto libObjPtr = bt_field_class_array_dynamic_create(
2106 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
2108 internal::validateCreatedObjPtr(libObjPtr);
2109 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
2112 StructureFieldClass::Shared createStructureFieldClass()
2114 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2116 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
2118 internal::validateCreatedObjPtr(libObjPtr);
2119 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
2122 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass)
2124 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2126 const auto libObjPtr = bt_field_class_option_without_selector_create(
2127 this->libObjPtr(), optionalFieldClass.libObjPtr());
2129 internal::validateCreatedObjPtr(libObjPtr);
2130 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
2133 OptionWithBoolSelectorFieldClass::Shared
2134 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
2135 const FieldClass selectorFieldClass)
2137 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2139 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
2140 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
2142 internal::validateCreatedObjPtr(libObjPtr);
2143 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2146 OptionWithUnsignedIntegerSelectorFieldClass::Shared
2147 createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2148 const IntegerFieldClass selectorFieldClass,
2149 const ConstUnsignedIntegerRangeSet ranges)
2151 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2153 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
2154 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2155 ranges.libObjPtr());
2157 internal::validateCreatedObjPtr(libObjPtr);
2158 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2161 OptionWithSignedIntegerSelectorFieldClass::Shared
2162 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2163 const IntegerFieldClass selectorFieldClass,
2164 const ConstSignedIntegerRangeSet ranges)
2166 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2168 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
2169 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2170 ranges.libObjPtr());
2172 internal::validateCreatedObjPtr(libObjPtr);
2173 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2176 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass()
2178 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2180 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
2182 internal::validateCreatedObjPtr(libObjPtr);
2183 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2186 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2187 createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2189 return this->_createVariantWithIntegerSelectorFieldClass<
2190 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
2193 VariantWithSignedIntegerSelectorFieldClass::Shared
2194 createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2196 return this->_createVariantWithIntegerSelectorFieldClass<
2197 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
2200 void assignsAutomaticStreamClassId(const bool val) noexcept
2202 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2204 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
2205 static_cast<bt_bool>(val));
2208 bool assignsAutomaticStreamClassId() const noexcept
2210 return static_cast<bool>(
2211 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2214 std::uint64_t size() const noexcept
2216 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2219 ConstStreamClass operator[](const std::uint64_t index) const noexcept
2221 return ConstStreamClass {_ConstSpec::streamClassByIndex(this->libObjPtr(), index)};
2224 _StreamClass operator[](const std::uint64_t index) noexcept
2226 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2229 nonstd::optional<ConstStreamClass> streamClassById(const std::uint64_t id) const noexcept
2231 const auto libObjPtr = _ConstSpec::streamClassById(this->libObjPtr(), id);
2234 return ConstStreamClass {libObjPtr};
2237 return nonstd::nullopt;
2240 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) noexcept
2242 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2245 return _StreamClass {libObjPtr};
2248 return nonstd::nullopt;
2251 template <typename LibValT>
2252 void userAttributes(const CommonMapValue<LibValT> userAttrs)
2254 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2256 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2259 ConstMapValue userAttributes() const noexcept
2261 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
2264 UserAttributes userAttributes() noexcept
2266 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2269 Shared shared() const noexcept
2271 return Shared::createWithRef(*this);
2275 template <typename ObjT>
2276 typename ObjT::Shared
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);
2285 return ObjT::Shared::createWithoutRef(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 */