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 _ConstSpec = internal::CommonEventSpec<const bt_event>;
133 using _Spec = internal::CommonEventSpec<LibObjT>;
136 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
137 CommonPacket<bt_packet>>::type;
140 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
141 CommonStream<bt_stream>>::type;
143 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
144 ConstStructureField, StructureField>::type;
147 using Class = typename std::conditional<std::is_const<LibObjT>::value,
148 CommonEventClass<const bt_event_class>,
149 CommonEventClass<bt_event_class>>::type;
151 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
155 template <typename OtherLibObjT>
156 CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
160 template <typename OtherLibObjT>
161 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
163 _ThisBorrowedObject::operator=(event);
167 CommonEventClass<const bt_event_class> cls() const noexcept;
168 Class cls() noexcept;
169 CommonStream<const bt_stream> stream() const noexcept;
170 _Stream stream() noexcept;
171 nonstd::optional<CommonPacket<const bt_packet>> packet() const noexcept;
172 nonstd::optional<_Packet> packet() noexcept;
174 nonstd::optional<ConstStructureField> payloadField() const noexcept
176 const auto libObjPtr = _ConstSpec::payloadField(this->libObjPtr());
179 return ConstStructureField {libObjPtr};
182 return nonstd::nullopt;
185 nonstd::optional<_StructureField> payloadField() noexcept
187 const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
190 return _StructureField {libObjPtr};
193 return nonstd::nullopt;
196 nonstd::optional<ConstStructureField> specificContextField() const noexcept
198 const auto libObjPtr = _ConstSpec::specificContextField(this->libObjPtr());
201 return ConstStructureField {libObjPtr};
204 return nonstd::nullopt;
207 nonstd::optional<_StructureField> specificContextField() noexcept
209 const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
212 return _StructureField {libObjPtr};
215 return nonstd::nullopt;
218 nonstd::optional<ConstStructureField> commonContextField() const noexcept
220 const auto libObjPtr = _ConstSpec::commonContextField(this->libObjPtr());
223 return ConstStructureField {libObjPtr};
226 return nonstd::nullopt;
229 nonstd::optional<_StructureField> commonContextField() noexcept
231 const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
234 return _StructureField {libObjPtr};
237 return nonstd::nullopt;
241 using Event = CommonEvent<bt_event>;
242 using ConstEvent = CommonEvent<const bt_event>;
246 struct EventTypeDescr
248 using Const = ConstEvent;
249 using NonConst = Event;
253 struct TypeDescr<Event> : public EventTypeDescr
258 struct TypeDescr<ConstEvent> : public EventTypeDescr
262 struct PacketRefFuncs final
264 static void get(const bt_packet * const libObjPtr)
266 bt_packet_get_ref(libObjPtr);
269 static void put(const bt_packet * const libObjPtr)
271 bt_packet_put_ref(libObjPtr);
275 template <typename LibObjT>
276 struct CommonPacketSpec;
278 /* Functions specific to mutable packets */
280 struct CommonPacketSpec<bt_packet> final
282 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
284 return bt_packet_borrow_stream(libObjPtr);
287 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
289 return bt_packet_borrow_context_field(libObjPtr);
293 /* Functions specific to constant packets */
295 struct CommonPacketSpec<const bt_packet> final
297 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
299 return bt_packet_borrow_stream_const(libObjPtr);
302 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
304 return bt_packet_borrow_context_field_const(libObjPtr);
308 } /* namespace internal */
310 template <typename LibObjT>
311 class CommonPacket final : public BorrowedObject<LibObjT>
314 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
315 using typename BorrowedObject<LibObjT>::_LibObjPtr;
316 using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
317 using _Spec = internal::CommonPacketSpec<LibObjT>;
318 using _ThisCommonPacket = CommonPacket<LibObjT>;
321 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
322 CommonStream<bt_stream>>::type;
324 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
325 ConstStructureField, StructureField>::type;
328 using Shared = SharedObject<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
330 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
334 template <typename OtherLibObjT>
335 CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
339 template <typename OtherLibObjT>
340 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
342 _ThisBorrowedObject::operator=(packet);
346 CommonStream<const bt_stream> stream() const noexcept;
347 _Stream stream() noexcept;
349 nonstd::optional<ConstStructureField> contextField() const noexcept
351 const auto libObjPtr = _ConstSpec::contextField(this->libObjPtr());
354 return ConstStructureField {libObjPtr};
357 return nonstd::nullopt;
360 nonstd::optional<_StructureField> contextField() noexcept
362 const auto libObjPtr = _Spec::contextField(this->libObjPtr());
365 return _StructureField {libObjPtr};
368 return nonstd::nullopt;
371 Shared shared() const noexcept
373 return Shared::createWithRef(*this);
377 using Packet = CommonPacket<bt_packet>;
378 using ConstPacket = CommonPacket<const bt_packet>;
382 struct PacketTypeDescr
384 using Const = ConstPacket;
385 using NonConst = Packet;
389 struct TypeDescr<Packet> : public PacketTypeDescr
394 struct TypeDescr<ConstPacket> : public PacketTypeDescr
398 } /* namespace internal */
400 template <typename LibObjT>
401 nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
403 const auto libObjPtr = _ConstSpec::packet(this->libObjPtr());
406 return ConstPacket {libObjPtr};
409 return nonstd::nullopt;
412 template <typename LibObjT>
413 nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept
415 const auto libObjPtr = _Spec::packet(this->libObjPtr());
418 return _Packet {libObjPtr};
421 return nonstd::nullopt;
426 struct StreamRefFuncs final
428 static void get(const bt_stream * const libObjPtr)
430 bt_stream_get_ref(libObjPtr);
433 static void put(const bt_stream * const libObjPtr)
435 bt_stream_put_ref(libObjPtr);
439 template <typename LibObjT>
440 struct CommonStreamSpec;
442 /* Functions specific to mutable streams */
444 struct CommonStreamSpec<bt_stream> final
446 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
448 return bt_stream_borrow_class(libObjPtr);
451 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
453 return bt_stream_borrow_trace(libObjPtr);
456 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
458 return bt_stream_borrow_user_attributes(libObjPtr);
462 /* Functions specific to constant streams */
464 struct CommonStreamSpec<const bt_stream> final
466 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
468 return bt_stream_borrow_class_const(libObjPtr);
471 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
473 return bt_stream_borrow_trace_const(libObjPtr);
476 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
478 return bt_stream_borrow_user_attributes_const(libObjPtr);
482 } /* namespace internal */
484 template <typename LibObjT>
485 class CommonStream final : public BorrowedObject<LibObjT>
488 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
489 using typename BorrowedObject<LibObjT>::_LibObjPtr;
490 using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
491 using _Spec = internal::CommonStreamSpec<LibObjT>;
492 using _ThisCommonStream = CommonStream<LibObjT>;
495 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
496 CommonTrace<bt_trace>>::type;
499 using Shared = SharedObject<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
501 using Class = typename std::conditional<std::is_const<LibObjT>::value,
502 CommonStreamClass<const bt_stream_class>,
503 CommonStreamClass<bt_stream_class>>::type;
505 using UserAttributes =
506 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
508 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
512 template <typename OtherLibObjT>
513 CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
517 template <typename OtherLibObjT>
518 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
520 _ThisBorrowedObject::operator=(stream);
524 Packet::Shared createPacket()
526 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
528 const auto libObjPtr = bt_packet_create(this->libObjPtr());
530 internal::validateCreatedObjPtr(libObjPtr);
531 return Packet::Shared::createWithoutRef(libObjPtr);
534 CommonStreamClass<const bt_stream_class> cls() const noexcept;
535 Class cls() noexcept;
536 CommonTrace<const bt_trace> trace() const noexcept;
537 _Trace trace() noexcept;
539 std::uint64_t id() const noexcept
541 return bt_stream_get_id(this->libObjPtr());
544 void name(const char * const name)
546 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
548 const auto status = bt_stream_set_name(this->libObjPtr(), name);
550 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
551 throw MemoryError {};
555 void name(const std::string& name)
557 this->name(name.data());
560 nonstd::optional<bpstd::string_view> name() const noexcept
562 const auto name = bt_stream_get_name(this->libObjPtr());
568 return nonstd::nullopt;
571 template <typename LibValT>
572 void userAttributes(const CommonMapValue<LibValT> userAttrs)
574 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
576 bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
579 ConstMapValue userAttributes() const noexcept
581 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
584 UserAttributes userAttributes() noexcept
586 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
589 Shared shared() const noexcept
591 return Shared::createWithRef(*this);
595 using Stream = CommonStream<bt_stream>;
596 using ConstStream = CommonStream<const bt_stream>;
600 struct StreamTypeDescr
602 using Const = ConstStream;
603 using NonConst = Stream;
607 struct TypeDescr<Stream> : public StreamTypeDescr
612 struct TypeDescr<ConstStream> : public StreamTypeDescr
616 } /* namespace internal */
618 template <typename LibObjT>
619 ConstStream CommonEvent<LibObjT>::stream() const noexcept
621 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
624 template <typename LibObjT>
625 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept
627 return _Stream {_Spec::stream(this->libObjPtr())};
630 template <typename LibObjT>
631 ConstStream CommonPacket<LibObjT>::stream() const noexcept
633 return ConstStream {_ConstSpec::stream(this->libObjPtr())};
636 template <typename LibObjT>
637 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept
639 return _Stream {_Spec::stream(this->libObjPtr())};
644 struct TraceRefFuncs final
646 static void get(const bt_trace * const libObjPtr)
648 bt_trace_get_ref(libObjPtr);
651 static void put(const bt_trace * const libObjPtr)
653 bt_trace_put_ref(libObjPtr);
657 template <typename LibObjT>
658 struct CommonTraceSpec;
660 /* Functions specific to mutable traces */
662 struct CommonTraceSpec<bt_trace> final
664 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
666 return bt_trace_borrow_class(libObjPtr);
669 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
671 return bt_trace_borrow_stream_by_index(libObjPtr, index);
674 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
676 return bt_trace_borrow_stream_by_id(libObjPtr, id);
679 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
681 return bt_trace_borrow_user_attributes(libObjPtr);
685 /* Functions specific to constant traces */
687 struct CommonTraceSpec<const bt_trace> final
689 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
691 return bt_trace_borrow_class_const(libObjPtr);
694 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
695 const std::uint64_t index) noexcept
697 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
700 static const bt_stream *streamById(const bt_trace * const libObjPtr,
701 const std::uint64_t id) noexcept
703 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
706 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
708 return bt_trace_borrow_user_attributes_const(libObjPtr);
712 } /* namespace internal */
714 template <typename LibObjT>
715 class CommonTrace final : public BorrowedObject<LibObjT>
717 /* Allow instantiate() to call `trace.libObjPtr()` */
718 friend class CommonStreamClass<bt_stream_class>;
721 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
722 using typename BorrowedObject<LibObjT>::_LibObjPtr;
723 using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
724 using _Spec = internal::CommonTraceSpec<LibObjT>;
725 using _ThisCommonTrace = CommonTrace<LibObjT>;
728 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
729 CommonStream<bt_stream>>::type;
732 using Shared = SharedObject<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
734 using Class = typename std::conditional<std::is_const<LibObjT>::value,
735 CommonTraceClass<const bt_trace_class>,
736 CommonTraceClass<bt_trace_class>>::type;
738 using UserAttributes =
739 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
741 struct ConstEnvironmentEntry
743 bpstd::string_view name;
747 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
751 template <typename OtherLibObjT>
752 CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
756 template <typename OtherLibObjT>
757 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
759 _ThisBorrowedObject::operator=(trace);
763 CommonTraceClass<const bt_trace_class> cls() const noexcept;
764 Class cls() noexcept;
766 void name(const char * const name)
768 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
770 const auto status = bt_trace_set_name(this->libObjPtr(), name);
772 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
773 throw MemoryError {};
777 void name(const std::string& name)
779 this->name(name.data());
782 nonstd::optional<bpstd::string_view> name() const noexcept
784 const auto name = bt_trace_get_name(this->libObjPtr());
790 return nonstd::nullopt;
793 void uuid(const bt2_common::UuidView& uuid) noexcept
795 bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
798 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
800 const auto uuid = bt_trace_get_uuid(this->libObjPtr());
803 return bt2_common::UuidView {uuid};
806 return nonstd::nullopt;
809 std::uint64_t size() const noexcept
811 return bt_trace_get_stream_count(this->libObjPtr());
814 ConstStream operator[](const std::uint64_t index) const noexcept
816 return ConstStream {_ConstSpec::streamByIndex(this->libObjPtr(), index)};
819 _Stream operator[](const std::uint64_t index) noexcept
821 return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
824 nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept
826 const auto libObjPtr = _ConstSpec::streamById(this->libObjPtr(), id);
829 return ConstStream {libObjPtr};
832 return nonstd::nullopt;
835 nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept
837 const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
840 return _Stream {libObjPtr};
843 return nonstd::nullopt;
846 void environmentEntry(const char * const name, const std::int64_t val)
848 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
850 const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
852 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
853 throw MemoryError {};
857 void environmentEntry(const std::string& name, const std::int64_t val)
859 this->environmentEntry(name.data(), val);
862 void environmentEntry(const char * const name, const char * const val)
864 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
866 const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
868 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
869 throw MemoryError {};
873 void environmentEntry(const std::string& name, const char * const val)
875 this->environmentEntry(name.data(), val);
878 void environmentEntry(const char * const name, const std::string& val)
880 this->environmentEntry(name, val.data());
883 void environmentEntry(const std::string& name, const std::string& val)
885 this->environmentEntry(name.data(), val.data());
888 std::uint64_t environmentSize() const noexcept
890 return bt_trace_get_environment_entry_count(this->libObjPtr());
893 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
896 const bt_value *libObjPtr;
898 bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
900 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
903 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
905 const auto libObjPtr =
906 bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
909 return ConstValue {libObjPtr};
912 return nonstd::nullopt;
915 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
917 return this->environmentEntry(name.data());
920 template <typename LibValT>
921 void userAttributes(const CommonMapValue<LibValT> userAttrs)
923 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
925 bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
928 ConstMapValue userAttributes() const noexcept
930 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
933 UserAttributes userAttributes() noexcept
935 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
938 Shared shared() const noexcept
940 return Shared::createWithRef(*this);
944 using Trace = CommonTrace<bt_trace>;
945 using ConstTrace = CommonTrace<const bt_trace>;
949 struct TraceTypeDescr
951 using Const = ConstTrace;
952 using NonConst = Trace;
956 struct TypeDescr<Trace> : public TraceTypeDescr
961 struct TypeDescr<ConstTrace> : public TraceTypeDescr
965 } /* namespace internal */
967 template <typename LibObjT>
968 ConstTrace CommonStream<LibObjT>::trace() const noexcept
970 return ConstTrace {_ConstSpec::trace(this->libObjPtr())};
973 template <typename LibObjT>
974 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept
976 return _Trace {_Spec::trace(this->libObjPtr())};
981 struct EventClassRefFuncs final
983 static void get(const bt_event_class * const libObjPtr)
985 bt_event_class_get_ref(libObjPtr);
988 static void put(const bt_event_class * const libObjPtr)
990 bt_event_class_put_ref(libObjPtr);
994 template <typename LibObjT>
995 struct CommonEventClassSpec;
997 /* Functions specific to mutable event classes */
999 struct CommonEventClassSpec<bt_event_class> final
1001 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
1003 return bt_event_class_borrow_stream_class(libObjPtr);
1006 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
1008 return bt_event_class_borrow_payload_field_class(libObjPtr);
1011 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
1013 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
1016 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
1018 return bt_event_class_borrow_user_attributes(libObjPtr);
1022 /* Functions specific to constant event classes */
1024 struct CommonEventClassSpec<const bt_event_class> final
1026 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
1028 return bt_event_class_borrow_stream_class_const(libObjPtr);
1031 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
1033 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
1036 static const bt_field_class *
1037 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
1039 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
1042 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
1044 return bt_event_class_borrow_user_attributes_const(libObjPtr);
1048 } /* namespace internal */
1050 template <typename LibObjT>
1051 class CommonEventClass final : public BorrowedObject<LibObjT>
1054 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1055 using typename BorrowedObject<LibObjT>::_LibObjPtr;
1056 using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
1057 using _Spec = internal::CommonEventClassSpec<LibObjT>;
1058 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
1060 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1061 CommonStreamClass<const bt_stream_class>,
1062 CommonStreamClass<bt_stream_class>>::type;
1064 using _StructureFieldClass =
1065 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1066 StructureFieldClass>::type;
1069 using Shared = SharedObject<_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 : _ThisBorrowedObject {libObjPtr}
1097 template <typename OtherLibObjT>
1098 CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
1099 _ThisBorrowedObject {eventClass}
1103 template <typename OtherLibObjT>
1104 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
1106 _ThisBorrowedObject::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 BorrowedObject<LibObjT>
1429 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1430 using typename BorrowedObject<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;
1451 using Shared = SharedObject<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1453 using UserAttributes =
1454 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1456 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
1457 _ThisBorrowedObject {libObjPtr}
1461 template <typename OtherLibObjT>
1462 CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
1463 _ThisBorrowedObject {streamClass}
1467 template <typename OtherLibObjT>
1468 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
1470 _ThisBorrowedObject::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 BorrowedObject<LibObjT>
1922 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
1923 using typename BorrowedObject<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;
1933 using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1935 using UserAttributes =
1936 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1938 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
1942 template <typename OtherLibObjT>
1943 CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
1944 _ThisBorrowedObject {traceClass}
1948 template <typename OtherLibObjT>
1949 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
1951 _ThisBorrowedObject::operator=(traceClass);
1955 Trace::Shared instantiate()
1957 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1959 const auto libObjPtr = bt_trace_create(this->libObjPtr());
1961 internal::validateCreatedObjPtr(libObjPtr);
1962 return Trace::Shared::createWithoutRef(libObjPtr);
1965 StreamClass::Shared createStreamClass()
1967 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1969 const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
1971 internal::validateCreatedObjPtr(libObjPtr);
1972 return StreamClass::Shared::createWithoutRef(libObjPtr);
1975 StreamClass::Shared createStreamClass(const std::uint64_t id)
1977 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1979 const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
1981 internal::validateCreatedObjPtr(libObjPtr);
1982 return StreamClass::Shared::createWithoutRef(libObjPtr);
1985 FieldClass::Shared createBoolFieldClass()
1987 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1989 const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
1991 internal::validateCreatedObjPtr(libObjPtr);
1992 return FieldClass::Shared::createWithoutRef(libObjPtr);
1995 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length)
1997 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1999 const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
2001 internal::validateCreatedObjPtr(libObjPtr);
2002 return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2005 IntegerFieldClass::Shared createUnsignedIntegerFieldClass()
2007 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2009 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
2011 internal::validateCreatedObjPtr(libObjPtr);
2012 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2015 IntegerFieldClass::Shared createSignedIntegerFieldClass()
2017 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2019 const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
2021 internal::validateCreatedObjPtr(libObjPtr);
2022 return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
2025 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass()
2027 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2029 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
2031 internal::validateCreatedObjPtr(libObjPtr);
2032 return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2035 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass()
2037 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2039 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
2041 internal::validateCreatedObjPtr(libObjPtr);
2042 return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
2045 FieldClass::Shared createSinglePrecisionRealFieldClass()
2047 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2049 const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
2051 internal::validateCreatedObjPtr(libObjPtr);
2052 return FieldClass::Shared::createWithoutRef(libObjPtr);
2055 FieldClass::Shared createDoublePrecisionRealFieldClass()
2057 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2059 const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
2061 internal::validateCreatedObjPtr(libObjPtr);
2062 return FieldClass::Shared::createWithoutRef(libObjPtr);
2065 FieldClass::Shared createStringFieldClass()
2067 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2069 const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
2071 internal::validateCreatedObjPtr(libObjPtr);
2072 return FieldClass::Shared::createWithoutRef(libObjPtr);
2075 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
2076 const std::uint64_t length)
2078 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2080 const auto libObjPtr = bt_field_class_array_static_create(
2081 this->libObjPtr(), elementFieldClass.libObjPtr(), length);
2083 internal::validateCreatedObjPtr(libObjPtr);
2084 return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2087 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass)
2089 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2091 const auto libObjPtr = bt_field_class_array_dynamic_create(
2092 this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
2094 internal::validateCreatedObjPtr(libObjPtr);
2095 return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
2098 DynamicArrayWithLengthFieldClass::Shared
2099 createDynamicArrayFieldClass(const FieldClass elementFieldClass,
2100 const IntegerFieldClass lengthFieldClass)
2102 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2104 const auto libObjPtr = bt_field_class_array_dynamic_create(
2105 this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
2107 internal::validateCreatedObjPtr(libObjPtr);
2108 return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
2111 StructureFieldClass::Shared createStructureFieldClass()
2113 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2115 const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
2117 internal::validateCreatedObjPtr(libObjPtr);
2118 return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
2121 OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass)
2123 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2125 const auto libObjPtr = bt_field_class_option_without_selector_create(
2126 this->libObjPtr(), optionalFieldClass.libObjPtr());
2128 internal::validateCreatedObjPtr(libObjPtr);
2129 return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
2132 OptionWithBoolSelectorFieldClass::Shared
2133 createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
2134 const FieldClass selectorFieldClass)
2136 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2138 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
2139 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
2141 internal::validateCreatedObjPtr(libObjPtr);
2142 return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2145 OptionWithUnsignedIntegerSelectorFieldClass::Shared
2146 createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2147 const IntegerFieldClass selectorFieldClass,
2148 const ConstUnsignedIntegerRangeSet ranges)
2150 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2152 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
2153 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2154 ranges.libObjPtr());
2156 internal::validateCreatedObjPtr(libObjPtr);
2157 return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2160 OptionWithSignedIntegerSelectorFieldClass::Shared
2161 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
2162 const IntegerFieldClass selectorFieldClass,
2163 const ConstSignedIntegerRangeSet ranges)
2165 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2167 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
2168 this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
2169 ranges.libObjPtr());
2171 internal::validateCreatedObjPtr(libObjPtr);
2172 return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2175 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass()
2177 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2179 const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
2181 internal::validateCreatedObjPtr(libObjPtr);
2182 return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
2185 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2186 createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2188 return this->_createVariantWithIntegerSelectorFieldClass<
2189 VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
2192 VariantWithSignedIntegerSelectorFieldClass::Shared
2193 createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2195 return this->_createVariantWithIntegerSelectorFieldClass<
2196 VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
2199 void assignsAutomaticStreamClassId(const bool val) noexcept
2201 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2203 bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
2204 static_cast<bt_bool>(val));
2207 bool assignsAutomaticStreamClassId() const noexcept
2209 return static_cast<bool>(
2210 bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
2213 std::uint64_t size() const noexcept
2215 return bt_trace_class_get_stream_class_count(this->libObjPtr());
2218 ConstStreamClass operator[](const std::uint64_t index) const noexcept
2220 return ConstStreamClass {_ConstSpec::streamClassByIndex(this->libObjPtr(), index)};
2223 _StreamClass operator[](const std::uint64_t index) noexcept
2225 return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
2228 nonstd::optional<ConstStreamClass> streamClassById(const std::uint64_t id) const noexcept
2230 const auto libObjPtr = _ConstSpec::streamClassById(this->libObjPtr(), id);
2233 return ConstStreamClass {libObjPtr};
2236 return nonstd::nullopt;
2239 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) noexcept
2241 const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
2244 return _StreamClass {libObjPtr};
2247 return nonstd::nullopt;
2250 template <typename LibValT>
2251 void userAttributes(const CommonMapValue<LibValT> userAttrs)
2253 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2255 bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
2258 ConstMapValue userAttributes() const noexcept
2260 return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
2263 UserAttributes userAttributes() noexcept
2265 return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
2268 Shared shared() const noexcept
2270 return Shared::createWithRef(*this);
2274 template <typename ObjT>
2275 typename ObjT::Shared
2276 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
2278 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2280 const auto libObjPtr =
2281 bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
2283 internal::validateCreatedObjPtr(libObjPtr);
2284 return ObjT::Shared::createWithoutRef(libObjPtr);
2288 using TraceClass = CommonTraceClass<bt_trace_class>;
2289 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2291 namespace internal {
2293 struct TraceClassTypeDescr
2295 using Const = ConstTraceClass;
2296 using NonConst = TraceClass;
2300 struct TypeDescr<TraceClass> : public TraceClassTypeDescr
2305 struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
2309 } /* namespace internal */
2311 template <typename LibObjT>
2312 ConstTraceClass CommonStreamClass<LibObjT>::traceClass() const noexcept
2314 return ConstTraceClass {_ConstSpec::traceClass(this->libObjPtr())};
2317 template <typename LibObjT>
2318 typename CommonStreamClass<LibObjT>::_TraceClass CommonStreamClass<LibObjT>::traceClass() noexcept
2320 return _TraceClass {_Spec::traceClass(this->libObjPtr())};
2323 template <typename LibObjT>
2324 ConstTraceClass CommonTrace<LibObjT>::cls() const noexcept
2326 return ConstTraceClass {_ConstSpec::cls(this->libObjPtr())};
2329 template <typename LibObjT>
2330 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() noexcept
2332 return Class {_Spec::cls(this->libObjPtr())};
2335 } /* namespace bt2 */
2337 #endif /* BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP */