2 * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
11 #include <type_traits>
13 #include <babeltrace2/babeltrace.h>
15 #include "cpp-common/optional.hpp"
16 #include "cpp-common/string_view.hpp"
18 #include "borrowed-object.hpp"
19 #include "clock-class.hpp"
20 #include "field-class.hpp"
22 #include "internal/utils.hpp"
23 #include "shared-object.hpp"
28 template <typename LibObjT>
31 template <typename LibObjT>
34 template <typename LibObjT>
37 template <typename LibObjT>
40 template <typename LibObjT>
41 class CommonEventClass;
43 template <typename LibObjT>
44 class CommonStreamClass;
46 template <typename LibObjT>
47 class CommonTraceClass;
51 template <typename LibObjT>
52 struct CommonEventSpec;
54 /* Functions specific to mutable events */
56 struct CommonEventSpec<bt_event> final
58 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
60 return bt_event_borrow_class(libObjPtr);
63 static bt_stream *stream(bt_event * const libObjPtr) noexcept
65 return bt_event_borrow_stream(libObjPtr);
68 static bt_packet *packet(bt_event * const libObjPtr) noexcept
70 return bt_event_borrow_packet(libObjPtr);
73 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
75 return bt_event_borrow_payload_field(libObjPtr);
78 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
80 return bt_event_borrow_specific_context_field(libObjPtr);
83 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
85 return bt_event_borrow_common_context_field(libObjPtr);
89 /* Functions specific to constant events */
91 struct CommonEventSpec<const bt_event> final
93 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
95 return bt_event_borrow_class_const(libObjPtr);
98 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
100 return bt_event_borrow_stream_const(libObjPtr);
103 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
105 return bt_event_borrow_packet_const(libObjPtr);
108 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
110 return bt_event_borrow_payload_field_const(libObjPtr);
113 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
115 return bt_event_borrow_specific_context_field_const(libObjPtr);
118 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
120 return bt_event_borrow_common_context_field_const(libObjPtr);
124 } /* namespace internal */
126 template <typename LibObjT>
127 class CommonEvent final : public BorrowedObject<LibObjT>
130 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
131 using typename BorrowedObject<LibObjT>::_LibObjPtr;
132 using _Spec = internal::CommonEventSpec<LibObjT>;
135 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
136 CommonPacket<bt_packet>>::type;
139 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
140 CommonStream<bt_stream>>::type;
142 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
143 ConstStructureField, StructureField>::type;
146 using Class = typename std::conditional<std::is_const<LibObjT>::value,
147 CommonEventClass<const bt_event_class>,
148 CommonEventClass<bt_event_class>>::type;
150 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
154 template <typename OtherLibObjT>
155 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
159 template <typename OtherLibObjT>
160 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
162 _ThisBorrowedObject::operator=(event);
166 Class cls() const noexcept;
167 _Stream stream() const noexcept;
168 nonstd::optional<_Packet> packet() const noexcept;
170 nonstd::optional<_StructureField> payloadField() const noexcept
172 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
175 return _StructureField {libObjPtr};
178 return nonstd::nullopt;
181 nonstd::optional<_StructureField> specificContextField() const noexcept
183 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
186 return _StructureField {libObjPtr};
189 return nonstd::nullopt;
192 nonstd::optional<_StructureField> commonContextField() const noexcept
194 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
197 return _StructureField {libObjPtr};
200 return nonstd::nullopt;
204 using Event = CommonEvent<bt_event>;
205 using ConstEvent = CommonEvent<const bt_event>;
209 struct EventTypeDescr
211 using Const = ConstEvent;
212 using NonConst = Event;
216 struct TypeDescr<Event> : public EventTypeDescr
221 struct TypeDescr<ConstEvent> : public EventTypeDescr
225 struct PacketRefFuncs final
227 static void get(const bt_packet * const libObjPtr) noexcept
229 bt_packet_get_ref(libObjPtr);
232 static void put(const bt_packet * const libObjPtr) noexcept
234 bt_packet_put_ref(libObjPtr);
238 template <typename LibObjT>
239 struct CommonPacketSpec;
241 /* Functions specific to mutable packets */
243 struct CommonPacketSpec<bt_packet> final
245 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
247 return bt_packet_borrow_stream(libObjPtr);
250 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
252 return bt_packet_borrow_context_field(libObjPtr);
256 /* Functions specific to constant packets */
258 struct CommonPacketSpec<const bt_packet> final
260 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
262 return bt_packet_borrow_stream_const(libObjPtr);
265 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
267 return bt_packet_borrow_context_field_const(libObjPtr);
271 } /* namespace internal */
273 template <typename LibObjT>
274 class CommonPacket final : public BorrowedObject<LibObjT>
277 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
278 using typename BorrowedObject<LibObjT>::_LibObjPtr;
279 using _Spec = internal::CommonPacketSpec<LibObjT>;
280 using _ThisCommonPacket = CommonPacket<LibObjT>;
283 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
284 CommonStream<bt_stream>>::type;
286 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
287 ConstStructureField, StructureField>::type;
290 using Shared = SharedObject<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
292 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
296 template <typename OtherLibObjT>
297 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
301 template <typename OtherLibObjT>
302 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
304 _ThisBorrowedObject::operator=(packet);
308 _Stream stream() const noexcept;
310 nonstd::optional<_StructureField> contextField() const noexcept
312 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
315 return _StructureField {libObjPtr};
318 return nonstd::nullopt;
321 Shared shared() const noexcept
323 return Shared::createWithRef(*this);
327 using Packet = CommonPacket<bt_packet>;
328 using ConstPacket = CommonPacket<const bt_packet>;
332 struct PacketTypeDescr
334 using Const = ConstPacket;
335 using NonConst = Packet;
339 struct TypeDescr<Packet> : public PacketTypeDescr
344 struct TypeDescr<ConstPacket> : public PacketTypeDescr
348 } /* namespace internal */
350 template <typename LibObjT>
351 nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
352 CommonEvent<LibObjT>::packet() const noexcept
354 const auto libObjPtr = _Spec::packet(this->libObjPtr());
357 return _Packet {libObjPtr};
360 return nonstd::nullopt;
365 struct StreamRefFuncs final
367 static void get(const bt_stream * const libObjPtr) noexcept
369 bt_stream_get_ref(libObjPtr);
372 static void put(const bt_stream * const libObjPtr) noexcept
374 bt_stream_put_ref(libObjPtr);
378 template <typename LibObjT>
379 struct CommonStreamSpec;
381 /* Functions specific to mutable streams */
383 struct CommonStreamSpec<bt_stream> final
385 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
387 return bt_stream_borrow_class(libObjPtr);
390 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
392 return bt_stream_borrow_trace(libObjPtr);
395 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
397 return bt_stream_borrow_user_attributes(libObjPtr);
401 /* Functions specific to constant streams */
403 struct CommonStreamSpec<const bt_stream> final
405 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
407 return bt_stream_borrow_class_const(libObjPtr);
410 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
412 return bt_stream_borrow_trace_const(libObjPtr);
415 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
417 return bt_stream_borrow_user_attributes_const(libObjPtr);
421 } /* namespace internal */
423 template <typename LibObjT>
424 class CommonStream final : public BorrowedObject<LibObjT>
427 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
428 using typename BorrowedObject<LibObjT>::_LibObjPtr;
429 using _Spec = internal::CommonStreamSpec<LibObjT>;
430 using _ThisCommonStream = CommonStream<LibObjT>;
433 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
434 CommonTrace<bt_trace>>::type;
437 using Shared = SharedObject<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
439 using Class = typename std::conditional<std::is_const<LibObjT>::value,
440 CommonStreamClass<const bt_stream_class>,
441 CommonStreamClass<bt_stream_class>>::type;
443 using UserAttributes =
444 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
446 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
450 template <typename OtherLibObjT>
451 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
455 template <typename OtherLibObjT>
456 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
458 _ThisBorrowedObject::operator=(stream);
462 Packet::Shared createPacket() const
464 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
466 const auto libObjPtr = bt_packet_create(this->libObjPtr());
468 internal::validateCreatedObjPtr(libObjPtr);
469 return Packet::Shared::createWithoutRef(libObjPtr);
472 Class cls() const noexcept;
473 _Trace trace() const noexcept;
475 std::uint64_t id() const noexcept
477 return bt_stream_get_id(this->libObjPtr());
480 void name(const char * const name) const
482 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
484 const auto status = bt_stream_set_name(this->libObjPtr(), name);
486 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
487 throw MemoryError {};
491 void name(const std::string& name) const
493 this->name(name.data());
496 nonstd::optional<bpstd::string_view> name() const noexcept
498 const auto name = bt_stream_get_name(this->libObjPtr());
504 return nonstd::nullopt;
507 template <typename LibValT>
508 void userAttributes(const CommonMapValue<LibValT> userAttrs) const
510 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
512 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
515 UserAttributes userAttributes() const noexcept
517 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
520 Shared shared() const noexcept
522 return Shared::createWithRef(*this);
526 using Stream = CommonStream<bt_stream>;
527 using ConstStream = CommonStream<const bt_stream>;
531 struct StreamTypeDescr
533 using Const = ConstStream;
534 using NonConst = Stream;
538 struct TypeDescr<Stream> : public StreamTypeDescr
543 struct TypeDescr<ConstStream> : public StreamTypeDescr
547 } /* namespace internal */
549 template <typename LibObjT>
550 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() const noexcept
552 return _Stream {_Spec::stream(this->libObjPtr())};
555 template <typename LibObjT>
556 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() const noexcept
558 return _Stream {_Spec::stream(this->libObjPtr())};
563 struct TraceRefFuncs final
565 static void get(const bt_trace * const libObjPtr) noexcept
567 bt_trace_get_ref(libObjPtr);
570 static void put(const bt_trace * const libObjPtr) noexcept
572 bt_trace_put_ref(libObjPtr);
576 template <typename LibObjT>
577 struct CommonTraceSpec;
579 /* Functions specific to mutable traces */
581 struct CommonTraceSpec<bt_trace> final
583 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
585 return bt_trace_borrow_class(libObjPtr);
588 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
590 return bt_trace_borrow_stream_by_index(libObjPtr, index);
593 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
595 return bt_trace_borrow_stream_by_id(libObjPtr, id);
598 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
600 return bt_trace_borrow_user_attributes(libObjPtr);
604 /* Functions specific to constant traces */
606 struct CommonTraceSpec<const bt_trace> final
608 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
610 return bt_trace_borrow_class_const(libObjPtr);
613 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
614 const std::uint64_t index) noexcept
616 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
619 static const bt_stream *streamById(const bt_trace * const libObjPtr,
620 const std::uint64_t id) noexcept
622 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
625 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
627 return bt_trace_borrow_user_attributes_const(libObjPtr);
631 } /* namespace internal */
633 template <typename LibObjT>
634 class CommonTrace final : public BorrowedObject<LibObjT>
636 /* Allow instantiate() to call `trace.libObjPtr()` */
637 friend class CommonStreamClass<bt_stream_class>;
640 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
641 using typename BorrowedObject<LibObjT>::_LibObjPtr;
642 using _Spec = internal::CommonTraceSpec<LibObjT>;
643 using _ThisCommonTrace = CommonTrace<LibObjT>;
646 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
647 CommonStream<bt_stream>>::type;
650 using Shared = SharedObject<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
652 using Class = typename std::conditional<std::is_const<LibObjT>::value,
653 CommonTraceClass<const bt_trace_class>,
654 CommonTraceClass<bt_trace_class>>::type;
656 using UserAttributes =
657 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
659 struct ConstEnvironmentEntry
661 bpstd::string_view name;
665 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
669 template <typename OtherLibObjT>
670 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
674 template <typename OtherLibObjT>
675 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
677 _ThisBorrowedObject::operator=(trace);
681 Class cls() const noexcept;
683 void name(const char * const name) const
685 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
687 const auto status = bt_trace_set_name(this->libObjPtr(), name);
689 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
690 throw MemoryError {};
694 void name(const std::string& name) const
696 this->name(name.data());
699 nonstd::optional<bpstd::string_view> name() const noexcept
701 const auto name = bt_trace_get_name(this->libObjPtr());
707 return nonstd::nullopt;
710 void uuid(const bt2_common::UuidView& uuid) const noexcept
712 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
715 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
717 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
720 return bt2_common::UuidView {uuid};
723 return nonstd::nullopt;
726 std::uint64_t size() const noexcept
728 return bt_trace_get_stream_count(this->libObjPtr());
731 _Stream operator[](const std::uint64_t index) const noexcept
733 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
736 nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
738 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
741 return _Stream {libObjPtr};
744 return nonstd::nullopt;
747 void environmentEntry(const char * const name, const std::int64_t val) const
749 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
751 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
753 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
754 throw MemoryError {};
758 void environmentEntry(const std::string& name, const std::int64_t val) const
760 this->environmentEntry(name.data(), val);
763 void environmentEntry(const char * const name, const char * const val) const
765 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
767 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
769 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
770 throw MemoryError {};
774 void environmentEntry(const std::string& name, const char * const val) const
776 this->environmentEntry(name.data(), val);
779 void environmentEntry(const char * const name, const std::string& val) const
781 this->environmentEntry(name, val.data());
784 void environmentEntry(const std::string& name, const std::string& val) const
786 this->environmentEntry(name.data(), val.data());
789 std::uint64_t environmentSize() const noexcept
791 return bt_trace_get_environment_entry_count(this->libObjPtr());
794 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
797 const bt_value *libObjPtr;
799 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
801 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
804 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
806 const auto libObjPtr =
807 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
810 return ConstValue {libObjPtr};
813 return nonstd::nullopt;
816 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
818 return this->environmentEntry(name.data());
821 template <typename LibValT>
822 void userAttributes(const CommonMapValue<LibValT> userAttrs) const
824 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
826 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
829 UserAttributes userAttributes() const noexcept
831 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
834 Shared shared() const noexcept
836 return Shared::createWithRef(*this);
840 using Trace = CommonTrace<bt_trace>;
841 using ConstTrace = CommonTrace<const bt_trace>;
845 struct TraceTypeDescr
847 using Const = ConstTrace;
848 using NonConst = Trace;
852 struct TypeDescr<Trace> : public TraceTypeDescr
857 struct TypeDescr<ConstTrace> : public TraceTypeDescr
861 } /* namespace internal */
863 template <typename LibObjT>
864 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() const noexcept
866 return _Trace {_Spec::trace(this->libObjPtr())};
871 struct EventClassRefFuncs final
873 static void get(const bt_event_class * const libObjPtr) noexcept
875 bt_event_class_get_ref(libObjPtr);
878 static void put(const bt_event_class * const libObjPtr) noexcept
880 bt_event_class_put_ref(libObjPtr);
884 template <typename LibObjT>
885 struct CommonEventClassSpec;
887 /* Functions specific to mutable event classes */
889 struct CommonEventClassSpec<bt_event_class> final
891 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
893 return bt_event_class_borrow_stream_class(libObjPtr);
896 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
898 return bt_event_class_borrow_payload_field_class(libObjPtr);
901 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
903 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
906 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
908 return bt_event_class_borrow_user_attributes(libObjPtr);
912 /* Functions specific to constant event classes */
914 struct CommonEventClassSpec<const bt_event_class> final
916 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
918 return bt_event_class_borrow_stream_class_const(libObjPtr);
921 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
923 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
926 static const bt_field_class *
927 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
929 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
932 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
934 return bt_event_class_borrow_user_attributes_const(libObjPtr);
938 } /* namespace internal */
940 template <typename LibObjT>
941 class CommonEventClass final : public BorrowedObject<LibObjT>
944 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
945 using typename BorrowedObject<LibObjT>::_LibObjPtr;
946 using _Spec = internal::CommonEventClassSpec<LibObjT>;
947 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
949 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
950 CommonStreamClass<const bt_stream_class>,
951 CommonStreamClass<bt_stream_class>>::type;
953 using _StructureFieldClass =
954 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
955 StructureFieldClass>::type;
958 using Shared = SharedObject<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
960 using UserAttributes =
961 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
965 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
966 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
967 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
968 ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
969 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
970 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
971 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
972 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
973 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
974 DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
975 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
976 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
977 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
978 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
979 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
982 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
986 template <typename OtherLibObjT>
987 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
988 _ThisBorrowedObject {eventClass}
992 template <typename OtherLibObjT>
993 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
995 _ThisBorrowedObject::operator=(eventClass);
999 _StreamClass streamClass() const noexcept;
1001 std::uint64_t id() const noexcept
1003 return bt_event_class_get_id(this->libObjPtr());
1006 void name(const char * const name) const
1008 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1010 const auto status = bt_event_class_set_name(this->libObjPtr(), name);
1012 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1013 throw MemoryError {};
1017 void name(const std::string& name) const
1019 this->name(name.data());
1022 nonstd::optional<bpstd::string_view> name() const noexcept
1024 const auto name = bt_event_class_get_name(this->libObjPtr());
1030 return nonstd::nullopt;
1033 void logLevel(const LogLevel logLevel) const noexcept
1035 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1037 bt_event_class_set_log_level(this->libObjPtr(),
1038 static_cast<bt_event_class_log_level>(logLevel));
1041 nonstd::optional<LogLevel> logLevel() const noexcept
1043 bt_event_class_log_level libLogLevel;
1044 const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
1046 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1047 return static_cast<LogLevel>(libLogLevel);
1050 return nonstd::nullopt;
1053 void emfUri(const char * const emfUri) const
1055 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1057 const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
1059 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1060 throw MemoryError {};
1064 void emfUri(const std::string& emfUri) const
1066 this->emfUri(emfUri.data());
1069 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1071 const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
1077 return nonstd::nullopt;
1080 void payloadFieldClass(const StructureFieldClass fc) const
1082 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1085 bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
1087 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1088 throw MemoryError {};
1092 nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
1094 const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
1097 return _StructureFieldClass {libObjPtr};
1100 return nonstd::nullopt;
1103 void specificContextFieldClass(const StructureFieldClass fc) const
1105 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1108 bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
1110 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1111 throw MemoryError {};
1115 nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
1117 const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
1120 return _StructureFieldClass {libObjPtr};
1123 return nonstd::nullopt;
1126 template <typename LibValT>
1127 void userAttributes(const CommonMapValue<LibValT> userAttrs) const
1129 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1131 bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1134 UserAttributes userAttributes() const noexcept
1136 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1139 Shared shared() const noexcept
1141 return Shared::createWithRef(*this);
1145 using EventClass = CommonEventClass<bt_event_class>;
1146 using ConstEventClass = CommonEventClass<const bt_event_class>;
1148 namespace internal {
1150 struct EventClassTypeDescr
1152 using Const = ConstEventClass;
1153 using NonConst = EventClass;
1157 struct TypeDescr<EventClass> : public EventClassTypeDescr
1162 struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
1166 } /* namespace internal */
1168 template <typename LibObjT>
1169 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() const noexcept
1171 return Class {_Spec::cls(this->libObjPtr())};
1174 namespace internal {
1176 struct StreamClassRefFuncs final
1178 static void get(const bt_stream_class * const libObjPtr) noexcept
1180 bt_stream_class_get_ref(libObjPtr);
1183 static void put(const bt_stream_class * const libObjPtr) noexcept
1185 bt_stream_class_put_ref(libObjPtr);
1189 template <typename LibObjT>
1190 struct CommonStreamClassSpec;
1192 /* Functions specific to mutable stream classes */
1194 struct CommonStreamClassSpec<bt_stream_class> final
1196 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1198 return bt_stream_class_borrow_trace_class(libObjPtr);
1201 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1202 const std::uint64_t index) noexcept
1204 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1207 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1208 const std::uint64_t id) noexcept
1210 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1213 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1215 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1218 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1220 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1223 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1225 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1228 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1230 return bt_stream_class_borrow_user_attributes(libObjPtr);
1234 /* Functions specific to constant stream classes */
1236 struct CommonStreamClassSpec<const bt_stream_class> final
1238 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1240 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1243 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1244 const std::uint64_t index) noexcept
1246 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1249 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1250 const std::uint64_t id) noexcept
1252 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1255 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1257 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1260 static const bt_field_class *
1261 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1263 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1266 static const bt_field_class *
1267 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1269 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1272 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1274 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1278 } /* namespace internal */
1280 template <typename LibObjT>
1281 class CommonStreamClass final : public BorrowedObject<LibObjT>
1284 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1285 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1286 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1287 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1289 using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
1290 CommonTraceClass<const bt_trace_class>,
1291 CommonTraceClass<bt_trace_class>>::type;
1293 using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
1294 CommonEventClass<const bt_event_class>,
1295 CommonEventClass<bt_event_class>>::type;
1297 using _StructureFieldClass =
1298 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1299 StructureFieldClass>::type;
1302 typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
1305 using Shared = SharedObject<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1307 using UserAttributes =
1308 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1310 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
1311 _ThisBorrowedObject {libObjPtr}
1315 template <typename OtherLibObjT>
1316 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1317 _ThisBorrowedObject {streamClass}
1321 template <typename OtherLibObjT>
1322 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1324 _ThisBorrowedObject::operator=(streamClass);
1328 Stream::Shared instantiate(const Trace trace) const
1330 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1332 const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
1334 internal::validateCreatedObjPtr(libObjPtr);
1335 return Stream::Shared::createWithoutRef(libObjPtr);
1338 Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
1340 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1342 const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
1344 internal::validateCreatedObjPtr(libObjPtr);
1345 return Stream::Shared::createWithoutRef(libObjPtr);
1348 EventClass::Shared createEventClass() const
1350 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1352 const auto libObjPtr = bt_event_class_create(this->libObjPtr());
1354 internal::validateCreatedObjPtr(libObjPtr);
1355 return EventClass::Shared::createWithoutRef(libObjPtr);
1358 EventClass::Shared createEventClass(const std::uint64_t id) const
1360 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1362 const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
1364 internal::validateCreatedObjPtr(libObjPtr);
1365 return EventClass::Shared::createWithoutRef(libObjPtr);
1368 _TraceClass traceClass() const noexcept;
1370 std::uint64_t id() const noexcept
1372 return bt_stream_class_get_id(this->libObjPtr());
1375 void name(const char * const name) const
1377 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1379 const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
1381 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1382 throw MemoryError {};
1386 void name(const std::string& name) const
1388 this->name(name.data());
1391 nonstd::optional<bpstd::string_view> name() const noexcept
1393 const auto name = bt_stream_class_get_name(this->libObjPtr());
1399 return nonstd::nullopt;
1402 void assignsAutomaticEventClassId(const bool val) const noexcept
1404 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1406 bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
1407 static_cast<bt_bool>(val));
1410 bool assignsAutomaticEventClassId() const noexcept
1412 return static_cast<bool>(
1413 bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
1416 void assignsAutomaticStreamId(const bool val) const noexcept
1418 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1420 bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
1421 static_cast<bt_bool>(val));
1424 bool assignsAutomaticStreamId() const noexcept
1426 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
1429 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1430 const bool withEndDefaultClkSnapshot) const noexcept
1432 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1434 bt_stream_class_set_supports_packets(this->libObjPtr(),
1435 static_cast<bt_bool>(supportsPackets),
1436 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1437 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1440 bool supportsPackets() const noexcept
1442 return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
1445 bool packetsHaveBeginningClockSnapshot() const noexcept
1447 return static_cast<bool>(
1448 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
1451 bool packetsHaveEndClockSnapshot() const noexcept
1453 return static_cast<bool>(
1454 bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
1457 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1458 const bool withDefaultClkSnapshots) const noexcept
1460 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1462 bt_stream_class_set_supports_discarded_events(
1463 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
1464 static_cast<bt_bool>(withDefaultClkSnapshots));
1467 bool supportsDiscardedEvents() const noexcept
1469 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
1472 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1474 return static_cast<bool>(
1475 bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
1478 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1479 const bool withDefaultClkSnapshots) const noexcept
1481 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1483 bt_stream_class_set_supports_discarded_packets(
1484 this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
1485 static_cast<bt_bool>(withDefaultClkSnapshots));
1488 bool supportsDiscardedPackets() const noexcept
1490 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
1493 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1495 return static_cast<bool>(
1496 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
1499 void defaultClockClass(const ClockClass clkCls) const
1501 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1504 bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
1506 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1509 nonstd::optional<_ClockClass> defaultClockClass() const noexcept
1511 const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
1514 return _ClockClass {libObjPtr};
1517 return nonstd::nullopt;
1520 std::uint64_t size() const noexcept
1522 return bt_stream_class_get_event_class_count(this->libObjPtr());
1525 _EventClass operator[](const std::uint64_t index) const noexcept
1527 return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
1530 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
1532 const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
1535 return _EventClass {libObjPtr};
1538 return nonstd::nullopt;
1541 void packetContextFieldClass(const StructureFieldClass fc) const
1543 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1546 bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
1548 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1549 throw MemoryError {};
1553 nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
1555 const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
1558 return _StructureFieldClass {libObjPtr};
1561 return nonstd::nullopt;
1564 void eventCommonContextFieldClass(const StructureFieldClass fc) const
1566 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1569 bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
1571 if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1572 throw MemoryError {};
1576 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
1578 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
1581 return _StructureFieldClass {libObjPtr};
1584 return nonstd::nullopt;
1587 template <typename LibValT>
1588 void userAttributes(const CommonMapValue<LibValT> userAttrs) const
1590 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1592 bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
1595 UserAttributes userAttributes() const noexcept
1597 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
1600 Shared shared() const noexcept
1602 return Shared::createWithRef(*this);
1606 using StreamClass = CommonStreamClass<bt_stream_class>;
1607 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1609 namespace internal {
1611 struct StreamClassTypeDescr
1613 using Const = ConstStreamClass;
1614 using NonConst = StreamClass;
1618 struct TypeDescr<StreamClass> : public StreamClassTypeDescr
1623 struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
1627 } /* namespace internal */
1629 template <typename LibObjT>
1630 typename CommonEventClass<LibObjT>::_StreamClass
1631 CommonEventClass<LibObjT>::streamClass() const noexcept
1633 return _StreamClass {_Spec::streamClass(this->libObjPtr())};
1636 template <typename LibObjT>
1637 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() const noexcept
1639 return Class {_Spec::cls(this->libObjPtr())};
1642 namespace internal {
1644 struct TraceClassRefFuncs final
1646 static void get(const bt_trace_class * const libObjPtr) noexcept
1648 bt_trace_class_get_ref(libObjPtr);
1651 static void put(const bt_trace_class * const libObjPtr) noexcept
1653 bt_trace_class_put_ref(libObjPtr);
1657 template <typename LibObjT>
1658 struct CommonTraceClassSpec;
1660 /* Functions specific to mutable stream classes */
1662 struct CommonTraceClassSpec<bt_trace_class> final
1664 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1665 const std::uint64_t index) noexcept
1667 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1670 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1671 const std::uint64_t id) noexcept
1673 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1676 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1678 return bt_trace_class_borrow_user_attributes(libObjPtr);
1682 /* Functions specific to constant stream classes */
1684 struct CommonTraceClassSpec<const bt_trace_class> final
1686 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1687 const std::uint64_t index) noexcept
1689 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1692 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1693 const std::uint64_t id) noexcept
1695 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1698 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1700 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1704 } /* namespace internal */
1706 template <typename LibObjT>
1707 class CommonTraceClass final : public BorrowedObject<LibObjT>
1710 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1711 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1712 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1713 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1715 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1716 CommonStreamClass<const bt_stream_class>,
1717 CommonStreamClass<bt_stream_class>>::type;
1720 using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1722 using UserAttributes =
1723 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1725 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1729 template <typename OtherLibObjT>
1730 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1731 _ThisBorrowedObject {traceClass}
1735 template <typename OtherLibObjT>
1736 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1738 _ThisBorrowedObject::operator=(traceClass);
1742 Trace::Shared instantiate() const
1744 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1746 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1748 internal::validateCreatedObjPtr(libObjPtr);
1749 return Trace::Shared::createWithoutRef(libObjPtr);
1752 StreamClass::Shared createStreamClass() const
1754 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1756 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1758 internal::validateCreatedObjPtr(libObjPtr);
1759 return StreamClass::Shared::createWithoutRef(libObjPtr);
1762 StreamClass::Shared createStreamClass(const std::uint64_t id) const
1764 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1766 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1768 internal::validateCreatedObjPtr(libObjPtr);
1769 return StreamClass::Shared::createWithoutRef(libObjPtr);
1772 FieldClass::Shared createBoolFieldClass() const
1774 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1776 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1778 internal::validateCreatedObjPtr(libObjPtr);
1779 return FieldClass::Shared::createWithoutRef(libObjPtr);
1782 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
1784 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1786 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
1788 internal::validateCreatedObjPtr(libObjPtr);
1789 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1792 IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
1794 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1796 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
1798 internal::validateCreatedObjPtr(libObjPtr);
1799 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1802 IntegerFieldClass::Shared createSignedIntegerFieldClass() const
1804 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1806 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
1808 internal::validateCreatedObjPtr(libObjPtr);
1809 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
1812 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
1814 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1816 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
1818 internal::validateCreatedObjPtr(libObjPtr);
1819 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1822 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
1824 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1826 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
1828 internal::validateCreatedObjPtr(libObjPtr);
1829 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
1832 FieldClass::Shared createSinglePrecisionRealFieldClass() const
1834 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1836 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
1838 internal::validateCreatedObjPtr(libObjPtr);
1839 return FieldClass::Shared::createWithoutRef(libObjPtr);
1842 FieldClass::Shared createDoublePrecisionRealFieldClass() const
1844 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1846 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
1848 internal::validateCreatedObjPtr(libObjPtr);
1849 return FieldClass::Shared::createWithoutRef(libObjPtr);
1852 FieldClass::Shared createStringFieldClass() const
1854 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1856 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
1858 internal::validateCreatedObjPtr(libObjPtr);
1859 return FieldClass::Shared::createWithoutRef(libObjPtr);
1862 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
1863 const std::uint64_t length) const
1865 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1867 const auto libObjPtr = bt_field_class_array_static_create(
1868 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
1870 internal::validateCreatedObjPtr(libObjPtr);
1871 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1874 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
1876 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1878 const auto libObjPtr = bt_field_class_array_dynamic_create(
1879 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
1881 internal::validateCreatedObjPtr(libObjPtr);
1882 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
1885 DynamicArrayWithLengthFieldClass::Shared
1886 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
1887 const IntegerFieldClass lengthFieldClass) const
1889 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1891 const auto libObjPtr = bt_field_class_array_dynamic_create(
1892 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
1894 internal::validateCreatedObjPtr(libObjPtr);
1895 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
1898 StructureFieldClass::Shared createStructureFieldClass() const
1900 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1902 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
1904 internal::validateCreatedObjPtr(libObjPtr);
1905 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
1908 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
1910 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1912 const auto libObjPtr = bt_field_class_option_without_selector_create(
1913 this->libObjPtr(), optionalFieldClass.libObjPtr());
1915 internal::validateCreatedObjPtr(libObjPtr);
1916 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
1919 OptionWithBoolSelectorFieldClass::Shared
1920 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
1921 const FieldClass selectorFieldClass) const
1923 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1925 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
1926 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
1928 internal::validateCreatedObjPtr(libObjPtr);
1929 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1932 OptionWithUnsignedIntegerSelectorFieldClass::Shared
1933 createOptionWithUnsignedIntegerSelectorFieldClass(
1934 const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
1935 const ConstUnsignedIntegerRangeSet ranges) const
1937 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1939 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
1940 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1941 ranges.libObjPtr());
1943 internal::validateCreatedObjPtr(libObjPtr);
1944 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1947 OptionWithSignedIntegerSelectorFieldClass::Shared
1948 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
1949 const IntegerFieldClass selectorFieldClass,
1950 const ConstSignedIntegerRangeSet ranges) const
1952 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1954 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
1955 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
1956 ranges.libObjPtr());
1958 internal::validateCreatedObjPtr(libObjPtr);
1959 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1962 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
1964 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1966 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
1968 internal::validateCreatedObjPtr(libObjPtr);
1969 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
1972 VariantWithUnsignedIntegerSelectorFieldClass::Shared
1973 createVariantWithUnsignedIntegerSelectorFieldClass(
1974 const IntegerFieldClass selectorFieldClass) const
1976 return this->_createVariantWithIntegerSelectorFieldClass<
1977 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
1980 VariantWithSignedIntegerSelectorFieldClass::Shared
1981 createVariantWithSignedIntegerSelectorFieldClass(
1982 const IntegerFieldClass selectorFieldClass) const
1984 return this->_createVariantWithIntegerSelectorFieldClass<
1985 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
1988 void assignsAutomaticStreamClassId(const bool val) const noexcept
1990 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1992 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
1993 static_cast<bt_bool>(val));
1996 bool assignsAutomaticStreamClassId() const noexcept
1998 return static_cast<bool>(
1999 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2002 std::uint64_t size() const noexcept
2004 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2007 _StreamClass operator[](const std::uint64_t index) const noexcept
2009 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2012 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
2014 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2017 return _StreamClass {libObjPtr};
2020 return nonstd::nullopt;
2023 template <typename LibValT>
2024 void userAttributes(const CommonMapValue<LibValT> userAttrs) const
2026 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2028 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2031 UserAttributes userAttributes() const noexcept
2033 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2036 Shared shared() const noexcept
2038 return Shared::createWithRef(*this);
2042 template <typename ObjT>
2043 typename ObjT::Shared
2044 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
2046 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2048 const auto libObjPtr =
2049 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2051 internal::validateCreatedObjPtr(libObjPtr);
2052 return ObjT::Shared::createWithoutRef(libObjPtr);
2056 using TraceClass = CommonTraceClass<bt_trace_class>;
2057 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2059 namespace internal {
2061 struct TraceClassTypeDescr
2063 using Const = ConstTraceClass;
2064 using NonConst = TraceClass;
2068 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2073 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2077 } /* namespace internal */
2079 template <typename LibObjT>
2080 typename CommonStreamClass<LibObjT>::_TraceClass
2081 CommonStreamClass<LibObjT>::traceClass() const noexcept
2083 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2086 template <typename LibObjT>
2087 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() const noexcept
2089 return Class {_Spec::cls(this->libObjPtr())};
2092 } /* namespace bt2 */
2094 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */