doc/api/libbabeltrace2/DoxygenLayout.xml: use `topics` tab
[babeltrace.git] / src / cpp-common / bt2 / trace-ir.hpp
index 5ee989601764d34fcea234c7eb46148e857cfa03..07c65924d931b4a27dd3d7da6402b8dbe10fccdd 100644 (file)
 
 #include <babeltrace2/babeltrace.h>
 
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
+#include "common/macros.h"
+#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object.hpp"
 #include "clock-class.hpp"
 #include "field-class.hpp"
 #include "field.hpp"
 #include "internal/utils.hpp"
+#include "optional-borrowed-object.hpp"
 #include "shared-object.hpp"
 #include "value.hpp"
 
@@ -121,6 +123,9 @@ struct CommonEventSpec<const bt_event> final
     }
 };
 
+template <typename LibObjT>
+using DepStructField = DepType<LibObjT, StructureField, ConstStructureField>;
+
 } /* namespace internal */
 
 template <typename LibObjT>
@@ -128,26 +133,18 @@ class CommonEvent final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonEventSpec<LibObjT>;
-
-    using _Packet =
-        typename std::conditional<std::is_const<LibObjT>::value, CommonPacket<const bt_packet>,
-                                  CommonPacket<bt_packet>>::type;
-
-    using _Stream =
-        typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
-                                  CommonStream<bt_stream>>::type;
-
-    using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
-                                                      ConstStructureField, StructureField>::type;
+    using _Packet = internal::DepPacket<LibObjT>;
+    using _Stream = internal::DepStream<LibObjT>;
+    using _StructureField = internal::DepStructField<LibObjT>;
 
 public:
-    using Class = typename std::conditional<std::is_const<LibObjT>::value,
-                                            CommonEventClass<const bt_event_class>,
-                                            CommonEventClass<bt_event_class>>::type;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
 
-    explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    using Class = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
+                                    CommonEventClass<const bt_event_class>>;
+
+    explicit CommonEvent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -157,47 +154,34 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
+    CommonEvent<LibObjT> operator=(const CommonEvent<OtherLibObjT> event) noexcept
     {
         _ThisBorrowedObject::operator=(event);
         return *this;
     }
 
+    CommonEvent<const bt_event> asConst() const noexcept
+    {
+        return CommonEvent<const bt_event> {*this};
+    }
+
     Class cls() const noexcept;
     _Stream stream() const noexcept;
-    nonstd::optional<_Packet> packet() const noexcept;
+    OptionalBorrowedObject<_Packet> packet() const noexcept;
 
-    nonstd::optional<_StructureField> payloadField() const noexcept
+    OptionalBorrowedObject<_StructureField> payloadField() const noexcept
     {
-        const auto libObjPtr = _Spec::payloadField(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::payloadField(this->libObjPtr());
     }
 
-    nonstd::optional<_StructureField> specificContextField() const noexcept
+    OptionalBorrowedObject<_StructureField> specificContextField() const noexcept
     {
-        const auto libObjPtr = _Spec::specificContextField(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::specificContextField(this->libObjPtr());
     }
 
-    nonstd::optional<_StructureField> commonContextField() const noexcept
+    OptionalBorrowedObject<_StructureField> commonContextField() const noexcept
     {
-        const auto libObjPtr = _Spec::commonContextField(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::commonContextField(this->libObjPtr());
     }
 };
 
@@ -275,21 +259,15 @@ class CommonPacket final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonPacketSpec<LibObjT>;
-    using _ThisCommonPacket = CommonPacket<LibObjT>;
-
-    using _Stream =
-        typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
-                                  CommonStream<bt_stream>>::type;
-
-    using _StructureField = typename std::conditional<std::is_const<LibObjT>::value,
-                                                      ConstStructureField, StructureField>::type;
+    using _Stream = internal::DepStream<LibObjT>;
+    using _StructureField = internal::DepStructField<LibObjT>;
 
 public:
-    using Shared = SharedObject<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+    using Shared = SharedObject<CommonPacket, LibObjT, internal::PacketRefFuncs>;
 
-    explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonPacket(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -299,23 +277,22 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
+    CommonPacket operator=(const CommonPacket<OtherLibObjT> packet) noexcept
     {
         _ThisBorrowedObject::operator=(packet);
         return *this;
     }
 
-    _Stream stream() const noexcept;
-
-    nonstd::optional<_StructureField> contextField() const noexcept
+    CommonPacket<const bt_packet> asConst() const noexcept
     {
-        const auto libObjPtr = _Spec::contextField(this->libObjPtr());
+        return CommonPacket<const bt_packet> {*this};
+    }
 
-        if (libObjPtr) {
-            return _StructureField {libObjPtr};
-        }
+    _Stream stream() const noexcept;
 
-        return nonstd::nullopt;
+    OptionalBorrowedObject<_StructureField> contextField() const noexcept
+    {
+        return _Spec::contextField(this->libObjPtr());
     }
 
     Shared shared() const noexcept
@@ -348,16 +325,10 @@ struct TypeDescr<ConstPacket> : public PacketTypeDescr
 } /* namespace internal */
 
 template <typename LibObjT>
-nonstd::optional<typename CommonEvent<LibObjT>::_Packet>
+OptionalBorrowedObject<typename CommonEvent<LibObjT>::_Packet>
 CommonEvent<LibObjT>::packet() const noexcept
 {
-    const auto libObjPtr = _Spec::packet(this->libObjPtr());
-
-    if (libObjPtr) {
-        return _Packet {libObjPtr};
-    }
-
-    return nonstd::nullopt;
+    return _Spec::packet(this->libObjPtr());
 }
 
 namespace internal {
@@ -425,25 +396,18 @@ class CommonStream final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonStreamSpec<LibObjT>;
-    using _ThisCommonStream = CommonStream<LibObjT>;
-
-    using _Trace =
-        typename std::conditional<std::is_const<LibObjT>::value, CommonTrace<const bt_trace>,
-                                  CommonTrace<bt_trace>>::type;
+    using _Trace = internal::DepType<LibObjT, CommonTrace<bt_trace>, CommonTrace<const bt_trace>>;
 
 public:
-    using Shared = SharedObject<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+    using Shared = SharedObject<CommonStream, LibObjT, internal::StreamRefFuncs>;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    using Class = typename std::conditional<std::is_const<LibObjT>::value,
-                                            CommonStreamClass<const bt_stream_class>,
-                                            CommonStreamClass<bt_stream_class>>::type;
+    using Class = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
+                                    CommonStreamClass<const bt_stream_class>>;
 
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
-
-    explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonStream(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -453,15 +417,20 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
+    CommonStream operator=(const CommonStream<OtherLibObjT> stream) noexcept
     {
         _ThisBorrowedObject::operator=(stream);
         return *this;
     }
 
+    CommonStream<const bt_stream> asConst() const noexcept
+    {
+        return CommonStream<const bt_stream> {*this};
+    }
+
     Packet::Shared createPacket() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
 
         const auto libObjPtr = bt_packet_create(this->libObjPtr());
 
@@ -477,39 +446,31 @@ public:
         return bt_stream_get_id(this->libObjPtr());
     }
 
-    void name(const char * const name) const
+    CommonStream name(const bt2c::CStringView name) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
 
         const auto status = bt_stream_set_name(this->libObjPtr(), name);
 
         if (status == BT_STREAM_SET_NAME_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
+        return *this;
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
-        const auto name = bt_stream_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_stream_get_name(this->libObjPtr());
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    CommonStream userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstStream`.");
 
         bt_stream_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+        return *this;
     }
 
     UserAttributes userAttributes() const noexcept
@@ -635,31 +596,24 @@ class CommonTrace final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonTraceSpec<LibObjT>;
-    using _ThisCommonTrace = CommonTrace<LibObjT>;
-
-    using _Stream =
-        typename std::conditional<std::is_const<LibObjT>::value, CommonStream<const bt_stream>,
-                                  CommonStream<bt_stream>>::type;
+    using _Stream = internal::DepStream<LibObjT>;
 
 public:
-    using Shared = SharedObject<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+    using Shared = SharedObject<CommonTrace, LibObjT, internal::TraceRefFuncs>;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    using Class = typename std::conditional<std::is_const<LibObjT>::value,
-                                            CommonTraceClass<const bt_trace_class>,
-                                            CommonTraceClass<bt_trace_class>>::type;
-
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
+    using Class = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
+                                    CommonTraceClass<const bt_trace_class>>;
 
     struct ConstEnvironmentEntry
     {
-        bpstd::string_view name;
+        bt2c::CStringView name;
         ConstValue value;
     };
 
-    explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonTrace(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -669,55 +623,52 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
+    CommonTrace operator=(const CommonTrace<OtherLibObjT> trace) noexcept
     {
         _ThisBorrowedObject::operator=(trace);
         return *this;
     }
 
+    CommonTrace<const bt_trace> asConst() const noexcept
+    {
+        return CommonTrace<const bt_trace> {*this};
+    }
+
     Class cls() const noexcept;
 
-    void name(const char * const name) const
+    CommonTrace name(const bt2c::CStringView name) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
 
         const auto status = bt_trace_set_name(this->libObjPtr(), name);
 
         if (status == BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
+        return *this;
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
-        const auto name = bt_trace_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_trace_get_name(this->libObjPtr());
     }
 
-    void uuid(const bt2_common::UuidView& uuid) const noexcept
+    CommonTrace uuid(const bt2c::UuidView& uuid) const noexcept
     {
         bt_trace_set_uuid(this->libObjPtr(), uuid.begin());
+        return *this;
     }
 
-    nonstd::optional<bt2_common::UuidView> uuid() const noexcept
+    bt2s::optional<bt2c::UuidView> uuid() const noexcept
     {
         const auto uuid = bt_trace_get_uuid(this->libObjPtr());
 
         if (uuid) {
-            return bt2_common::UuidView {uuid};
+            return bt2c::UuidView {uuid};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
     std::uint64_t length() const noexcept
@@ -730,57 +681,35 @@ public:
         return _Stream {_Spec::streamByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_Stream> streamById(const std::uint64_t id) const noexcept
+    OptionalBorrowedObject<_Stream> streamById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _Spec::streamById(this->libObjPtr(), id);
-
-        if (libObjPtr) {
-            return _Stream {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::streamById(this->libObjPtr(), id);
     }
 
-    void environmentEntry(const char * const name, const std::int64_t val) const
+    CommonTrace environmentEntry(const bt2c::CStringView name, const std::int64_t val) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
 
         const auto status = bt_trace_set_environment_entry_integer(this->libObjPtr(), name, val);
 
         if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void environmentEntry(const std::string& name, const std::int64_t val) const
-    {
-        this->environmentEntry(name.data(), val);
+        return *this;
     }
 
-    void environmentEntry(const char * const name, const char * const val) const
+    CommonTrace environmentEntry(const bt2c::CStringView name, const bt2c::CStringView val) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
 
         const auto status = bt_trace_set_environment_entry_string(this->libObjPtr(), name, val);
 
         if (status == BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
-
-    void environmentEntry(const std::string& name, const char * const val) const
-    {
-        this->environmentEntry(name.data(), val);
-    }
-
-    void environmentEntry(const char * const name, const std::string& val) const
-    {
-        this->environmentEntry(name, val.data());
-    }
 
-    void environmentEntry(const std::string& name, const std::string& val) const
-    {
-        this->environmentEntry(name.data(), val.data());
+        return *this;
     }
 
     std::uint64_t environmentSize() const noexcept
@@ -798,29 +727,18 @@ public:
         return ConstEnvironmentEntry {name, ConstValue {libObjPtr}};
     }
 
-    nonstd::optional<ConstValue> environmentEntry(const char * const name) const noexcept
+    OptionalBorrowedObject<ConstValue> environmentEntry(const bt2c::CStringView name) const noexcept
     {
-        const auto libObjPtr =
-            bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
-
-        if (libObjPtr) {
-            return ConstValue {libObjPtr};
-        }
-
-        return nonstd::nullopt;
-    }
-
-    nonstd::optional<ConstValue> environmentEntry(const std::string& name) const noexcept
-    {
-        return this->environmentEntry(name.data());
+        return bt_trace_borrow_environment_entry_value_by_name_const(this->libObjPtr(), name);
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    CommonTrace userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTrace`.");
 
         bt_trace_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+        return *this;
     }
 
     UserAttributes userAttributes() const noexcept
@@ -932,51 +850,53 @@ struct CommonEventClassSpec<const bt_event_class> final
     }
 };
 
+template <typename LibObjT>
+using DepStructFc = DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
+
 } /* namespace internal */
 
+/* Avoid `-Wshadow` error on GCC, conflicting with `bt2::Error` */
+BT_DIAG_PUSH
+BT_DIAG_IGNORE_SHADOW
+
+enum class EventClassLogLevel
+{
+    Emergency = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
+    Alert = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
+    Critical = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
+    Error = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
+    Warning = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
+    Notice = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
+    Info = BT_EVENT_CLASS_LOG_LEVEL_INFO,
+    DebugSystem = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
+    DebugProgram = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
+    DebugProcess = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
+    DebugModule = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
+    DebugUnit = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
+    DebugFunction = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
+    DebugLine = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
+    Debug = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
+};
+
+BT_DIAG_POP
+
 template <typename LibObjT>
 class CommonEventClass final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonEventClassSpec<LibObjT>;
-    using _ThisCommonEventClass = CommonEventClass<LibObjT>;
+    using _StructureFieldClass = internal::DepStructFc<LibObjT>;
 
-    using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
-                                                   CommonStreamClass<const bt_stream_class>,
-                                                   CommonStreamClass<bt_stream_class>>::type;
-
-    using _StructureFieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
-                                  StructureFieldClass>::type;
+    using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
+                                           CommonStreamClass<const bt_stream_class>>;
 
 public:
-    using Shared = SharedObject<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
-
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
-
-    enum class LogLevel
-    {
-        EMERGENCY = BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
-        ALERT = BT_EVENT_CLASS_LOG_LEVEL_ALERT,
-        CRITICAL = BT_EVENT_CLASS_LOG_LEVEL_CRITICAL,
-        ERR = BT_EVENT_CLASS_LOG_LEVEL_ERROR,
-        WARNING = BT_EVENT_CLASS_LOG_LEVEL_WARNING,
-        NOTICE = BT_EVENT_CLASS_LOG_LEVEL_NOTICE,
-        INFO = BT_EVENT_CLASS_LOG_LEVEL_INFO,
-        DEBUG_SYSTEM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM,
-        DEBUG_PROGRAM = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM,
-        DEBUG_PROC = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS,
-        DEBUG_MODULE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE,
-        DEBUG_UNIT = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT,
-        DEBUG_FUNCTION = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION,
-        DEBUG_LINE = BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE,
-        DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
-    };
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+    using Shared = SharedObject<CommonEventClass, LibObjT, internal::EventClassRefFuncs>;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonEventClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -987,12 +907,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
+    CommonEventClass operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
     {
         _ThisBorrowedObject::operator=(eventClass);
         return *this;
     }
 
+    CommonEventClass<const bt_event_class> asConst() const noexcept
+    {
+        return CommonEventClass<const bt_event_class> {*this};
+    }
+
     _StreamClass streamClass() const noexcept;
 
     std::uint64_t id() const noexcept
@@ -1000,83 +925,65 @@ public:
         return bt_event_class_get_id(this->libObjPtr());
     }
 
-    void name(const char * const name) const
+    CommonEventClass name(const bt2c::CStringView name) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
         const auto status = bt_event_class_set_name(this->libObjPtr(), name);
 
         if (status == BT_EVENT_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
+        return *this;
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
-        const auto name = bt_event_class_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_event_class_get_name(this->libObjPtr());
     }
 
-    void logLevel(const LogLevel logLevel) const noexcept
+    CommonEventClass logLevel(const EventClassLogLevel logLevel) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
         bt_event_class_set_log_level(this->libObjPtr(),
                                      static_cast<bt_event_class_log_level>(logLevel));
+        return *this;
     }
 
-    nonstd::optional<LogLevel> logLevel() const noexcept
+    bt2s::optional<EventClassLogLevel> logLevel() const noexcept
     {
         bt_event_class_log_level libLogLevel;
-        const auto avail = bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel);
 
-        if (avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) {
-            return static_cast<LogLevel>(libLogLevel);
+        if (bt_event_class_get_log_level(this->libObjPtr(), &libLogLevel)) {
+            return static_cast<EventClassLogLevel>(libLogLevel);
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    void emfUri(const char * const emfUri) const
+    CommonEventClass emfUri(const bt2c::CStringView emfUri) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
         const auto status = bt_event_class_set_emf_uri(this->libObjPtr(), emfUri);
 
         if (status == BT_EVENT_CLASS_SET_EMF_URI_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void emfUri(const std::string& emfUri) const
-    {
-        this->emfUri(emfUri.data());
+        return *this;
     }
 
-    nonstd::optional<bpstd::string_view> emfUri() const noexcept
+    bt2c::CStringView emfUri() const noexcept
     {
-        const auto emfUri = bt_event_class_get_emf_uri(this->libObjPtr());
-
-        if (emfUri) {
-            return emfUri;
-        }
-
-        return nonstd::nullopt;
+        return bt_event_class_get_emf_uri(this->libObjPtr());
     }
 
-    void payloadFieldClass(const StructureFieldClass fc) const
+    CommonEventClass payloadFieldClass(const StructureFieldClass fc) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
         const auto status =
             bt_event_class_set_payload_field_class(this->libObjPtr(), fc.libObjPtr());
@@ -1084,22 +991,18 @@ public:
         if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
+
+        return *this;
     }
 
-    nonstd::optional<_StructureFieldClass> payloadFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> payloadFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::payloadFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::payloadFieldClass(this->libObjPtr());
     }
 
-    void specificContextFieldClass(const StructureFieldClass fc) const
+    CommonEventClass specificContextFieldClass(const StructureFieldClass fc) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
         const auto status =
             bt_event_class_set_specific_context_field_class(this->libObjPtr(), fc.libObjPtr());
@@ -1107,25 +1010,22 @@ public:
         if (status == BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
+
+        return *this;
     }
 
-    nonstd::optional<_StructureFieldClass> specificContextFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> specificContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::specificContextFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::specificContextFieldClass(this->libObjPtr());
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    CommonEventClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstEventClass`.");
 
         bt_event_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+        return *this;
     }
 
     UserAttributes userAttributes() const noexcept
@@ -1279,33 +1179,23 @@ class CommonStreamClass final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::CommonStreamClassSpec<LibObjT>;
-    using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
-
-    using _TraceClass = typename std::conditional<std::is_const<LibObjT>::value,
-                                                  CommonTraceClass<const bt_trace_class>,
-                                                  CommonTraceClass<bt_trace_class>>::type;
+    using _StructureFieldClass = internal::DepStructFc<LibObjT>;
 
-    using _EventClass = typename std::conditional<std::is_const<LibObjT>::value,
-                                                  CommonEventClass<const bt_event_class>,
-                                                  CommonEventClass<bt_event_class>>::type;
+    using _TraceClass = internal::DepType<LibObjT, CommonTraceClass<bt_trace_class>,
+                                          CommonTraceClass<const bt_trace_class>>;
 
-    using _StructureFieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
-                                  StructureFieldClass>::type;
+    using _EventClass = internal::DepType<LibObjT, CommonEventClass<bt_event_class>,
+                                          CommonEventClass<const bt_event_class>>;
 
-    using _ClockClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
+    using _ClockClass = internal::DepType<LibObjT, ClockClass, ConstClockClass>;
 
 public:
-    using Shared = SharedObject<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+    using Shared = SharedObject<CommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
-
-    explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
-        _ThisBorrowedObject {libObjPtr}
+    explicit CommonStreamClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -1316,15 +1206,21 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
+    CommonStreamClass operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
     {
         _ThisBorrowedObject::operator=(streamClass);
         return *this;
     }
 
+    CommonStreamClass<const bt_stream_class> asConst() const noexcept
+    {
+        return CommonStreamClass<const bt_stream_class> {*this};
+    }
+
     Stream::Shared instantiate(const Trace trace) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto libObjPtr = bt_stream_create(this->libObjPtr(), trace.libObjPtr());
 
@@ -1334,7 +1230,8 @@ public:
 
     Stream::Shared instantiate(const Trace trace, const std::uint64_t id) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto libObjPtr = bt_stream_create_with_id(this->libObjPtr(), trace.libObjPtr(), id);
 
@@ -1344,7 +1241,8 @@ public:
 
     EventClass::Shared createEventClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto libObjPtr = bt_event_class_create(this->libObjPtr());
 
@@ -1354,7 +1252,8 @@ public:
 
     EventClass::Shared createEventClass(const std::uint64_t id) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto libObjPtr = bt_event_class_create_with_id(this->libObjPtr(), id);
 
@@ -1369,39 +1268,33 @@ public:
         return bt_stream_class_get_id(this->libObjPtr());
     }
 
-    void name(const char * const name) const
+    CommonStreamClass name(const bt2c::CStringView name) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto status = bt_stream_class_set_name(this->libObjPtr(), name);
 
         if (status == BT_STREAM_CLASS_SET_NAME_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-    }
 
-    void name(const std::string& name) const
-    {
-        this->name(name.data());
+        return *this;
     }
 
-    nonstd::optional<bpstd::string_view> name() const noexcept
+    bt2c::CStringView name() const noexcept
     {
-        const auto name = bt_stream_class_get_name(this->libObjPtr());
-
-        if (name) {
-            return name;
-        }
-
-        return nonstd::nullopt;
+        return bt_stream_class_get_name(this->libObjPtr());
     }
 
-    void assignsAutomaticEventClassId(const bool val) const noexcept
+    CommonStreamClass assignsAutomaticEventClassId(const bool val) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         bt_stream_class_set_assigns_automatic_event_class_id(this->libObjPtr(),
                                                              static_cast<bt_bool>(val));
+        return *this;
     }
 
     bool assignsAutomaticEventClassId() const noexcept
@@ -1410,12 +1303,14 @@ public:
             bt_stream_class_assigns_automatic_event_class_id(this->libObjPtr()));
     }
 
-    void assignsAutomaticStreamId(const bool val) const noexcept
+    CommonStreamClass assignsAutomaticStreamId(const bool val) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         bt_stream_class_set_assigns_automatic_stream_id(this->libObjPtr(),
                                                         static_cast<bt_bool>(val));
+        return *this;
     }
 
     bool assignsAutomaticStreamId() const noexcept
@@ -1423,15 +1318,18 @@ public:
         return static_cast<bool>(bt_stream_class_assigns_automatic_stream_id(this->libObjPtr()));
     }
 
-    void supportsPackets(const bool supportsPackets, const bool withBeginningDefaultClkSnapshot,
-                         const bool withEndDefaultClkSnapshot) const noexcept
+    CommonStreamClass supportsPackets(const bool supportsPackets,
+                                      const bool withBeginningDefaultClkSnapshot,
+                                      const bool withEndDefaultClkSnapshot) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         bt_stream_class_set_supports_packets(this->libObjPtr(),
                                              static_cast<bt_bool>(supportsPackets),
                                              static_cast<bt_bool>(withBeginningDefaultClkSnapshot),
                                              static_cast<bt_bool>(withEndDefaultClkSnapshot));
+        return *this;
     }
 
     bool supportsPackets() const noexcept
@@ -1451,14 +1349,16 @@ public:
             bt_stream_class_packets_have_end_default_clock_snapshot(this->libObjPtr()));
     }
 
-    void supportsDiscardedEvents(const bool supportsDiscardedEvents,
-                                 const bool withDefaultClkSnapshots) const noexcept
+    CommonStreamClass supportsDiscardedEvents(const bool supportsDiscardedEvents,
+                                              const bool withDefaultClkSnapshots) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         bt_stream_class_set_supports_discarded_events(
             this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedEvents),
             static_cast<bt_bool>(withDefaultClkSnapshots));
+        return *this;
     }
 
     bool supportsDiscardedEvents() const noexcept
@@ -1472,14 +1372,16 @@ public:
             bt_stream_class_discarded_events_have_default_clock_snapshots(this->libObjPtr()));
     }
 
-    void supportsDiscardedPackets(const bool supportsDiscardedPackets,
-                                  const bool withDefaultClkSnapshots) const noexcept
+    CommonStreamClass supportsDiscardedPackets(const bool supportsDiscardedPackets,
+                                               const bool withDefaultClkSnapshots) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         bt_stream_class_set_supports_discarded_packets(
             this->libObjPtr(), static_cast<bt_bool>(supportsDiscardedPackets),
             static_cast<bt_bool>(withDefaultClkSnapshots));
+        return *this;
     }
 
     bool supportsDiscardedPackets() const noexcept
@@ -1493,25 +1395,21 @@ public:
             bt_stream_class_discarded_packets_have_default_clock_snapshots(this->libObjPtr()));
     }
 
-    void defaultClockClass(const ClockClass clkCls) const
+    CommonStreamClass defaultClockClass(const ClockClass clkCls) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto status =
             bt_stream_class_set_default_clock_class(this->libObjPtr(), clkCls.libObjPtr());
 
         BT_ASSERT(status == BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK);
+        return *this;
     }
 
-    nonstd::optional<_ClockClass> defaultClockClass() const noexcept
+    OptionalBorrowedObject<_ClockClass> defaultClockClass() const noexcept
     {
-        const auto libObjPtr = _Spec::defaultClockClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _ClockClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::defaultClockClass(this->libObjPtr());
     }
 
     std::uint64_t length() const noexcept
@@ -1524,20 +1422,15 @@ public:
         return _EventClass {_Spec::eventClassByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_EventClass> eventClassById(const std::uint64_t id) const noexcept
+    OptionalBorrowedObject<_EventClass> eventClassById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _Spec::eventClassById(this->libObjPtr(), id);
-
-        if (libObjPtr) {
-            return _EventClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::eventClassById(this->libObjPtr(), id);
     }
 
-    void packetContextFieldClass(const StructureFieldClass fc) const
+    CommonStreamClass packetContextFieldClass(const StructureFieldClass fc) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto status =
             bt_stream_class_set_packet_context_field_class(this->libObjPtr(), fc.libObjPtr());
@@ -1545,22 +1438,19 @@ public:
         if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
+
+        return *this;
     }
 
-    nonstd::optional<_StructureFieldClass> packetContextFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> packetContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::packetContextFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::packetContextFieldClass(this->libObjPtr());
     }
 
-    void eventCommonContextFieldClass(const StructureFieldClass fc) const
+    CommonStreamClass eventCommonContextFieldClass(const StructureFieldClass fc) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         const auto status =
             bt_stream_class_set_event_common_context_field_class(this->libObjPtr(), fc.libObjPtr());
@@ -1568,25 +1458,23 @@ public:
         if (status == BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
+
+        return *this;
     }
 
-    nonstd::optional<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
+    OptionalBorrowedObject<_StructureFieldClass> eventCommonContextFieldClass() const noexcept
     {
-        const auto libObjPtr = _Spec::eventCommonContextFieldClass(this->libObjPtr());
-
-        if (libObjPtr) {
-            return _StructureFieldClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::eventCommonContextFieldClass(this->libObjPtr());
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    CommonStreamClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStreamClass`.");
 
         bt_stream_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+        return *this;
     }
 
     UserAttributes userAttributes() const noexcept
@@ -1705,21 +1593,18 @@ class CommonTraceClass final : public BorrowedObject<LibObjT>
 {
 private:
     using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
-    using typename BorrowedObject<LibObjT>::_LibObjPtr;
+
     using _Spec = internal::CommonTraceClassSpec<LibObjT>;
-    using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
 
-    using _StreamClass = typename std::conditional<std::is_const<LibObjT>::value,
-                                                   CommonStreamClass<const bt_stream_class>,
-                                                   CommonStreamClass<bt_stream_class>>::type;
+    using _StreamClass = internal::DepType<LibObjT, CommonStreamClass<bt_stream_class>,
+                                           CommonStreamClass<const bt_stream_class>>;
 
 public:
-    using Shared = SharedObject<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
+    using typename BorrowedObject<LibObjT>::LibObjPtr;
+    using Shared = SharedObject<CommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
-
-    explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
+    explicit CommonTraceClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
@@ -1730,15 +1615,20 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
+    CommonTraceClass operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
     {
         _ThisBorrowedObject::operator=(traceClass);
         return *this;
     }
 
+    CommonTraceClass<const bt_trace_class> asConst() const noexcept
+    {
+        return CommonTraceClass<const bt_trace_class> {*this};
+    }
+
     Trace::Shared instantiate() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_trace_create(this->libObjPtr());
 
@@ -1748,7 +1638,7 @@ public:
 
     StreamClass::Shared createStreamClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_stream_class_create(this->libObjPtr());
 
@@ -1758,7 +1648,7 @@ public:
 
     StreamClass::Shared createStreamClass(const std::uint64_t id) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_stream_class_create_with_id(this->libObjPtr(), id);
 
@@ -1768,7 +1658,7 @@ public:
 
     FieldClass::Shared createBoolFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_bool_create(this->libObjPtr());
 
@@ -1778,7 +1668,7 @@ public:
 
     BitArrayFieldClass::Shared createBitArrayFieldClass(const std::uint64_t length) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_bit_array_create(this->libObjPtr(), length);
 
@@ -1788,7 +1678,7 @@ public:
 
     IntegerFieldClass::Shared createUnsignedIntegerFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_integer_unsigned_create(this->libObjPtr());
 
@@ -1798,7 +1688,7 @@ public:
 
     IntegerFieldClass::Shared createSignedIntegerFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_integer_signed_create(this->libObjPtr());
 
@@ -1808,7 +1698,7 @@ public:
 
     UnsignedEnumerationFieldClass::Shared createUnsignedEnumerationFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_enumeration_unsigned_create(this->libObjPtr());
 
@@ -1818,7 +1708,7 @@ public:
 
     SignedEnumerationFieldClass::Shared createSignedEnumerationFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_enumeration_signed_create(this->libObjPtr());
 
@@ -1828,7 +1718,7 @@ public:
 
     FieldClass::Shared createSinglePrecisionRealFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_real_single_precision_create(this->libObjPtr());
 
@@ -1838,7 +1728,7 @@ public:
 
     FieldClass::Shared createDoublePrecisionRealFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_real_double_precision_create(this->libObjPtr());
 
@@ -1848,7 +1738,7 @@ public:
 
     FieldClass::Shared createStringFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_string_create(this->libObjPtr());
 
@@ -1859,7 +1749,7 @@ public:
     StaticArrayFieldClass::Shared createStaticArrayFieldClass(const FieldClass elementFieldClass,
                                                               const std::uint64_t length) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_array_static_create(
             this->libObjPtr(), elementFieldClass.libObjPtr(), length);
@@ -1870,7 +1760,7 @@ public:
 
     ArrayFieldClass::Shared createDynamicArrayFieldClass(const FieldClass elementFieldClass) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_array_dynamic_create(
             this->libObjPtr(), elementFieldClass.libObjPtr(), nullptr);
@@ -1883,7 +1773,7 @@ public:
     createDynamicArrayFieldClass(const FieldClass elementFieldClass,
                                  const IntegerFieldClass lengthFieldClass) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_array_dynamic_create(
             this->libObjPtr(), elementFieldClass.libObjPtr(), lengthFieldClass.libObjPtr());
@@ -1894,7 +1784,7 @@ public:
 
     StructureFieldClass::Shared createStructureFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_structure_create(this->libObjPtr());
 
@@ -1904,7 +1794,7 @@ public:
 
     OptionFieldClass::Shared createOptionFieldClass(const FieldClass optionalFieldClass) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_option_without_selector_create(
             this->libObjPtr(), optionalFieldClass.libObjPtr());
@@ -1917,7 +1807,7 @@ public:
     createOptionWithBoolSelectorFieldClass(const FieldClass optionalFieldClass,
                                            const FieldClass selectorFieldClass) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_option_with_selector_field_bool_create(
             this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr());
@@ -1931,7 +1821,7 @@ public:
         const FieldClass optionalFieldClass, const IntegerFieldClass selectorFieldClass,
         const ConstUnsignedIntegerRangeSet ranges) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_option_with_selector_field_integer_unsigned_create(
             this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
@@ -1946,7 +1836,7 @@ public:
                                                     const IntegerFieldClass selectorFieldClass,
                                                     const ConstSignedIntegerRangeSet ranges) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_option_with_selector_field_integer_signed_create(
             this->libObjPtr(), optionalFieldClass.libObjPtr(), selectorFieldClass.libObjPtr(),
@@ -1958,7 +1848,7 @@ public:
 
     VariantWithoutSelectorFieldClass::Shared createVariantFieldClass() const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr = bt_field_class_variant_create(this->libObjPtr(), nullptr);
 
@@ -1982,12 +1872,13 @@ public:
             VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
     }
 
-    void assignsAutomaticStreamClassId(const bool val) const noexcept
+    CommonTraceClass assignsAutomaticStreamClassId(const bool val) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         bt_trace_class_set_assigns_automatic_stream_class_id(this->libObjPtr(),
                                                              static_cast<bt_bool>(val));
+        return *this;
     }
 
     bool assignsAutomaticStreamClassId() const noexcept
@@ -2006,23 +1897,18 @@ public:
         return _StreamClass {_Spec::streamClassByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
+    OptionalBorrowedObject<_StreamClass> streamClassById(const std::uint64_t id) const noexcept
     {
-        const auto libObjPtr = _Spec::streamClassById(this->libObjPtr(), id);
-
-        if (libObjPtr) {
-            return _StreamClass {libObjPtr};
-        }
-
-        return nonstd::nullopt;
+        return _Spec::streamClassById(this->libObjPtr(), id);
     }
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    CommonTraceClass userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         bt_trace_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+        return *this;
     }
 
     UserAttributes userAttributes() const noexcept
@@ -2040,7 +1926,7 @@ private:
     typename ObjT::Shared
     _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstTraceClass`.");
 
         const auto libObjPtr =
             bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
This page took 0.042888 seconds and 4 git commands to generate.