2 * Copyright (c) 2020-2021 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
10 #include <type_traits>
12 #include <babeltrace2/babeltrace.h>
14 #include "internal/borrowed-obj.hpp"
15 #include "cpp-common/optional.hpp"
16 #include "cpp-common/string_view.hpp"
17 #include "clock-class.hpp"
18 #include "clock-snapshot.hpp"
19 #include "field-class.hpp"
22 #include "internal/utils.hpp"
26 template <typename LibObjT>
29 template <typename LibObjT>
32 template <typename LibObjT>
35 template <typename LibObjT>
38 template <typename LibObjT>
39 class CommonEventClass;
41 template <typename LibObjT>
42 class CommonStreamClass;
44 template <typename LibObjT>
45 class CommonTraceClass;
49 template <typename LibObjT>
50 struct CommonEventSpec;
52 // Functions specific to mutable events
54 struct CommonEventSpec<bt_event> final
56 static bt_event_class *cls(bt_event * const libObjPtr) noexcept
58 return bt_event_borrow_class(libObjPtr);
61 static bt_stream *stream(bt_event * const libObjPtr) noexcept
63 return bt_event_borrow_stream(libObjPtr);
66 static bt_packet *packet(bt_event * const libObjPtr) noexcept
68 return bt_event_borrow_packet(libObjPtr);
71 static bt_field *payloadField(bt_event * const libObjPtr) noexcept
73 return bt_event_borrow_payload_field(libObjPtr);
76 static bt_field *specificContextField(bt_event * const libObjPtr) noexcept
78 return bt_event_borrow_specific_context_field(libObjPtr);
81 static bt_field *commonContextField(bt_event * const libObjPtr) noexcept
83 return bt_event_borrow_common_context_field(libObjPtr);
87 // Functions specific to constant events
89 struct CommonEventSpec<const bt_event> final
91 static const bt_event_class *cls(const bt_event * const libObjPtr) noexcept
93 return bt_event_borrow_class_const(libObjPtr);
96 static const bt_stream *stream(const bt_event * const libObjPtr) noexcept
98 return bt_event_borrow_stream_const(libObjPtr);
101 static const bt_packet *packet(const bt_event * const libObjPtr) noexcept
103 return bt_event_borrow_packet_const(libObjPtr);
106 static const bt_field *payloadField(const bt_event * const libObjPtr) noexcept
108 return bt_event_borrow_payload_field_const(libObjPtr);
111 static const bt_field *specificContextField(const bt_event * const libObjPtr) noexcept
113 return bt_event_borrow_specific_context_field_const(libObjPtr);
116 static const bt_field *commonContextField(const bt_event * const libObjPtr) noexcept
118 return bt_event_borrow_common_context_field_const(libObjPtr);
122 } // namespace internal
124 template <typename LibObjT>
125 class CommonEvent final : public internal::BorrowedObj<LibObjT>
128 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
129 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
130 using _ConstSpec = internal::CommonEventSpec<const bt_event>;
131 using _Spec = internal::CommonEventSpec<LibObjT>;
134 typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
135 CommonPacket<bt_packet>>::type;
138 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
139 CommonStream<bt_stream>>::type;
141 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
142 ConstStructureField, StructureField>::type;
145 using Class = typename std::conditional<std::is_const<LibObjT>::value,
146 CommonEventClass<const bt_event_class>,
147 CommonEventClass<bt_event_class>>::type;
149 explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
153 template <typename OtherLibObjT>
154 CommonEvent(const CommonEvent<OtherLibObjT>& event) noexcept : _ThisBorrowedObj {event}
158 template <typename OtherLibObjT>
159 CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT>& event) noexcept
161 _ThisBorrowedObj::operator=(event);
165 CommonEventClass<const bt_event_class> cls() const noexcept;
166 Class cls() noexcept;
167 CommonStream<const bt_stream> stream() const noexcept;
168 _Stream stream() noexcept;
169 nonstd::optional<CommonPacket<const bt_packet>> packet() const noexcept;
170 nonstd::optional<_Packet> packet() noexcept;
172 nonstd::optional<ConstStructureField> payloadField() const noexcept
174 const auto libObjPtr = _ConstSpec::payloadField(this->_libObjPtr());
177 return ConstStructureField {libObjPtr};
180 return nonstd::nullopt;
183 nonstd::optional<_StructureField> payloadField() noexcept
185 const auto libObjPtr = _Spec::payloadField(this->_libObjPtr());
188 return _StructureField {libObjPtr};
191 return nonstd::nullopt;
194 nonstd::optional<ConstStructureField> specificContextField() const noexcept
196 const auto libObjPtr = _ConstSpec::specificContextField(this->_libObjPtr());
199 return ConstStructureField {libObjPtr};
202 return nonstd::nullopt;
205 nonstd::optional<_StructureField> specificContextField() noexcept
207 const auto libObjPtr = _Spec::specificContextField(this->_libObjPtr());
210 return _StructureField {libObjPtr};
213 return nonstd::nullopt;
216 nonstd::optional<ConstStructureField> commonContextField() const noexcept
218 const auto libObjPtr = _ConstSpec::commonContextField(this->_libObjPtr());
221 return ConstStructureField {libObjPtr};
224 return nonstd::nullopt;
227 nonstd::optional<_StructureField> commonContextField() noexcept
229 const auto libObjPtr = _Spec::commonContextField(this->_libObjPtr());
232 return _StructureField {libObjPtr};
235 return nonstd::nullopt;
239 using Event = CommonEvent<bt_event>;
240 using ConstEvent = CommonEvent<const bt_event>;
244 struct PacketRefFuncs final
246 static void get(const bt_packet * const libObjPtr)
248 bt_packet_get_ref(libObjPtr);
251 static void put(const bt_packet * const libObjPtr)
253 bt_packet_put_ref(libObjPtr);
257 template <typename LibObjT>
258 struct CommonPacketSpec;
260 // Functions specific to mutable packets
262 struct CommonPacketSpec<bt_packet> final
264 static bt_stream *stream(bt_packet * const libObjPtr) noexcept
266 return bt_packet_borrow_stream(libObjPtr);
269 static bt_field *contextField(bt_packet * const libObjPtr) noexcept
271 return bt_packet_borrow_context_field(libObjPtr);
275 // Functions specific to constant packets
277 struct CommonPacketSpec<const bt_packet> final
279 static const bt_stream *stream(const bt_packet * const libObjPtr) noexcept
281 return bt_packet_borrow_stream_const(libObjPtr);
284 static const bt_field *contextField(const bt_packet * const libObjPtr) noexcept
286 return bt_packet_borrow_context_field_const(libObjPtr);
290 } // namespace internal
292 template <typename LibObjT>
293 class CommonPacket final : public internal::BorrowedObj<LibObjT>
296 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
297 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
298 using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
299 using _Spec = internal::CommonPacketSpec<LibObjT>;
300 using _ThisCommonPacket = CommonPacket<LibObjT>;
303 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
304 CommonStream<bt_stream>>::type;
306 using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
307 ConstStructureField, StructureField>::type;
310 using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
312 explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
316 template <typename OtherLibObjT>
317 CommonPacket(const CommonPacket<OtherLibObjT>& packet) noexcept : _ThisBorrowedObj {packet}
321 template <typename OtherLibObjT>
322 _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT>& packet) noexcept
324 _ThisBorrowedObj::operator=(packet);
328 CommonStream<const bt_stream> stream() const noexcept;
329 _Stream stream() noexcept;
331 nonstd::optional<ConstStructureField> contextField() const noexcept
333 const auto libObjPtr = _ConstSpec::contextField(this->_libObjPtr());
336 return ConstStructureField {libObjPtr};
339 return nonstd::nullopt;
342 nonstd::optional<_StructureField> contextField() noexcept
344 const auto libObjPtr = _Spec::contextField(this->_libObjPtr());
347 return _StructureField {libObjPtr};
350 return nonstd::nullopt;
353 Shared shared() const noexcept
355 return Shared {*this};
359 using Packet = CommonPacket<bt_packet>;
360 using ConstPacket = CommonPacket<const bt_packet>;
362 template <typename LibObjT>
363 nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
365 const auto libObjPtr = _ConstSpec::packet(this->_libObjPtr());
368 return ConstPacket {libObjPtr};
371 return nonstd::nullopt;
374 template <typename LibObjT>
375 nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept
377 const auto libObjPtr = _Spec::packet(this->_libObjPtr());
380 return _Packet {libObjPtr};
383 return nonstd::nullopt;
388 struct StreamRefFuncs final
390 static void get(const bt_stream * const libObjPtr)
392 bt_stream_get_ref(libObjPtr);
395 static void put(const bt_stream * const libObjPtr)
397 bt_stream_put_ref(libObjPtr);
401 template <typename LibObjT>
402 struct CommonStreamSpec;
404 // Functions specific to mutable streams
406 struct CommonStreamSpec<bt_stream> final
408 static bt_stream_class *cls(bt_stream * const libObjPtr) noexcept
410 return bt_stream_borrow_class(libObjPtr);
413 static bt_trace *trace(bt_stream * const libObjPtr) noexcept
415 return bt_stream_borrow_trace(libObjPtr);
418 static bt_value *userAttributes(bt_stream * const libObjPtr) noexcept
420 return bt_stream_borrow_user_attributes(libObjPtr);
424 // Functions specific to constant streams
426 struct CommonStreamSpec<const bt_stream> final
428 static const bt_stream_class *cls(const bt_stream * const libObjPtr) noexcept
430 return bt_stream_borrow_class_const(libObjPtr);
433 static const bt_trace *trace(const bt_stream * const libObjPtr) noexcept
435 return bt_stream_borrow_trace_const(libObjPtr);
438 static const bt_value *userAttributes(const bt_stream * const libObjPtr) noexcept
440 return bt_stream_borrow_user_attributes_const(libObjPtr);
444 } // namespace internal
446 template <typename LibObjT>
447 class CommonStream final : public internal::BorrowedObj<LibObjT>
450 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
451 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
452 using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
453 using _Spec = internal::CommonStreamSpec<LibObjT>;
454 using _ThisCommonStream = CommonStream<LibObjT>;
457 typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
458 CommonTrace<bt_trace>>::type;
461 using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
463 using Class = typename std::conditional<std::is_const<LibObjT>::value,
464 CommonStreamClass<const bt_stream_class>,
465 CommonStreamClass<bt_stream_class>>::type;
467 using UserAttributes =
468 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
470 explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
474 template <typename OtherLibObjT>
475 CommonStream(const CommonStream<OtherLibObjT>& stream) noexcept : _ThisBorrowedObj {stream}
479 template <typename OtherLibObjT>
480 _ThisCommonStream& operator=(const CommonStream<OtherLibObjT>& stream) noexcept
482 _ThisBorrowedObj::operator=(stream);
486 Packet::Shared createPacket()
488 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
490 const auto libObjPtr = bt_packet_create(this->_libObjPtr());
492 internal::validateCreatedObjPtr(libObjPtr);
493 return Packet::Shared {Packet {libObjPtr}};
496 CommonStreamClass<const bt_stream_class> cls() const noexcept;
497 Class cls() noexcept;
498 CommonTrace<const bt_trace> trace() const noexcept;
499 _Trace trace() noexcept;
501 std::uint64_t id() const noexcept
503 return bt_stream_get_id(this->_libObjPtr());
506 void name(const char * const name)
508 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
510 const auto status = bt_stream_set_name(this->_libObjPtr(), name);
512 if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
513 throw LibMemoryError {};
517 void name(const std::string& name)
519 this->name(name.data());
522 nonstd::optional<bpstd::string_view> name() const noexcept
524 const auto name = bt_stream_get_name(this->_libObjPtr());
530 return nonstd::nullopt;
533 template <typename LibValT>
534 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
536 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
538 bt_stream_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
541 ConstMapValue userAttributes() const noexcept
543 return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
546 UserAttributes userAttributes() noexcept
548 return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
551 Shared shared() const noexcept
553 return Shared {*this};
557 using Stream = CommonStream<bt_stream>;
558 using ConstStream = CommonStream<const bt_stream>;
560 template <typename LibObjT>
561 ConstStream CommonEvent<LibObjT>::stream() const noexcept
563 return ConstStream {_ConstSpec::stream(this->_libObjPtr())};
566 template <typename LibObjT>
567 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept
569 return _Stream {_Spec::stream(this->_libObjPtr())};
572 template <typename LibObjT>
573 ConstStream CommonPacket<LibObjT>::stream() const noexcept
575 return ConstStream {_ConstSpec::stream(this->_libObjPtr())};
578 template <typename LibObjT>
579 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept
581 return _Stream {_Spec::stream(this->_libObjPtr())};
586 struct TraceRefFuncs final
588 static void get(const bt_trace * const libObjPtr)
590 bt_trace_get_ref(libObjPtr);
593 static void put(const bt_trace * const libObjPtr)
595 bt_trace_put_ref(libObjPtr);
599 template <typename LibObjT>
600 struct CommonTraceSpec;
602 // Functions specific to mutable traces
604 struct CommonTraceSpec<bt_trace> final
606 static bt_trace_class *cls(bt_trace * const libObjPtr) noexcept
608 return bt_trace_borrow_class(libObjPtr);
611 static bt_stream *streamByIndex(bt_trace * const libObjPtr, const std::uint64_t index) noexcept
613 return bt_trace_borrow_stream_by_index(libObjPtr, index);
616 static bt_stream *streamById(bt_trace * const libObjPtr, const std::uint64_t id) noexcept
618 return bt_trace_borrow_stream_by_id(libObjPtr, id);
621 static bt_value *userAttributes(bt_trace * const libObjPtr) noexcept
623 return bt_trace_borrow_user_attributes(libObjPtr);
627 // Functions specific to constant traces
629 struct CommonTraceSpec<const bt_trace> final
631 static const bt_trace_class *cls(const bt_trace * const libObjPtr) noexcept
633 return bt_trace_borrow_class_const(libObjPtr);
636 static const bt_stream *streamByIndex(const bt_trace * const libObjPtr,
637 const std::uint64_t index) noexcept
639 return bt_trace_borrow_stream_by_index_const(libObjPtr, index);
642 static const bt_stream *streamById(const bt_trace * const libObjPtr,
643 const std::uint64_t id) noexcept
645 return bt_trace_borrow_stream_by_id_const(libObjPtr, id);
648 static const bt_value *userAttributes(const bt_trace * const libObjPtr) noexcept
650 return bt_trace_borrow_user_attributes_const(libObjPtr);
654 } // namespace internal
656 template <typename LibObjT>
657 class CommonTrace final : public internal::BorrowedObj<LibObjT>
659 // Allow instantiate() to call `trace._libObjPtr()`
660 friend class CommonStreamClass<bt_stream_class>;
663 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
664 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
665 using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
666 using _Spec = internal::CommonTraceSpec<LibObjT>;
667 using _ThisCommonTrace = CommonTrace<LibObjT>;
670 typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
671 CommonStream<bt_stream>>::type;
674 using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
676 using Class = typename std::conditional<std::is_const<LibObjT>::value,
677 CommonTraceClass<const bt_trace_class>,
678 CommonTraceClass<bt_trace_class>>::type;
680 using UserAttributes =
681 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
683 struct ConstEnvironmentEntry
685 bpstd::string_view name;
689 explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
693 template <typename OtherLibObjT>
694 CommonTrace(const CommonTrace<OtherLibObjT>& trace) noexcept : _ThisBorrowedObj {trace}
698 template <typename OtherLibObjT>
699 _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT>& trace) noexcept
701 _ThisBorrowedObj::operator=(trace);
705 CommonTraceClass<const bt_trace_class> cls() const noexcept;
706 Class cls() noexcept;
708 void name(const char * const name)
710 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
712 const auto status = bt_trace_set_name(this->_libObjPtr(), name);
714 if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
715 throw LibMemoryError {};
719 void name(const std::string& name)
721 this->name(name.data());
724 nonstd::optional<bpstd::string_view> name() const noexcept
726 const auto name = bt_trace_get_name(this->_libObjPtr());
732 return nonstd::nullopt;
735 void uuid(const std::uint8_t * const uuid) noexcept
737 bt_trace_set_uuid(this->_libObjPtr(), uuid);
740 nonstd::optional<bt2_common::UuidView> uuid() const noexcept
742 const auto uuid = bt_trace_get_uuid(this->_libObjPtr());
745 return bt2_common::UuidView {uuid};
748 return nonstd::nullopt;
751 std::uint64_t size() const noexcept
753 return bt_trace_get_stream_count(this->_libObjPtr());
756 ConstStream operator[](const std::uint64_t index) const noexcept
758 return ConstStream {_ConstSpec::streamByIndex(this->_libObjPtr(), index)};
761 _Stream operator[](const std::uint64_t index) noexcept
763 return _Stream {_Spec::streamByIndex(this->_libObjPtr(), index)};
766 nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept
768 const auto libObjPtr = _ConstSpec::streamById(this->_libObjPtr(), id);
771 return ConstStream {libObjPtr};
774 return nonstd::nullopt;
777 nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept
779 const auto libObjPtr = _Spec::streamById(this->_libObjPtr(), id);
782 return _Stream {libObjPtr};
785 return nonstd::nullopt;
788 void environmentEntry(const char * const name, const std::int64_t val)
790 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
792 const auto status = bt_trace_set_environment_entry_integer(this->_libObjPtr(), name, val);
794 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
795 throw LibMemoryError {};
799 void environmentEntry(const std::string& name, const std::int64_t val)
801 this->environmentEntry(name.data(), val);
804 void environmentEntry(const char * const name, const char * const val)
806 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
808 const auto status = bt_trace_set_environment_entry_string(this->_libObjPtr(), name, val);
810 if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
811 throw LibMemoryError {};
815 void environmentEntry(const std::string& name, const char * const val)
817 this->environmentEntry(name.data(), val);
820 void environmentEntry(const char * const name, const std::string& val)
822 this->environmentEntry(name, val.data());
825 void environmentEntry(const std::string& name, const std::string& val)
827 this->environmentEntry(name.data(), val.data());
830 std::uint64_t environmentSize() const noexcept
832 return bt_trace_get_environment_entry_count(this->_libObjPtr());
835 ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
838 const bt_value *libObjPtr;
840 bt_trace_borrow_environment_entry_by_index_const(this->_libObjPtr(), index, &name,
842 return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
845 nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
847 const auto libObjPtr =
848 bt_trace_borrow_environment_entry_value_by_name_const(this->_libObjPtr(), name);
851 return ConstValue {libObjPtr};
854 return nonstd::nullopt;
857 nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
859 return this->environmentEntry(name.data());
862 template <typename LibValT>
863 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
865 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
867 bt_trace_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
870 ConstMapValue userAttributes() const noexcept
872 return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
875 UserAttributes userAttributes() noexcept
877 return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
880 Shared shared() const noexcept
882 return Shared {*this};
886 using Trace = CommonTrace<bt_trace>;
887 using ConstTrace = CommonTrace<const bt_trace>;
889 template <typename LibObjT>
890 ConstTrace CommonStream<LibObjT>::trace() const noexcept
892 return ConstTrace {_ConstSpec::trace(this->_libObjPtr())};
895 template <typename LibObjT>
896 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept
898 return _Trace {_Spec::trace(this->_libObjPtr())};
903 struct EventClassRefFuncs final
905 static void get(const bt_event_class * const libObjPtr)
907 bt_event_class_get_ref(libObjPtr);
910 static void put(const bt_event_class * const libObjPtr)
912 bt_event_class_put_ref(libObjPtr);
916 template <typename LibObjT>
917 struct CommonEventClassSpec;
919 // Functions specific to mutable event classes
921 struct CommonEventClassSpec<bt_event_class> final
923 static bt_stream_class *streamClass(bt_event_class * const libObjPtr) noexcept
925 return bt_event_class_borrow_stream_class(libObjPtr);
928 static bt_field_class *payloadFieldClass(bt_event_class * const libObjPtr) noexcept
930 return bt_event_class_borrow_payload_field_class(libObjPtr);
933 static bt_field_class *specificContextFieldClass(bt_event_class * const libObjPtr) noexcept
935 return bt_event_class_borrow_specific_context_field_class(libObjPtr);
938 static bt_value *userAttributes(bt_event_class * const libObjPtr) noexcept
940 return bt_event_class_borrow_user_attributes(libObjPtr);
944 // Functions specific to constant event classes
946 struct CommonEventClassSpec<const bt_event_class> final
948 static const bt_stream_class *streamClass(const bt_event_class * const libObjPtr) noexcept
950 return bt_event_class_borrow_stream_class_const(libObjPtr);
953 static const bt_field_class *payloadFieldClass(const bt_event_class * const libObjPtr) noexcept
955 return bt_event_class_borrow_payload_field_class_const(libObjPtr);
958 static const bt_field_class *
959 specificContextFieldClass(const bt_event_class * const libObjPtr) noexcept
961 return bt_event_class_borrow_specific_context_field_class_const(libObjPtr);
964 static const bt_value *userAttributes(const bt_event_class * const libObjPtr) noexcept
966 return bt_event_class_borrow_user_attributes_const(libObjPtr);
970 } // namespace internal
972 template <typename LibObjT>
973 class CommonEventClass final : public internal::BorrowedObj<LibObjT>
976 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
977 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
978 using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
979 using _Spec = internal::CommonEventClassSpec<LibObjT>;
980 using _ThisCommonEventClass = CommonEventClass<LibObjT>;
982 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
983 CommonStreamClass<const bt_stream_class>,
984 CommonStreamClass<bt_stream_class>>::type;
986 using _StructureFieldClass =
987 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
988 StructureFieldClass>::type;
992 internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
994 using UserAttributes =
995 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
999 EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
1000 ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
1001 CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
1002 ERROR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
1003 WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
1004 NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
1005 INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
1006 DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
1007 DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
1008 DEBUG_PROCESS = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
1009 DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
1010 DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
1011 DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
1012 DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
1013 DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
1016 explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1020 template <typename OtherLibObjT>
1021 CommonEventClass(const CommonEventClass<OtherLibObjT>& eventClass) noexcept :
1022 _ThisBorrowedObj {eventClass}
1026 template <typename OtherLibObjT>
1027 _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT>& eventClass) noexcept
1029 _ThisBorrowedObj::operator=(eventClass);
1033 CommonStreamClass<const bt_stream_class> streamClass() const noexcept;
1034 _StreamClass streamClass() noexcept;
1036 std::uint64_t id() const noexcept
1038 return bt_event_class_get_id(this->_libObjPtr());
1041 void name(const char * const name)
1043 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1045 const auto status = bt_event_class_set_name(this->_libObjPtr(), name);
1047 if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1048 throw LibMemoryError {};
1052 void name(const std::string& name)
1054 this->name(name.data());
1057 nonstd::optional<bpstd::string_view> name() const noexcept
1059 const auto name = bt_event_class_get_name(this->_libObjPtr());
1065 return nonstd::nullopt;
1068 void logLevel(const LogLevel logLevel) noexcept
1070 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1072 bt_event_class_set_log_level(this->_libObjPtr(),
1073 static_cast<bt_event_class_log_level>(logLevel));
1076 nonstd::optional<LogLevel> logLevel() const noexcept
1078 bt_event_class_log_level libLogLevel;
1079 const auto avail = bt_event_class_get_log_level(this->_libObjPtr(), &libLogLevel);
1081 if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
1082 return static_cast<LogLevel>(libLogLevel);
1085 return nonstd::nullopt;
1088 void emfUri(const char * const emfUri)
1090 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1092 const auto status = bt_event_class_set_emf_uri(this->_libObjPtr(), emfUri);
1094 if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
1095 throw LibMemoryError {};
1099 void emfUri(const std::string& emfUri)
1101 this->emfUri(emfUri.data());
1104 nonstd::optional<bpstd::string_view> emfUri() const noexcept
1106 const auto emfUri = bt_event_class_get_emf_uri(this->_libObjPtr());
1112 return nonstd::nullopt;
1115 void payloadFieldClass(const StructureFieldClass& fc)
1117 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1120 bt_event_class_set_payload_field_class(this->_libObjPtr(), fc._libObjPtr());
1122 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1123 throw LibMemoryError {};
1127 nonstd::optional<ConstStructureFieldClass> payloadFieldClass() const noexcept
1129 const auto libObjPtr = _ConstSpec::payloadFieldClass(this->_libObjPtr());
1132 return ConstStructureFieldClass {libObjPtr};
1135 return nonstd::nullopt;
1138 nonstd::optional<_StructureFieldClass> payloadFieldClass() noexcept
1140 const auto libObjPtr = _Spec::payloadFieldClass(this->_libObjPtr());
1143 return _StructureFieldClass {libObjPtr};
1146 return nonstd::nullopt;
1149 void specificContextFieldClass(const StructureFieldClass& fc)
1151 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1154 bt_event_class_set_specificContext_field_class(this->_libObjPtr(), fc._libObjPtr());
1156 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1157 throw LibMemoryError {};
1161 nonstd::optional<ConstStructureFieldClass> specificContextFieldClass() const noexcept
1163 const auto libObjPtr = _ConstSpec::specificContextFieldClass(this->_libObjPtr());
1166 return ConstStructureFieldClass {libObjPtr};
1169 return nonstd::nullopt;
1172 nonstd::optional<_StructureFieldClass> specificContextFieldClass() noexcept
1174 const auto libObjPtr = _Spec::specificContextFieldClass(this->_libObjPtr());
1177 return _StructureFieldClass {libObjPtr};
1180 return nonstd::nullopt;
1183 template <typename LibValT>
1184 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
1186 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1188 bt_event_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
1191 ConstMapValue userAttributes() const noexcept
1193 return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
1196 UserAttributes userAttributes() noexcept
1198 return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
1201 Shared shared() const noexcept
1203 return Shared {*this};
1207 using EventClass = CommonEventClass<bt_event_class>;
1208 using ConstEventClass = CommonEventClass<const bt_event_class>;
1210 template <typename LibObjT>
1211 ConstEventClass CommonEvent<LibObjT>::cls() const noexcept
1213 return ConstEventClass {_ConstSpec::cls(this->_libObjPtr())};
1216 template <typename LibObjT>
1217 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() noexcept
1219 return Class {_Spec::cls(this->_libObjPtr())};
1222 namespace internal {
1224 struct StreamClassRefFuncs final
1226 static void get(const bt_stream_class * const libObjPtr)
1228 bt_stream_class_get_ref(libObjPtr);
1231 static void put(const bt_stream_class * const libObjPtr)
1233 bt_stream_class_put_ref(libObjPtr);
1237 template <typename LibObjT>
1238 struct CommonStreamClassSpec;
1240 // Functions specific to mutable stream classes
1242 struct CommonStreamClassSpec<bt_stream_class> final
1244 static bt_trace_class *traceClass(bt_stream_class * const libObjPtr) noexcept
1246 return bt_stream_class_borrow_trace_class(libObjPtr);
1249 static bt_event_class *eventClassByIndex(bt_stream_class * const libObjPtr,
1250 const std::uint64_t index) noexcept
1252 return bt_stream_class_borrow_event_class_by_index(libObjPtr, index);
1255 static bt_event_class *eventClassById(bt_stream_class * const libObjPtr,
1256 const std::uint64_t id) noexcept
1258 return bt_stream_class_borrow_event_class_by_id(libObjPtr, id);
1261 static bt_clock_class *defaultClockClass(bt_stream_class * const libObjPtr) noexcept
1263 return bt_stream_class_borrow_default_clock_class(libObjPtr);
1266 static bt_field_class *packetContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1268 return bt_stream_class_borrow_packet_context_field_class(libObjPtr);
1271 static bt_field_class *eventCommonContextFieldClass(bt_stream_class * const libObjPtr) noexcept
1273 return bt_stream_class_borrow_event_common_context_field_class(libObjPtr);
1276 static bt_value *userAttributes(bt_stream_class * const libObjPtr) noexcept
1278 return bt_stream_class_borrow_user_attributes(libObjPtr);
1282 // Functions specific to constant stream classes
1284 struct CommonStreamClassSpec<const bt_stream_class> final
1286 static const bt_trace_class *traceClass(const bt_stream_class * const libObjPtr) noexcept
1288 return bt_stream_class_borrow_trace_class_const(libObjPtr);
1291 static const bt_event_class *eventClassByIndex(const bt_stream_class * const libObjPtr,
1292 const std::uint64_t index) noexcept
1294 return bt_stream_class_borrow_event_class_by_index_const(libObjPtr, index);
1297 static const bt_event_class *eventClassById(const bt_stream_class * const libObjPtr,
1298 const std::uint64_t id) noexcept
1300 return bt_stream_class_borrow_event_class_by_id_const(libObjPtr, id);
1303 static const bt_clock_class *defaultClockClass(const bt_stream_class * const libObjPtr) noexcept
1305 return bt_stream_class_borrow_default_clock_class_const(libObjPtr);
1308 static const bt_field_class *
1309 packetContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1311 return bt_stream_class_borrow_packet_context_field_class_const(libObjPtr);
1314 static const bt_field_class *
1315 eventCommonContextFieldClass(const bt_stream_class * const libObjPtr) noexcept
1317 return bt_stream_class_borrow_event_common_context_field_class_const(libObjPtr);
1320 static const bt_value *userAttributes(const bt_stream_class * const libObjPtr) noexcept
1322 return bt_stream_class_borrow_user_attributes_const(libObjPtr);
1326 } // namespace internal
1328 template <typename LibObjT>
1329 class CommonStreamClass final : public internal::BorrowedObj<LibObjT>
1332 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1333 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1334 using _ConstSpec = internal::CommonStreamClassSpec<const bt_stream_class>;
1335 using _Spec = internal::CommonStreamClassSpec<LibObjT>;
1336 using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
1338 using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
1339 CommonTraceClass<const bt_trace_class>,
1340 CommonTraceClass<bt_trace_class>>::type;
1342 using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
1343 CommonEventClass<const bt_event_class>,
1344 CommonEventClass<bt_event_class>>::type;
1346 using _StructureFieldClass =
1347 typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
1348 StructureFieldClass>::type;
1351 typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
1355 internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
1357 using UserAttributes =
1358 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1360 explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1364 template <typename OtherLibObjT>
1365 CommonStreamClass(const CommonStreamClass<OtherLibObjT>& streamClass) noexcept :
1366 _ThisBorrowedObj {streamClass}
1370 template <typename OtherLibObjT>
1371 _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT>& streamClass) noexcept
1373 _ThisBorrowedObj::operator=(streamClass);
1377 Stream::Shared instantiate(const Trace& trace)
1379 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1381 const auto libObjPtr = bt_stream_create(this->_libObjPtr(), trace._libObjPtr());
1383 internal::validateCreatedObjPtr(libObjPtr);
1384 return Stream::Shared {Stream {libObjPtr}};
1387 Stream::Shared instantiate(const Trace& trace, const std::uint64_t id)
1389 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1391 const auto libObjPtr = bt_stream_create_with_id(this->_libObjPtr(), trace._libObjPtr(), id);
1393 internal::validateCreatedObjPtr(libObjPtr);
1394 return Stream::Shared {Stream {libObjPtr}};
1397 EventClass::Shared createEventClass()
1399 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1401 const auto libObjPtr = bt_event_class_create(this->_libObjPtr());
1403 internal::validateCreatedObjPtr(libObjPtr);
1404 return EventClass::Shared {EventClass {libObjPtr}};
1407 EventClass::Shared createEventClass(const std::uint64_t id)
1409 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1411 const auto libObjPtr = bt_event_class_create_with_id(this->_libObjPtr(), id);
1413 internal::validateCreatedObjPtr(libObjPtr);
1414 return EventClass::Shared {EventClass {libObjPtr}};
1417 CommonTraceClass<const bt_trace_class> traceClass() const noexcept;
1418 _TraceClass traceClass() noexcept;
1420 std::uint64_t id() const noexcept
1422 return bt_stream_class_get_id(this->_libObjPtr());
1425 void name(const char * const name)
1427 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1429 const auto status = bt_stream_class_set_name(this->_libObjPtr(), name);
1431 if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
1432 throw LibMemoryError {};
1436 void name(const std::string& name)
1438 this->name(name.data());
1441 nonstd::optional<bpstd::string_view> name() const noexcept
1443 const auto name = bt_stream_class_get_name(this->_libObjPtr());
1449 return nonstd::nullopt;
1452 void assignsAutomaticEventClassId(const bool val) noexcept
1454 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1456 bt_stream_class_set_assigns_automatic_event_class_id(this->_libObjPtr(),
1457 static_cast<bt_bool>(val));
1460 bool assignsAutomaticEventClassId() const noexcept
1462 return static_cast<bool>(
1463 bt_stream_class_assigns_automatic_event_class_id(this->_libObjPtr()));
1466 void assignsAutomaticStreamId(const bool val) noexcept
1468 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1470 bt_stream_class_set_assigns_automatic_stream_id(this->_libObjPtr(),
1471 static_cast<bt_bool>(val));
1474 bool assignsAutomaticStreamId() const noexcept
1476 return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->_libObjPtr()));
1479 void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
1480 const bool withEndDefaultClkSnapshot) noexcept
1482 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1484 bt_stream_class_set_supports_packets(this->_libObjPtr(),
1485 static_cast<bt_bool>(supportsPackets),
1486 static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
1487 static_cast<bt_bool>(withEndDefaultClkSnapshot));
1490 bool supportsPackets() const noexcept
1492 return static_cast<bool>(bt_stream_class_supports_packets(this->_libObjPtr()));
1495 bool packetsHaveBeginningClockSnapshot() const noexcept
1497 return static_cast<bool>(
1498 bt_stream_class_packets_have_beginning_default_clock_snapshot(this->_libObjPtr()));
1501 bool packetsHaveEndClockSnapshot() const noexcept
1503 return static_cast<bool>(
1504 bt_stream_class_packets_have_end_default_clock_snapshot(this->_libObjPtr()));
1507 void supportsDiscardedEvents(const bool supportsDiscardedEvents,
1508 const bool withDefaultClkSnapshots) noexcept
1510 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1512 bt_stream_class_set_supports_discarded_events(
1513 this->_libObjPtr(), static_cast<bt_bool>(supportsPackets),
1514 static_cast<bt_bool>(withDefaultClkSnapshots));
1517 bool supportsDiscardedEvents() const noexcept
1519 return static_cast<bool>(bt_stream_class_supports_discarded_events(this->_libObjPtr()));
1522 bool discardedEventsHaveDefaultClockSnapshots() const noexcept
1524 return static_cast<bool>(
1525 bt_stream_class_discarded_events_have_default_clock_snapshots(this->_libObjPtr()));
1528 void supportsDiscardedPackets(const bool supportsDiscardedPackets,
1529 const bool withDefaultClkSnapshots) noexcept
1531 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1533 bt_stream_class_set_supports_discarded_packets(
1534 this->_libObjPtr(), static_cast<bt_bool>(supportsPackets),
1535 static_cast<bt_bool>(withDefaultClkSnapshots));
1538 bool supportsDiscardedPackets() const noexcept
1540 return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->_libObjPtr()));
1543 bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
1545 return static_cast<bool>(
1546 bt_stream_class_discarded_packets_have_default_clock_snapshots(this->_libObjPtr()));
1549 void defaultClockClass(const ClockClass& clkCls)
1551 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1554 bt_stream_class_set_default_clock_class(this->_libObjPtr(), clkCls._libObjPtr());
1556 BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
1559 nonstd::optional<ConstClockClass> defaultClockClass() const noexcept
1561 const auto libObjPtr = _ConstSpec::defaultClockClass(this->_libObjPtr());
1564 return ConstClockClass {libObjPtr};
1567 return nonstd::nullopt;
1570 nonstd::optional<_ClockClass> defaultClockClass() noexcept
1572 const auto libObjPtr = _Spec::defaultClockClass(this->_libObjPtr());
1575 return _ClockClass {libObjPtr};
1578 return nonstd::nullopt;
1581 std::uint64_t size() const noexcept
1583 return bt_stream_class_get_event_class_count(this->_libObjPtr());
1586 ConstEventClass operator[](const std::uint64_t index) const noexcept
1588 return ConstEventClass {_ConstSpec::eventClassByIndex(this->_libObjPtr(), index)};
1591 _EventClass operator[](const std::uint64_t index) noexcept
1593 return _EventClass {_Spec::eventClassByIndex(this->_libObjPtr(), index)};
1596 nonstd::optional<ConstEventClass> eventClassById(const std::uint64_t id) const noexcept
1598 const auto libObjPtr = _ConstSpec::eventClassById(this->_libObjPtr(), id);
1601 return ConstEventClass {libObjPtr};
1604 return nonstd::nullopt;
1607 nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) noexcept
1609 const auto libObjPtr = _Spec::eventClassById(this->_libObjPtr(), id);
1612 return _EventClass {libObjPtr};
1615 return nonstd::nullopt;
1618 void packetContextFieldClass(const StructureFieldClass& fc)
1620 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1623 bt_stream_class_set_payload_field_class(this->_libObjPtr(), fc._libObjPtr());
1625 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1626 throw LibMemoryError {};
1630 nonstd::optional<ConstStructureFieldClass> packetContextFieldClass() const noexcept
1632 const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->_libObjPtr());
1635 return ConstStructureFieldClass {libObjPtr};
1638 return nonstd::nullopt;
1641 nonstd::optional<_StructureFieldClass> packetContextFieldClass() noexcept
1643 const auto libObjPtr = _Spec::packetContextFieldClass(this->_libObjPtr());
1646 return _StructureFieldClass {libObjPtr};
1649 return nonstd::nullopt;
1652 void eventCommonContextFieldClass(const StructureFieldClass& fc)
1654 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1657 bt_stream_class_set_specificContext_field_class(this->_libObjPtr(), fc._libObjPtr());
1659 if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
1660 throw LibMemoryError {};
1664 nonstd::optional<ConstStructureFieldClass> eventCommonContextFieldClass() const noexcept
1666 const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->_libObjPtr());
1669 return ConstStructureFieldClass {libObjPtr};
1672 return nonstd::nullopt;
1675 nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() noexcept
1677 const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->_libObjPtr());
1680 return _StructureFieldClass {libObjPtr};
1683 return nonstd::nullopt;
1686 template <typename LibValT>
1687 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
1689 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1691 bt_stream_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
1694 ConstMapValue userAttributes() const noexcept
1696 return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
1699 UserAttributes userAttributes() noexcept
1701 return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
1704 Shared shared() const noexcept
1706 return Shared {*this};
1710 using StreamClass = CommonStreamClass<bt_stream_class>;
1711 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
1713 template <typename LibObjT>
1714 ConstStreamClass CommonEventClass<LibObjT>::streamClass() const noexcept
1716 return ConstStreamClass {_ConstSpec::streamClass(this->_libObjPtr())};
1719 template <typename LibObjT>
1720 typename CommonEventClass<LibObjT>::_StreamClass CommonEventClass<LibObjT>::streamClass() noexcept
1722 return _StreamClass {_Spec::streamClass(this->_libObjPtr())};
1725 template <typename LibObjT>
1726 ConstStreamClass CommonStream<LibObjT>::cls() const noexcept
1728 return ConstStreamClass {_ConstSpec::cls(this->_libObjPtr())};
1731 template <typename LibObjT>
1732 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() noexcept
1734 return Class {_Spec::cls(this->_libObjPtr())};
1737 namespace internal {
1739 struct TraceClassRefFuncs final
1741 static void get(const bt_trace_class * const libObjPtr)
1743 bt_trace_class_get_ref(libObjPtr);
1746 static void put(const bt_trace_class * const libObjPtr)
1748 bt_trace_class_put_ref(libObjPtr);
1752 template <typename LibObjT>
1753 struct CommonTraceClassSpec;
1755 // Functions specific to mutable stream classes
1757 struct CommonTraceClassSpec<bt_trace_class> final
1759 static bt_stream_class *streamClassByIndex(bt_trace_class * const libObjPtr,
1760 const std::uint64_t index) noexcept
1762 return bt_trace_class_borrow_stream_class_by_index(libObjPtr, index);
1765 static bt_stream_class *streamClassById(bt_trace_class * const libObjPtr,
1766 const std::uint64_t id) noexcept
1768 return bt_trace_class_borrow_stream_class_by_id(libObjPtr, id);
1771 static bt_value *userAttributes(bt_trace_class * const libObjPtr) noexcept
1773 return bt_trace_class_borrow_user_attributes(libObjPtr);
1777 // Functions specific to constant stream classes
1779 struct CommonTraceClassSpec<const bt_trace_class> final
1781 static const bt_stream_class *streamClassByIndex(const bt_trace_class * const libObjPtr,
1782 const std::uint64_t index) noexcept
1784 return bt_trace_class_borrow_stream_class_by_index_const(libObjPtr, index);
1787 static const bt_stream_class *streamClassById(const bt_trace_class * const libObjPtr,
1788 const std::uint64_t id) noexcept
1790 return bt_trace_class_borrow_stream_class_by_id_const(libObjPtr, id);
1793 static const bt_value *userAttributes(const bt_trace_class * const libObjPtr) noexcept
1795 return bt_trace_class_borrow_user_attributes_const(libObjPtr);
1799 } // namespace internal
1801 template <typename LibObjT>
1802 class CommonTraceClass final : public internal::BorrowedObj<LibObjT>
1805 using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
1806 using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
1807 using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>;
1808 using _Spec = internal::CommonTraceClassSpec<LibObjT>;
1809 using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
1811 using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
1812 CommonStreamClass<const bt_stream_class>,
1813 CommonStreamClass<bt_stream_class>>::type;
1817 internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
1819 using UserAttributes =
1820 typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
1822 explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
1826 template <typename OtherLibObjT>
1827 CommonTraceClass(const CommonTraceClass<OtherLibObjT>& traceClass) noexcept :
1828 _ThisBorrowedObj {traceClass}
1832 template <typename OtherLibObjT>
1833 _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT>& traceClass) noexcept
1835 _ThisBorrowedObj::operator=(traceClass);
1839 Trace::Shared instantiate(const Trace& trace)
1841 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1843 const auto libObjPtr = bt_trace_create(this->_libObjPtr());
1845 internal::validateCreatedObjPtr(libObjPtr);
1846 return Trace::Shared {Trace {libObjPtr}};
1849 StreamClass::Shared createStreamClass()
1851 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1853 const auto libObjPtr = bt_stream_class_create(this->_libObjPtr());
1855 internal::validateCreatedObjPtr(libObjPtr);
1856 return StreamClass::Shared {StreamClass {libObjPtr}};
1859 StreamClass::Shared createStreamClass(const std::uint64_t id)
1861 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1863 const auto libObjPtr = bt_stream_class_create_with_id(this->_libObjPtr(), id);
1865 internal::validateCreatedObjPtr(libObjPtr);
1866 return StreamClass::Shared {StreamClass {libObjPtr}};
1869 FieldClass::Shared createBoolFieldClass()
1871 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1873 const auto libObjPtr = bt_field_class_bool_create(this->_libObjPtr());
1875 internal::validateCreatedObjPtr(libObjPtr);
1876 return FieldClass::Shared {FieldClass {libObjPtr}};
1879 BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length)
1881 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1883 const auto libObjPtr = bt_field_class_bit_array_create(this->_libObjPtr(), length);
1885 internal::validateCreatedObjPtr(libObjPtr);
1886 return BitArrayFieldClass::Shared {BitArrayFieldClass {libObjPtr}};
1889 IntegerFieldClass::Shared createUnsignedIntegerFieldClass()
1891 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1893 const auto libObjPtr = bt_field_class_integer_unsigned_create(this->_libObjPtr());
1895 internal::validateCreatedObjPtr(libObjPtr);
1896 return IntegerFieldClass::Shared {IntegerFieldClass {libObjPtr}};
1899 IntegerFieldClass::Shared createSignedIntegerFieldClass()
1901 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1903 const auto libObjPtr = bt_field_class_integer_signed_create(this->_libObjPtr());
1905 internal::validateCreatedObjPtr(libObjPtr);
1906 return IntegerFieldClass::Shared {IntegerFieldClass {libObjPtr}};
1909 UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass()
1911 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1913 const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->_libObjPtr());
1915 internal::validateCreatedObjPtr(libObjPtr);
1916 return UnsignedEnumerationFieldClass::Shared {UnsignedEnumerationFieldClass {libObjPtr}};
1919 SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass()
1921 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1923 const auto libObjPtr = bt_field_class_enumeration_signed_create(this->_libObjPtr());
1925 internal::validateCreatedObjPtr(libObjPtr);
1926 return SignedEnumerationFieldClass::Shared {SignedEnumerationFieldClass {libObjPtr}};
1929 FieldClass::Shared createSinglePrecisionRealFieldClass()
1931 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1933 const auto libObjPtr = bt_field_class_real_single_precision_create(this->_libObjPtr());
1935 internal::validateCreatedObjPtr(libObjPtr);
1936 return FieldClass::Shared {FieldClass {libObjPtr}};
1939 FieldClass::Shared createDoublePrecisionRealFieldClass()
1941 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1943 const auto libObjPtr = bt_field_class_real_double_precision_create(this->_libObjPtr());
1945 internal::validateCreatedObjPtr(libObjPtr);
1946 return FieldClass::Shared {FieldClass {libObjPtr}};
1949 FieldClass::Shared createStringFieldClass()
1951 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1953 const auto libObjPtr = bt_field_class_string_create(this->_libObjPtr());
1955 internal::validateCreatedObjPtr(libObjPtr);
1956 return FieldClass::Shared {FieldClass {libObjPtr}};
1959 StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass& elementFieldClass,
1960 const std::uint64_t length)
1962 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1964 const auto libObjPtr = bt_field_class_array_static_create(
1965 this->_libObjPtr(), elementFieldClass._libObjPtr(), length);
1967 internal::validateCreatedObjPtr(libObjPtr);
1968 return StaticArrayFieldClass::Shared {StaticArrayFieldClass {libObjPtr}};
1971 ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass& elementFieldClass)
1973 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1975 const auto libObjPtr = bt_field_class_array_dynamic_create(
1976 this->_libObjPtr(), elementFieldClass._libObjPtr(), nullptr);
1978 internal::validateCreatedObjPtr(libObjPtr);
1979 return ArrayFieldClass::Shared {ArrayFieldClass {libObjPtr}};
1982 DynamicArrayWithLengthFieldClass::Shared
1983 createDynamicArrayFieldClass(const FieldClass& elementFieldClass,
1984 const IntegerFieldClass& lengthFieldClass)
1986 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
1988 const auto libObjPtr = bt_field_class_array_dynamic_create(
1989 this->_libObjPtr(), elementFieldClass._libObjPtr(), lengthFieldClass._libObjPtr());
1991 internal::validateCreatedObjPtr(libObjPtr);
1992 return DynamicArrayWithLengthFieldClass::Shared {
1993 DynamicArrayWithLengthFieldClass {libObjPtr}};
1996 StructureFieldClass::Shared createStructureFieldClass(const std::uint64_t length)
1998 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2000 const auto libObjPtr = bt_field_class_structure_create(this->_libObjPtr(), length);
2002 internal::validateCreatedObjPtr(libObjPtr);
2003 return StructureFieldClass::Shared {StructureFieldClass {libObjPtr}};
2006 OptionFieldClass::Shared createOptionFieldClass(const FieldClass& optionalFieldClass)
2008 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2010 const auto libObjPtr = bt_field_class_option_without_selector_create(
2011 this->_libObjPtr(), optionalFieldClass._libObjPtr());
2013 internal::validateCreatedObjPtr(libObjPtr);
2014 return OptionFieldClass::Shared {OptionFieldClass {libObjPtr}};
2017 OptionWithBoolSelectorFieldClass::Shared
2018 createOptionWithBoolSelectorFieldClass(const FieldClass& optionalFieldClass,
2019 const FieldClass& selectorFieldClass)
2021 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2023 const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
2024 this->_libObjPtr(), optionalFieldClass._libObjPtr(), selectorFieldClass._libObjPtr());
2026 internal::validateCreatedObjPtr(libObjPtr);
2027 return OptionWithBoolSelectorFieldClass::Shared {
2028 OptionWithBoolSelectorFieldClass {libObjPtr}};
2031 OptionWithUnsignedIntegerSelectorFieldClass::Shared
2032 createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass& optionalFieldClass,
2033 const IntegerFieldClass& selectorFieldClass,
2034 const ConstUnsignedIntegerRangeSet& ranges)
2036 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2038 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
2039 this->_libObjPtr(), optionalFieldClass._libObjPtr(), selectorFieldClass._libObjPtr(),
2040 ranges._libObjPtr());
2042 internal::validateCreatedObjPtr(libObjPtr);
2043 return OptionWithUnsignedIntegerSelectorFieldClass::Shared {
2044 OptionWithUnsignedIntegerSelectorFieldClass {libObjPtr}};
2047 OptionWithSignedIntegerSelectorFieldClass::Shared
2048 createOptionWithSignedIntegerSelectorFieldClass(const FieldClass& optionalFieldClass,
2049 const IntegerFieldClass& selectorFieldClass,
2050 const ConstSignedIntegerRangeSet& ranges)
2052 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2054 const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
2055 this->_libObjPtr(), optionalFieldClass._libObjPtr(), selectorFieldClass._libObjPtr(),
2056 ranges._libObjPtr());
2058 internal::validateCreatedObjPtr(libObjPtr);
2059 return OptionWithSignedIntegerSelectorFieldClass::Shared {
2060 OptionWithSignedIntegerSelectorFieldClass {libObjPtr}};
2063 VariantWithoutSelectorFieldClass::Shared createVariantFieldClass()
2065 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2067 const auto libObjPtr = bt_field_class_variant_create(this->_libObjPtr());
2069 internal::validateCreatedObjPtr(libObjPtr);
2070 return VariantWithoutSelectorFieldClass::Shared {
2071 VariantWithoutSelectorFieldClass {libObjPtr}};
2074 VariantWithUnsignedIntegerSelectorFieldClass::Shared
2075 createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
2077 return VariantWithUnsignedIntegerSelectorFieldClass::Shared {
2078 VariantWithUnsignedIntegerSelectorFieldClass {
2079 this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}};
2082 VariantWithSignedIntegerSelectorFieldClass::Shared
2083 createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
2085 return VariantWithSignedIntegerSelectorFieldClass::Shared {
2086 VariantWithSignedIntegerSelectorFieldClass {
2087 this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}};
2090 void assignsAutomaticStreamClassId(const bool val) noexcept
2092 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2094 bt_trace_class_set_assigns_automatic_stream_class_id(this->_libObjPtr(),
2095 static_cast<bt_bool>(val));
2098 bool assignsAutomaticStreamClassId() const noexcept
2100 return static_cast<bool>(
2101 bt_trace_class_assigns_automatic_stream_class_id(this->_libObjPtr()));
2104 std::uint64_t size() const noexcept
2106 return bt_trace_class_get_stream_class_count(this->_libObjPtr());
2109 ConstStreamClass operator[](const std::uint64_t index) const noexcept
2111 return ConstStreamClass {_ConstSpec::streamClassByIndex(this->_libObjPtr(), index)};
2114 _StreamClass operator[](const std::uint64_t index) noexcept
2116 return _StreamClass {_Spec::streamClassByIndex(this->_libObjPtr(), index)};
2119 nonstd::optional<ConstStreamClass> streamClassById(const std::uint64_t id) const noexcept
2121 const auto libObjPtr = _ConstSpec::streamClassById(this->_libObjPtr(), id);
2124 return ConstStreamClass {libObjPtr};
2127 return nonstd::nullopt;
2130 nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) noexcept
2132 const auto libObjPtr = _Spec::streamClassById(this->_libObjPtr(), id);
2135 return _StreamClass {libObjPtr};
2138 return nonstd::nullopt;
2141 template <typename LibValT>
2142 void userAttributes(const CommonMapValue<LibValT>& userAttrs)
2144 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2146 bt_trace_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
2149 ConstMapValue userAttributes() const noexcept
2151 return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
2154 UserAttributes userAttributes() noexcept
2156 return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
2159 Shared shared() const noexcept
2161 return Shared {*this};
2166 _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
2168 static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
2170 const auto libObjPtr =
2171 bt_field_class_variant_create(this->_libObjPtr(), selectorFieldClass._libObjPtr());
2173 internal::validateCreatedObjPtr(libObjPtr);
2178 using TraceClass = CommonTraceClass<bt_trace_class>;
2179 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
2181 template <typename LibObjT>
2182 ConstTraceClass CommonStreamClass<LibObjT>::traceClass() const noexcept
2184 return ConstTraceClass {_ConstSpec::traceClass(this->_libObjPtr())};
2187 template <typename LibObjT>
2188 typename CommonStreamClass<LibObjT>::_TraceClass CommonStreamClass<LibObjT>::traceClass() noexcept
2190 return _TraceClass {_Spec::traceClass(this->_libObjPtr())};
2193 template <typename LibObjT>
2194 ConstTraceClass CommonTrace<LibObjT>::cls() const noexcept
2196 return ConstTraceClass {_ConstSpec::cls(this->_libObjPtr())};
2199 template <typename LibObjT>
2200 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() noexcept
2202 return Class {_Spec::cls(this->_libObjPtr())};
2207 #endif // BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP