Sort includes in C++ files
[babeltrace.git] / src / cpp-common / bt2 / trace-ir.hpp
index 44d84b6d3eb8413d4cc26cbffe80a77889b588b7..b61394e71d8ff8d641c3aafc9083c5a5ffe68bbe 100644 (file)
@@ -7,19 +7,21 @@
 #ifndef BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
 #define BABELTRACE_CPP_COMMON_BT2_TRACE_IR_HPP
 
-#include <type_traits>
 #include <cstdint>
+#include <type_traits>
+
 #include <babeltrace2/babeltrace.h>
 
-#include "internal/borrowed-obj.hpp"
 #include "cpp-common/optional.hpp"
 #include "cpp-common/string_view.hpp"
+
 #include "clock-class.hpp"
 #include "clock-snapshot.hpp"
 #include "field-class.hpp"
 #include "field.hpp"
-#include "value.hpp"
+#include "internal/borrowed-obj.hpp"
 #include "internal/utils.hpp"
+#include "value.hpp"
 
 namespace bt2 {
 
@@ -151,12 +153,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonEvent(const CommonEvent<OtherLibObjT>& event) noexcept : _ThisBorrowedObj {event}
+    CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObj {event}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT>& event) noexcept
+    CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
     {
         _ThisBorrowedObj::operator=(event);
         return *this;
@@ -171,7 +173,7 @@ public:
 
     nonstd::optional<ConstStructureField> payloadField() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::payloadField(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::payloadField(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureField {libObjPtr};
@@ -182,7 +184,7 @@ public:
 
     nonstd::optional<_StructureField> payloadField() noexcept
     {
-        const auto libObjPtr = _Spec::payloadField(this->_libObjPtr());
+        const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureField {libObjPtr};
@@ -193,7 +195,7 @@ public:
 
     nonstd::optional<ConstStructureField> specificContextField() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::specificContextField(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::specificContextField(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureField {libObjPtr};
@@ -204,7 +206,7 @@ public:
 
     nonstd::optional<_StructureField> specificContextField() noexcept
     {
-        const auto libObjPtr = _Spec::specificContextField(this->_libObjPtr());
+        const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureField {libObjPtr};
@@ -215,7 +217,7 @@ public:
 
     nonstd::optional<ConstStructureField> commonContextField() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::commonContextField(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::commonContextField(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureField {libObjPtr};
@@ -226,7 +228,7 @@ public:
 
     nonstd::optional<_StructureField> commonContextField() noexcept
     {
-        const auto libObjPtr = _Spec::commonContextField(this->_libObjPtr());
+        const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureField {libObjPtr};
@@ -241,6 +243,22 @@ using ConstEvent = CommonEvent<const bt_event>;
 
 namespace internal {
 
+struct EventTypeDescr
+{
+    using Const = ConstEvent;
+    using NonConst = Event;
+};
+
+template <>
+struct TypeDescr<Event> : public EventTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstEvent> : public EventTypeDescr
+{
+};
+
 struct PacketRefFuncs final
 {
     static void get(const bt_packet * const libObjPtr)
@@ -314,12 +332,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonPacket(const CommonPacket<OtherLibObjT>& packet) noexcept : _ThisBorrowedObj {packet}
+    CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObj {packet}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT>& packet) noexcept
+    _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
     {
         _ThisBorrowedObj::operator=(packet);
         return *this;
@@ -330,7 +348,7 @@ public:
 
     nonstd::optional<ConstStructureField> contextField() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::contextField(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::contextField(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureField {libObjPtr};
@@ -341,7 +359,7 @@ public:
 
     nonstd::optional<_StructureField> contextField() noexcept
     {
-        const auto libObjPtr = _Spec::contextField(this->_libObjPtr());
+        const auto libObjPtr = _Spec::contextField(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureField {libObjPtr};
@@ -352,17 +370,37 @@ public:
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 };
 
 using Packet = CommonPacket<bt_packet>;
 using ConstPacket = CommonPacket<const bt_packet>;
 
+namespace internal {
+
+struct PacketTypeDescr
+{
+    using Const = ConstPacket;
+    using NonConst = Packet;
+};
+
+template <>
+struct TypeDescr<Packet> : public PacketTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstPacket> : public PacketTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
 {
-    const auto libObjPtr = _ConstSpec::packet(this->_libObjPtr());
+    const auto libObjPtr = _ConstSpec::packet(this->libObjPtr());
 
     if (libObjPtr) {
         return ConstPacket {libObjPtr};
@@ -374,7 +412,7 @@ nonstd::optional<ConstPacket> CommonEvent<LibObjT>::packet() const noexcept
 template <typename LibObjT>
 nonstd::optional<typename CommonEvent<LibObjT>::_Packet> CommonEvent<LibObjT>::packet() noexcept
 {
-    const auto libObjPtr = _Spec::packet(this->_libObjPtr());
+    const auto libObjPtr = _Spec::packet(this->libObjPtr());
 
     if (libObjPtr) {
         return _Packet {libObjPtr};
@@ -472,12 +510,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStream(const CommonStream<OtherLibObjT>& stream) noexcept : _ThisBorrowedObj {stream}
+    CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObj {stream}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonStream& operator=(const CommonStream<OtherLibObjT>& stream) noexcept
+    _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
     {
         _ThisBorrowedObj::operator=(stream);
         return *this;
@@ -487,10 +525,10 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_packet_create(this->_libObjPtr());
+        const auto libObjPtr = bt_packet_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return Packet::Shared {Packet {libObjPtr}};
+        return Packet::Shared::createWithoutRef(libObjPtr);
     }
 
     CommonStreamClass<const bt_stream_class> cls() const noexcept;
@@ -500,17 +538,17 @@ public:
 
     std::uint64_t id() const noexcept
     {
-        return bt_stream_get_id(this->_libObjPtr());
+        return bt_stream_get_id(this->libObjPtr());
     }
 
     void name(const char * const name)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_stream_set_name(this->_libObjPtr(), name);
+        const auto status = bt_stream_set_name(this->libObjPtr(), name);
 
         if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -521,7 +559,7 @@ public:
 
     nonstd::optional<bpstd::string_view> name() const noexcept
     {
-        const auto name = bt_stream_get_name(this->_libObjPtr());
+        const auto name = bt_stream_get_name(this->libObjPtr());
 
         if (name) {
             return name;
@@ -531,54 +569,74 @@ public:
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    void userAttributes(const CommonMapValue<LibValT> userAttrs)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_stream_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
+        bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
 
     ConstMapValue userAttributes() const noexcept
     {
-        return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
+        return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
     }
 
     UserAttributes userAttributes() noexcept
     {
-        return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
+        return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
     }
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 };
 
 using Stream = CommonStream<bt_stream>;
 using ConstStream = CommonStream<const bt_stream>;
 
+namespace internal {
+
+struct StreamTypeDescr
+{
+    using Const = ConstStream;
+    using NonConst = Stream;
+};
+
+template <>
+struct TypeDescr<Stream> : public StreamTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStream> : public StreamTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 ConstStream CommonEvent<LibObjT>::stream() const noexcept
 {
-    return ConstStream {_ConstSpec::stream(this->_libObjPtr())};
+    return ConstStream {_ConstSpec::stream(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonEvent<LibObjT>::_Stream CommonEvent<LibObjT>::stream() noexcept
 {
-    return _Stream {_Spec::stream(this->_libObjPtr())};
+    return _Stream {_Spec::stream(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 ConstStream CommonPacket<LibObjT>::stream() const noexcept
 {
-    return ConstStream {_ConstSpec::stream(this->_libObjPtr())};
+    return ConstStream {_ConstSpec::stream(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonPacket<LibObjT>::_Stream CommonPacket<LibObjT>::stream() noexcept
 {
-    return _Stream {_Spec::stream(this->_libObjPtr())};
+    return _Stream {_Spec::stream(this->libObjPtr())};
 }
 
 namespace internal {
@@ -656,7 +714,7 @@ struct CommonTraceSpec<const bt_trace> final
 template <typename LibObjT>
 class CommonTrace final : public internal::BorrowedObj<LibObjT>
 {
-    /* Allow instantiate() to call `trace._libObjPtr()` */
+    /* Allow instantiate() to call `trace.libObjPtr()` */
     friend class CommonStreamClass<bt_stream_class>;
 
 private:
@@ -691,12 +749,12 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonTrace(const CommonTrace<OtherLibObjT>& trace) noexcept : _ThisBorrowedObj {trace}
+    CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObj {trace}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT>& trace) noexcept
+    _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
     {
         _ThisBorrowedObj::operator=(trace);
         return *this;
@@ -709,10 +767,10 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_trace_set_name(this->_libObjPtr(), name);
+        const auto status = bt_trace_set_name(this->libObjPtr(), name);
 
         if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -723,7 +781,7 @@ public:
 
     nonstd::optional<bpstd::string_view> name() const noexcept
     {
-        const auto name = bt_trace_get_name(this->_libObjPtr());
+        const auto name = bt_trace_get_name(this->libObjPtr());
 
         if (name) {
             return name;
@@ -732,14 +790,14 @@ public:
         return nonstd::nullopt;
     }
 
-    void uuid(const std::uint8_t * const uuid) noexcept
+    void uuid(const bt2_common::UuidView& uuid) noexcept
     {
-        bt_trace_set_uuid(this->_libObjPtr(), uuid);
+        bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
     }
 
     nonstd::optional<bt2_common::UuidView> uuid() const noexcept
     {
-        const auto uuid = bt_trace_get_uuid(this->_libObjPtr());
+        const auto uuid = bt_trace_get_uuid(this->libObjPtr());
 
         if (uuid) {
             return bt2_common::UuidView {uuid};
@@ -750,22 +808,22 @@ public:
 
     std::uint64_t size() const noexcept
     {
-        return bt_trace_get_stream_count(this->_libObjPtr());
+        return bt_trace_get_stream_count(this->libObjPtr());
     }
 
     ConstStream operator[](const std::uint64_t index) const noexcept
     {
-        return ConstStream {_ConstSpec::streamByIndex(this->_libObjPtr(), index)};
+        return ConstStream {_ConstSpec::streamByIndex(this->libObjPtr(), index)};
     }
 
     _Stream operator[](const std::uint64_t index) noexcept
     {
-        return _Stream {_Spec::streamByIndex(this->_libObjPtr(), index)};
+        return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
     }
 
     nonstd::optional<ConstStream> streamById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _ConstSpec::streamById(this->_libObjPtr(), id);
+        const auto libObjPtr = _ConstSpec::streamById(this->libObjPtr(), id);
 
         if (libObjPtr) {
             return ConstStream {libObjPtr};
@@ -776,7 +834,7 @@ public:
 
     nonstd::optional<_Stream> streamById(const std::uint64_t id) noexcept
     {
-        const auto libObjPtr = _Spec::streamById(this->_libObjPtr(), id);
+        const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
 
         if (libObjPtr) {
             return _Stream {libObjPtr};
@@ -789,10 +847,10 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_trace_set_environment_entry_integer(this->_libObjPtr(), name, val);
+        const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
 
         if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -805,10 +863,10 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_trace_set_environment_entry_string(this->_libObjPtr(), name, val);
+        const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
 
         if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -829,7 +887,7 @@ public:
 
     std::uint64_t environmentSize() const noexcept
     {
-        return bt_trace_get_environment_entry_count(this->_libObjPtr());
+        return bt_trace_get_environment_entry_count(this->libObjPtr());
     }
 
     ConstEnvironmentEntry environmentEntry(const std::uint64_t index) const noexcept
@@ -837,7 +895,7 @@ public:
         const char *name;
         const bt_value *libObjPtr;
 
-        bt_trace_borrow_environment_entry_by_index_const(this->_libObjPtr(), index, &name,
+        bt_trace_borrow_environment_entry_by_index_const(this->libObjPtr(), index, &name,
                                                          &libObjPtr);
         return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
     }
@@ -845,7 +903,7 @@ public:
     nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
     {
         const auto libObjPtr =
-            bt_trace_borrow_environment_entry_value_by_name_const(this->_libObjPtr(), name);
+            bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
 
         if (libObjPtr) {
             return ConstValue {libObjPtr};
@@ -860,42 +918,62 @@ public:
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    void userAttributes(const CommonMapValue<LibValT> userAttrs)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_trace_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
+        bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
 
     ConstMapValue userAttributes() const noexcept
     {
-        return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
+        return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
     }
 
     UserAttributes userAttributes() noexcept
     {
-        return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
+        return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
     }
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 };
 
 using Trace = CommonTrace<bt_trace>;
 using ConstTrace = CommonTrace<const bt_trace>;
 
+namespace internal {
+
+struct TraceTypeDescr
+{
+    using Const = ConstTrace;
+    using NonConst = Trace;
+};
+
+template <>
+struct TypeDescr<Trace> : public TraceTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstTrace> : public TraceTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 ConstTrace CommonStream<LibObjT>::trace() const noexcept
 {
-    return ConstTrace {_ConstSpec::trace(this->_libObjPtr())};
+    return ConstTrace {_ConstSpec::trace(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonStream<LibObjT>::_Trace CommonStream<LibObjT>::trace() noexcept
 {
-    return _Trace {_Spec::trace(this->_libObjPtr())};
+    return _Trace {_Spec::trace(this->libObjPtr())};
 }
 
 namespace internal {
@@ -1018,13 +1096,13 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonEventClass(const CommonEventClass<OtherLibObjT>& eventClass) noexcept :
+    CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
         _ThisBorrowedObj {eventClass}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT>& eventClass) noexcept
+    _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
     {
         _ThisBorrowedObj::operator=(eventClass);
         return *this;
@@ -1035,17 +1113,17 @@ public:
 
     std::uint64_t id() const noexcept
     {
-        return bt_event_class_get_id(this->_libObjPtr());
+        return bt_event_class_get_id(this->libObjPtr());
     }
 
     void name(const char * const name)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_event_class_set_name(this->_libObjPtr(), name);
+        const auto status = bt_event_class_set_name(this->libObjPtr(), name);
 
         if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1056,7 +1134,7 @@ public:
 
     nonstd::optional<bpstd::string_view> name() const noexcept
     {
-        const auto name = bt_event_class_get_name(this->_libObjPtr());
+        const auto name = bt_event_class_get_name(this->libObjPtr());
 
         if (name) {
             return name;
@@ -1069,14 +1147,14 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_event_class_set_log_level(this->_libObjPtr(),
+        bt_event_class_set_log_level(this->libObjPtr(),
                                      static_cast<bt_event_class_log_level>(logLevel));
     }
 
     nonstd::optional<LogLevel> logLevel() const noexcept
     {
         bt_event_class_log_level libLogLevel;
-        const auto avail = bt_event_class_get_log_level(this->_libObjPtr(), &libLogLevel);
+        const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
 
         if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
             return static_cast<LogLevel>(libLogLevel);
@@ -1089,10 +1167,10 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_event_class_set_emf_uri(this->_libObjPtr(), emfUri);
+        const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
 
         if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1103,7 +1181,7 @@ public:
 
     nonstd::optional<bpstd::string_view> emfUri() const noexcept
     {
-        const auto emfUri = bt_event_class_get_emf_uri(this->_libObjPtr());
+        const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
 
         if (emfUri) {
             return emfUri;
@@ -1112,21 +1190,21 @@ public:
         return nonstd::nullopt;
     }
 
-    void payloadFieldClass(const StructureFieldClass& fc)
+    void payloadFieldClass(const StructureFieldClass fc)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_event_class_set_payload_field_class(this->_libObjPtr(), fc._libObjPtr());
+            bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
 
         if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
     nonstd::optional<ConstStructureFieldClass> payloadFieldClass() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::payloadFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::payloadFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureFieldClass {libObjPtr};
@@ -1137,7 +1215,7 @@ public:
 
     nonstd::optional<_StructureFieldClass> payloadFieldClass() noexcept
     {
-        const auto libObjPtr = _Spec::payloadFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureFieldClass {libObjPtr};
@@ -1146,21 +1224,21 @@ public:
         return nonstd::nullopt;
     }
 
-    void specificContextFieldClass(const StructureFieldClass& fc)
+    void specificContextFieldClass(const StructureFieldClass fc)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_event_class_set_specific_context_field_class(this->_libObjPtr(), fc._libObjPtr());
+            bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
 
         if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
     nonstd::optional<ConstStructureFieldClass> specificContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::specificContextFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::specificContextFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureFieldClass {libObjPtr};
@@ -1171,7 +1249,7 @@ public:
 
     nonstd::optional<_StructureFieldClass> specificContextFieldClass() noexcept
     {
-        const auto libObjPtr = _Spec::specificContextFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureFieldClass {libObjPtr};
@@ -1181,42 +1259,62 @@ public:
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    void userAttributes(const CommonMapValue<LibValT> userAttrs)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_event_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
+        bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
 
     ConstMapValue userAttributes() const noexcept
     {
-        return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
+        return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
     }
 
     UserAttributes userAttributes() noexcept
     {
-        return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
+        return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
     }
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 };
 
 using EventClass = CommonEventClass<bt_event_class>;
 using ConstEventClass = CommonEventClass<const bt_event_class>;
 
+namespace internal {
+
+struct EventClassTypeDescr
+{
+    using Const = ConstEventClass;
+    using NonConst = EventClass;
+};
+
+template <>
+struct TypeDescr<EventClass> : public EventClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstEventClass> : public EventClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 ConstEventClass CommonEvent<LibObjT>::cls() const noexcept
 {
-    return ConstEventClass {_ConstSpec::cls(this->_libObjPtr())};
+    return ConstEventClass {_ConstSpec::cls(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonEvent<LibObjT>::Class CommonEvent<LibObjT>::cls() noexcept
 {
-    return Class {_Spec::cls(this->_libObjPtr())};
+    return Class {_Spec::cls(this->libObjPtr())};
 }
 
 namespace internal {
@@ -1362,56 +1460,56 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStreamClass(const CommonStreamClass<OtherLibObjT>& streamClass) noexcept :
+    CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
         _ThisBorrowedObj {streamClass}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT>& streamClass) noexcept
+    _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
     {
         _ThisBorrowedObj::operator=(streamClass);
         return *this;
     }
 
-    Stream::Shared instantiate(const Trace& trace)
+    Stream::Shared instantiate(const Trace trace)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_stream_create(this->_libObjPtr(), trace._libObjPtr());
+        const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return Stream::Shared {Stream {libObjPtr}};
+        return Stream::Shared::createWithoutRef(libObjPtr);
     }
 
-    Stream::Shared instantiate(const Trace& trace, const std::uint64_t id)
+    Stream::Shared instantiate(const Trace trace, const std::uint64_t id)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_stream_create_with_id(this->_libObjPtr(), trace._libObjPtr(), id);
+        const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return Stream::Shared {Stream {libObjPtr}};
+        return Stream::Shared::createWithoutRef(libObjPtr);
     }
 
     EventClass::Shared createEventClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_event_class_create(this->_libObjPtr());
+        const auto libObjPtr = bt_event_class_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return EventClass::Shared {EventClass {libObjPtr}};
+        return EventClass::Shared::createWithoutRef(libObjPtr);
     }
 
     EventClass::Shared createEventClass(const std::uint64_t id)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_event_class_create_with_id(this->_libObjPtr(), id);
+        const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return EventClass::Shared {EventClass {libObjPtr}};
+        return EventClass::Shared::createWithoutRef(libObjPtr);
     }
 
     CommonTraceClass<const bt_trace_class> traceClass() const noexcept;
@@ -1419,17 +1517,17 @@ public:
 
     std::uint64_t id() const noexcept
     {
-        return bt_stream_class_get_id(this->_libObjPtr());
+        return bt_stream_class_get_id(this->libObjPtr());
     }
 
     void name(const char * const name)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_stream_class_set_name(this->_libObjPtr(), name);
+        const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
 
         if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
@@ -1440,7 +1538,7 @@ public:
 
     nonstd::optional<bpstd::string_view> name() const noexcept
     {
-        const auto name = bt_stream_class_get_name(this->_libObjPtr());
+        const auto name = bt_stream_class_get_name(this->libObjPtr());
 
         if (name) {
             return name;
@@ -1453,27 +1551,27 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_stream_class_set_assigns_automatic_event_class_id(this->_libObjPtr(),
+        bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
                                                              static_cast<bt_bool>(val));
     }
 
     bool assignsAutomaticEventClassId() const noexcept
     {
         return static_cast<bool>(
-            bt_stream_class_assigns_automatic_event_class_id(this->_libObjPtr()));
+            bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
     }
 
     void assignsAutomaticStreamId(const bool val) noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_stream_class_set_assigns_automatic_stream_id(this->_libObjPtr(),
+        bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
                                                         static_cast<bt_bool>(val));
     }
 
     bool assignsAutomaticStreamId() const noexcept
     {
-        return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->_libObjPtr()));
+        return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
     }
 
     void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
@@ -1481,7 +1579,7 @@ public:
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_stream_class_set_supports_packets(this->_libObjPtr(),
+        bt_stream_class_set_supports_packets(this->libObjPtr(),
                                              static_cast<bt_bool>(supportsPackets),
                                              static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
                                              static_cast<bt_bool>(withEndDefaultClkSnapshot));
@@ -1489,19 +1587,19 @@ public:
 
     bool supportsPackets() const noexcept
     {
-        return static_cast<bool>(bt_stream_class_supports_packets(this->_libObjPtr()));
+        return static_cast<bool>(bt_stream_class_supports_packets(this->libObjPtr()));
     }
 
     bool packetsHaveBeginningClockSnapshot() const noexcept
     {
         return static_cast<bool>(
-            bt_stream_class_packets_have_beginning_default_clock_snapshot(this->_libObjPtr()));
+            bt_stream_class_packets_have_beginning_default_clock_snapshot(this->libObjPtr()));
     }
 
     bool packetsHaveEndClockSnapshot() const noexcept
     {
         return static_cast<bool>(
-            bt_stream_class_packets_have_end_default_clock_snapshot(this->_libObjPtr()));
+            bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
     }
 
     void supportsDiscardedEvents(const bool supportsDiscardedEvents,
@@ -1510,19 +1608,19 @@ public:
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         bt_stream_class_set_supports_discarded_events(
-            this->_libObjPtr(), static_cast<bt_bool>(supportsPackets),
+            this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
             static_cast<bt_bool>(withDefaultClkSnapshots));
     }
 
     bool supportsDiscardedEvents() const noexcept
     {
-        return static_cast<bool>(bt_stream_class_supports_discarded_events(this->_libObjPtr()));
+        return static_cast<bool>(bt_stream_class_supports_discarded_events(this->libObjPtr()));
     }
 
     bool discardedEventsHaveDefaultClockSnapshots() const noexcept
     {
         return static_cast<bool>(
-            bt_stream_class_discarded_events_have_default_clock_snapshots(this->_libObjPtr()));
+            bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
     }
 
     void supportsDiscardedPackets(const bool supportsDiscardedPackets,
@@ -1531,34 +1629,34 @@ public:
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         bt_stream_class_set_supports_discarded_packets(
-            this->_libObjPtr(), static_cast<bt_bool>(supportsPackets),
+            this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
             static_cast<bt_bool>(withDefaultClkSnapshots));
     }
 
     bool supportsDiscardedPackets() const noexcept
     {
-        return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->_libObjPtr()));
+        return static_cast<bool>(bt_stream_class_supports_discarded_packets(this->libObjPtr()));
     }
 
     bool discardedPacketsHaveDefaultClockSnapshots() const noexcept
     {
         return static_cast<bool>(
-            bt_stream_class_discarded_packets_have_default_clock_snapshots(this->_libObjPtr()));
+            bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
     }
 
-    void defaultClockClass(const ClockClass& clkCls)
+    void defaultClockClass(const ClockClass clkCls)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_stream_class_set_default_clock_class(this->_libObjPtr(), clkCls._libObjPtr());
+            bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
 
         BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
     }
 
     nonstd::optional<ConstClockClass> defaultClockClass() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::defaultClockClass(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::defaultClockClass(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstClockClass {libObjPtr};
@@ -1569,7 +1667,7 @@ public:
 
     nonstd::optional<_ClockClass> defaultClockClass() noexcept
     {
-        const auto libObjPtr = _Spec::defaultClockClass(this->_libObjPtr());
+        const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
 
         if (libObjPtr) {
             return _ClockClass {libObjPtr};
@@ -1580,22 +1678,22 @@ public:
 
     std::uint64_t size() const noexcept
     {
-        return bt_stream_class_get_event_class_count(this->_libObjPtr());
+        return bt_stream_class_get_event_class_count(this->libObjPtr());
     }
 
     ConstEventClass operator[](const std::uint64_t index) const noexcept
     {
-        return ConstEventClass {_ConstSpec::eventClassByIndex(this->_libObjPtr(), index)};
+        return ConstEventClass {_ConstSpec::eventClassByIndex(this->libObjPtr(), index)};
     }
 
     _EventClass operator[](const std::uint64_t index) noexcept
     {
-        return _EventClass {_Spec::eventClassByIndex(this->_libObjPtr(), index)};
+        return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
     }
 
     nonstd::optional<ConstEventClass> eventClassById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _ConstSpec::eventClassById(this->_libObjPtr(), id);
+        const auto libObjPtr = _ConstSpec::eventClassById(this->libObjPtr(), id);
 
         if (libObjPtr) {
             return ConstEventClass {libObjPtr};
@@ -1606,7 +1704,7 @@ public:
 
     nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) noexcept
     {
-        const auto libObjPtr = _Spec::eventClassById(this->_libObjPtr(), id);
+        const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
 
         if (libObjPtr) {
             return _EventClass {libObjPtr};
@@ -1615,21 +1713,21 @@ public:
         return nonstd::nullopt;
     }
 
-    void packetContextFieldClass(const StructureFieldClass& fc)
+    void packetContextFieldClass(const StructureFieldClass fc)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto status =
-            bt_stream_class_set_packet_context_field_class(this->_libObjPtr(), fc._libObjPtr());
+            bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
 
-        if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+        if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
+            throw MemoryError {};
         }
     }
 
     nonstd::optional<ConstStructureFieldClass> packetContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::packetContextFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureFieldClass {libObjPtr};
@@ -1640,7 +1738,7 @@ public:
 
     nonstd::optional<_StructureFieldClass> packetContextFieldClass() noexcept
     {
-        const auto libObjPtr = _Spec::packetContextFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureFieldClass {libObjPtr};
@@ -1649,21 +1747,21 @@ public:
         return nonstd::nullopt;
     }
 
-    void eventCommonContextFieldClass(const StructureFieldClass& fc)
+    void eventCommonContextFieldClass(const StructureFieldClass fc)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto status = bt_stream_class_set_event_common_context_field_class(this->_libObjPtr(),
-                                                                                 fc._libObjPtr());
+        const auto status =
+            bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
 
-        if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+        if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
+            throw MemoryError {};
         }
     }
 
     nonstd::optional<ConstStructureFieldClass> eventCommonContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _ConstSpec::eventCommonContextFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return ConstStructureFieldClass {libObjPtr};
@@ -1674,7 +1772,7 @@ public:
 
     nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() noexcept
     {
-        const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->_libObjPtr());
+        const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
 
         if (libObjPtr) {
             return _StructureFieldClass {libObjPtr};
@@ -1684,54 +1782,74 @@ public:
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    void userAttributes(const CommonMapValue<LibValT> userAttrs)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_stream_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
+        bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
 
     ConstMapValue userAttributes() const noexcept
     {
-        return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
+        return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
     }
 
     UserAttributes userAttributes() noexcept
     {
-        return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
+        return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
     }
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 };
 
 using StreamClass = CommonStreamClass<bt_stream_class>;
 using ConstStreamClass = CommonStreamClass<const bt_stream_class>;
 
+namespace internal {
+
+struct StreamClassTypeDescr
+{
+    using Const = ConstStreamClass;
+    using NonConst = StreamClass;
+};
+
+template <>
+struct TypeDescr<StreamClass> : public StreamClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstStreamClass> : public StreamClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 ConstStreamClass CommonEventClass<LibObjT>::streamClass() const noexcept
 {
-    return ConstStreamClass {_ConstSpec::streamClass(this->_libObjPtr())};
+    return ConstStreamClass {_ConstSpec::streamClass(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonEventClass<LibObjT>::_StreamClass CommonEventClass<LibObjT>::streamClass() noexcept
 {
-    return _StreamClass {_Spec::streamClass(this->_libObjPtr())};
+    return _StreamClass {_Spec::streamClass(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 ConstStreamClass CommonStream<LibObjT>::cls() const noexcept
 {
-    return ConstStreamClass {_ConstSpec::cls(this->_libObjPtr())};
+    return ConstStreamClass {_ConstSpec::cls(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonStream<LibObjT>::Class CommonStream<LibObjT>::cls() noexcept
 {
-    return Class {_Spec::cls(this->_libObjPtr())};
+    return Class {_Spec::cls(this->libObjPtr())};
 }
 
 namespace internal {
@@ -1824,301 +1942,294 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonTraceClass(const CommonTraceClass<OtherLibObjT>& traceClass) noexcept :
+    CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
         _ThisBorrowedObj {traceClass}
     {
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT>& traceClass) noexcept
+    _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
     {
         _ThisBorrowedObj::operator=(traceClass);
         return *this;
     }
 
-    Trace::Shared instantiate(const Trace& trace)
+    Trace::Shared instantiate()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_trace_create(this->_libObjPtr());
+        const auto libObjPtr = bt_trace_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return Trace::Shared {Trace {libObjPtr}};
+        return Trace::Shared::createWithoutRef(libObjPtr);
     }
 
     StreamClass::Shared createStreamClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_stream_class_create(this->_libObjPtr());
+        const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return StreamClass::Shared {StreamClass {libObjPtr}};
+        return StreamClass::Shared::createWithoutRef(libObjPtr);
     }
 
     StreamClass::Shared createStreamClass(const std::uint64_t id)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_stream_class_create_with_id(this->_libObjPtr(), id);
+        const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return StreamClass::Shared {StreamClass {libObjPtr}};
+        return StreamClass::Shared::createWithoutRef(libObjPtr);
     }
 
     FieldClass::Shared createBoolFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_bool_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return FieldClass::Shared {FieldClass {libObjPtr}};
+        return FieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_bit_array_create(this->_libObjPtr(), length);
+        const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return BitArrayFieldClass::Shared {BitArrayFieldClass {libObjPtr}};
+        return BitArrayFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     IntegerFieldClass::Shared createUnsignedIntegerFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_integer_unsigned_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return IntegerFieldClass::Shared {IntegerFieldClass {libObjPtr}};
+        return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     IntegerFieldClass::Shared createSignedIntegerFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_integer_signed_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return IntegerFieldClass::Shared {IntegerFieldClass {libObjPtr}};
+        return IntegerFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return UnsignedEnumerationFieldClass::Shared {UnsignedEnumerationFieldClass {libObjPtr}};
+        return UnsignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_enumeration_signed_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return SignedEnumerationFieldClass::Shared {SignedEnumerationFieldClass {libObjPtr}};
+        return SignedEnumerationFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     FieldClass::Shared createSinglePrecisionRealFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_real_single_precision_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return FieldClass::Shared {FieldClass {libObjPtr}};
+        return FieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     FieldClass::Shared createDoublePrecisionRealFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_real_double_precision_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return FieldClass::Shared {FieldClass {libObjPtr}};
+        return FieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     FieldClass::Shared createStringFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_string_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return FieldClass::Shared {FieldClass {libObjPtr}};
+        return FieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
-    StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass& elementFieldClass,
+    StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
                                                               const std::uint64_t length)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr = bt_field_class_array_static_create(
-            this->_libObjPtr(), elementFieldClass._libObjPtr(), length);
+            this->libObjPtr(), elementFieldClass.libObjPtr(), length);
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return StaticArrayFieldClass::Shared {StaticArrayFieldClass {libObjPtr}};
+        return StaticArrayFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
-    ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass& elementFieldClass)
+    ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr = bt_field_class_array_dynamic_create(
-            this->_libObjPtr(), elementFieldClass._libObjPtr(), nullptr);
+            this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return ArrayFieldClass::Shared {ArrayFieldClass {libObjPtr}};
+        return ArrayFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     DynamicArrayWithLengthFieldClass::Shared
-    createDynamicArrayFieldClass(const FieldClass& elementFieldClass,
-                                 const IntegerFieldClass& lengthFieldClass)
+    createDynamicArrayFieldClass(const FieldClass elementFieldClass,
+                                 const IntegerFieldClass lengthFieldClass)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr = bt_field_class_array_dynamic_create(
-            this->_libObjPtr(), elementFieldClass._libObjPtr(), lengthFieldClass._libObjPtr());
+            this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return DynamicArrayWithLengthFieldClass::Shared {
-            DynamicArrayWithLengthFieldClass {libObjPtr}};
+        return DynamicArrayWithLengthFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     StructureFieldClass::Shared createStructureFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_structure_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return StructureFieldClass::Shared {StructureFieldClass {libObjPtr}};
+        return StructureFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
-    OptionFieldClass::Shared createOptionFieldClass(const FieldClass& optionalFieldClass)
+    OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr = bt_field_class_option_without_selector_create(
-            this->_libObjPtr(), optionalFieldClass._libObjPtr());
+            this->libObjPtr(), optionalFieldClass.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return OptionFieldClass::Shared {OptionFieldClass {libObjPtr}};
+        return OptionFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     OptionWithBoolSelectorFieldClass::Shared
-    createOptionWithBoolSelectorFieldClass(const FieldClass& optionalFieldClass,
-                                           const FieldClass& selectorFieldClass)
+    createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
+                                           const FieldClass selectorFieldClass)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
-            this->_libObjPtr(), optionalFieldClass._libObjPtr(), selectorFieldClass._libObjPtr());
+            this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return OptionWithBoolSelectorFieldClass::Shared {
-            OptionWithBoolSelectorFieldClass {libObjPtr}};
+        return OptionWithBoolSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     OptionWithUnsignedIntegerSelectorFieldClass::Shared
-    createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass& optionalFieldClass,
-                                                      const IntegerFieldClass& selectorFieldClass,
-                                                      const ConstUnsignedIntegerRangeSet& ranges)
+    createOptionWithUnsignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
+                                                      const IntegerFieldClass selectorFieldClass,
+                                                      const ConstUnsignedIntegerRangeSet ranges)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
-            this->_libObjPtr(), optionalFieldClass._libObjPtr(), selectorFieldClass._libObjPtr(),
-            ranges._libObjPtr());
+            this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
+            ranges.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return OptionWithUnsignedIntegerSelectorFieldClass::Shared {
-            OptionWithUnsignedIntegerSelectorFieldClass {libObjPtr}};
+        return OptionWithUnsignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     OptionWithSignedIntegerSelectorFieldClass::Shared
-    createOptionWithSignedIntegerSelectorFieldClass(const FieldClass& optionalFieldClass,
-                                                    const IntegerFieldClass& selectorFieldClass,
-                                                    const ConstSignedIntegerRangeSet& ranges)
+    createOptionWithSignedIntegerSelectorFieldClass(const FieldClass optionalFieldClass,
+                                                    const IntegerFieldClass selectorFieldClass,
+                                                    const ConstSignedIntegerRangeSet ranges)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
-            this->_libObjPtr(), optionalFieldClass._libObjPtr(), selectorFieldClass._libObjPtr(),
-            ranges._libObjPtr());
+            this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
+            ranges.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return OptionWithSignedIntegerSelectorFieldClass::Shared {
-            OptionWithSignedIntegerSelectorFieldClass {libObjPtr}};
+        return OptionWithSignedIntegerSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     VariantWithoutSelectorFieldClass::Shared createVariantFieldClass()
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        const auto libObjPtr = bt_field_class_variant_create(this->_libObjPtr());
+        const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return VariantWithoutSelectorFieldClass::Shared {
-            VariantWithoutSelectorFieldClass {libObjPtr}};
+        return VariantWithoutSelectorFieldClass::Shared::createWithoutRef(libObjPtr);
     }
 
     VariantWithUnsignedIntegerSelectorFieldClass::Shared
-    createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
+    createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
-        return VariantWithUnsignedIntegerSelectorFieldClass::Shared {
-            VariantWithUnsignedIntegerSelectorFieldClass {
-                this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}};
+        return this->_createVariantWithIntegerSelectorFieldClass<
+            VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
     }
 
     VariantWithSignedIntegerSelectorFieldClass::Shared
-    createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
+    createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
-        return VariantWithSignedIntegerSelectorFieldClass::Shared {
-            VariantWithSignedIntegerSelectorFieldClass {
-                this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}};
+        return this->_createVariantWithIntegerSelectorFieldClass<
+            VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
     }
 
     void assignsAutomaticStreamClassId(const bool val) noexcept
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_trace_class_set_assigns_automatic_stream_class_id(this->_libObjPtr(),
+        bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
                                                              static_cast<bt_bool>(val));
     }
 
     bool assignsAutomaticStreamClassId() const noexcept
     {
         return static_cast<bool>(
-            bt_trace_class_assigns_automatic_stream_class_id(this->_libObjPtr()));
+            bt_trace_class_assigns_automatic_stream_class_id(this->libObjPtr()));
     }
 
     std::uint64_t size() const noexcept
     {
-        return bt_trace_class_get_stream_class_count(this->_libObjPtr());
+        return bt_trace_class_get_stream_class_count(this->libObjPtr());
     }
 
     ConstStreamClass operator[](const std::uint64_t index) const noexcept
     {
-        return ConstStreamClass {_ConstSpec::streamClassByIndex(this->_libObjPtr(), index)};
+        return ConstStreamClass {_ConstSpec::streamClassByIndex(this->libObjPtr(), index)};
     }
 
     _StreamClass operator[](const std::uint64_t index) noexcept
     {
-        return _StreamClass {_Spec::streamClassByIndex(this->_libObjPtr(), index)};
+        return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
     }
 
     nonstd::optional<ConstStreamClass> streamClassById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _ConstSpec::streamClassById(this->_libObjPtr(), id);
+        const auto libObjPtr = _ConstSpec::streamClassById(this->libObjPtr(), id);
 
         if (libObjPtr) {
             return ConstStreamClass {libObjPtr};
@@ -2129,7 +2240,7 @@ public:
 
     nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) noexcept
     {
-        const auto libObjPtr = _Spec::streamClassById(this->_libObjPtr(), id);
+        const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
 
         if (libObjPtr) {
             return _StreamClass {libObjPtr};
@@ -2139,67 +2250,88 @@ public:
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    void userAttributes(const CommonMapValue<LibValT> userAttrs)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
-        bt_trace_class_set_user_attributes(this->_libObjPtr(), userAttrs._libObjPtr());
+        bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
 
     ConstMapValue userAttributes() const noexcept
     {
-        return ConstMapValue {_ConstSpec::userAttributes(this->_libObjPtr())};
+        return ConstMapValue {_ConstSpec::userAttributes(this->libObjPtr())};
     }
 
     UserAttributes userAttributes() noexcept
     {
-        return UserAttributes {_Spec::userAttributes(this->_libObjPtr())};
+        return UserAttributes {_Spec::userAttributes(this->libObjPtr())};
     }
 
     Shared shared() const noexcept
     {
-        return Shared {*this};
+        return Shared::createWithRef(*this);
     }
 
 private:
-    bt_field_class *
-    _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass& selectorFieldClass)
+    template <typename ObjT>
+    typename ObjT::Shared
+    _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
 
         const auto libObjPtr =
-            bt_field_class_variant_create(this->_libObjPtr(), selectorFieldClass._libObjPtr());
+            bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return libObjPtr;
+        return ObjT::Shared::createWithoutRef(libObjPtr);
     }
 };
 
 using TraceClass = CommonTraceClass<bt_trace_class>;
 using ConstTraceClass = CommonTraceClass<const bt_trace_class>;
 
+namespace internal {
+
+struct TraceClassTypeDescr
+{
+    using Const = ConstTraceClass;
+    using NonConst = TraceClass;
+};
+
+template <>
+struct TypeDescr<TraceClass> : public TraceClassTypeDescr
+{
+};
+
+template <>
+struct TypeDescr<ConstTraceClass> : public TraceClassTypeDescr
+{
+};
+
+} /* namespace internal */
+
 template <typename LibObjT>
 ConstTraceClass CommonStreamClass<LibObjT>::traceClass() const noexcept
 {
-    return ConstTraceClass {_ConstSpec::traceClass(this->_libObjPtr())};
+    return ConstTraceClass {_ConstSpec::traceClass(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonStreamClass<LibObjT>::_TraceClass CommonStreamClass<LibObjT>::traceClass() noexcept
 {
-    return _TraceClass {_Spec::traceClass(this->_libObjPtr())};
+    return _TraceClass {_Spec::traceClass(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 ConstTraceClass CommonTrace<LibObjT>::cls() const noexcept
 {
-    return ConstTraceClass {_ConstSpec::cls(this->_libObjPtr())};
+    return ConstTraceClass {_ConstSpec::cls(this->libObjPtr())};
 }
 
 template <typename LibObjT>
 typename CommonTrace<LibObjT>::Class CommonTrace<LibObjT>::cls() noexcept
 {
-    return Class {_Spec::cls(this->_libObjPtr())};
+    return Class {_Spec::cls(this->libObjPtr())};
 }
 
 } /* namespace bt2 */
This page took 0.050916 seconds and 4 git commands to generate.