cpp-common/bt2: `bt2::internal::SharedObj` -> `bt2::SharedObj`
[babeltrace.git] / src / cpp-common / bt2 / trace-ir.hpp
index 727a9946c11e81ccab4bfdd18e22fb12642f06e1..293e99546afa2098b837d1a3d3ae30cedd1f14fd 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 "borrowed-object.hpp"
 #include "clock-class.hpp"
-#include "clock-snapshot.hpp"
 #include "field-class.hpp"
 #include "field.hpp"
-#include "value.hpp"
 #include "internal/utils.hpp"
+#include "shared-obj.hpp"
+#include "value.hpp"
 
 namespace bt2 {
 
@@ -122,11 +124,11 @@ struct CommonEventSpec<const bt_event> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonEvent final : public internal::BorrowedObj<LibObjT>
+class CommonEvent final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonEventSpec<const bt_event>;
     using _Spec = internal::CommonEventSpec<LibObjT>;
 
@@ -146,19 +148,19 @@ public:
                                             CommonEventClass<const bt_event_class>,
                                             CommonEventClass<bt_event_class>>::type;
 
-    explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonEvent(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObj {event}
+    CommonEvent(const CommonEvent<OtherLibObjT> event) noexcept : _ThisBorrowedObject {event}
     {
     }
 
     template <typename OtherLibObjT>
     CommonEvent<LibObjT>& operator=(const CommonEvent<OtherLibObjT> event) noexcept
     {
-        _ThisBorrowedObj::operator=(event);
+        _ThisBorrowedObject::operator=(event);
         return *this;
     }
 
@@ -306,11 +308,11 @@ struct CommonPacketSpec<const bt_packet> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonPacket final : public internal::BorrowedObj<LibObjT>
+class CommonPacket final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonPacketSpec<const bt_packet>;
     using _Spec = internal::CommonPacketSpec<LibObjT>;
     using _ThisCommonPacket = CommonPacket<LibObjT>;
@@ -323,21 +325,21 @@ private:
                                                       ConstStructureField, StructureField>::type;
 
 public:
-    using Shared = internal::SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
+    using Shared = SharedObj<_ThisCommonPacket, LibObjT, internal::PacketRefFuncs>;
 
-    explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonPacket(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObj {packet}
+    CommonPacket(const CommonPacket<OtherLibObjT> packet) noexcept : _ThisBorrowedObject {packet}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonPacket& operator=(const CommonPacket<OtherLibObjT> packet) noexcept
     {
-        _ThisBorrowedObj::operator=(packet);
+        _ThisBorrowedObject::operator=(packet);
         return *this;
     }
 
@@ -480,11 +482,11 @@ struct CommonStreamSpec<const bt_stream> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonStream final : public internal::BorrowedObj<LibObjT>
+class CommonStream final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonStreamSpec<const bt_stream>;
     using _Spec = internal::CommonStreamSpec<LibObjT>;
     using _ThisCommonStream = CommonStream<LibObjT>;
@@ -494,7 +496,7 @@ private:
                                   CommonTrace<bt_trace>>::type;
 
 public:
-    using Shared = internal::SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
+    using Shared = SharedObj<_ThisCommonStream, LibObjT, internal::StreamRefFuncs>;
 
     using Class = typename std::conditional<std::is_const<LibObjT>::value,
                                             CommonStreamClass<const bt_stream_class>,
@@ -503,19 +505,19 @@ public:
     using UserAttributes =
         typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
 
-    explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonStream(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObj {stream}
+    CommonStream(const CommonStream<OtherLibObjT> stream) noexcept : _ThisBorrowedObject {stream}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonStream& operator=(const CommonStream<OtherLibObjT> stream) noexcept
     {
-        _ThisBorrowedObj::operator=(stream);
+        _ThisBorrowedObject::operator=(stream);
         return *this;
     }
 
@@ -710,14 +712,14 @@ struct CommonTraceSpec<const bt_trace> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonTrace final : public internal::BorrowedObj<LibObjT>
+class CommonTrace final : public BorrowedObject<LibObjT>
 {
     /* Allow instantiate() to call `trace.libObjPtr()` */
     friend class CommonStreamClass<bt_stream_class>;
 
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonTraceSpec<const bt_trace>;
     using _Spec = internal::CommonTraceSpec<LibObjT>;
     using _ThisCommonTrace = CommonTrace<LibObjT>;
@@ -727,7 +729,7 @@ private:
                                   CommonStream<bt_stream>>::type;
 
 public:
-    using Shared = internal::SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
+    using Shared = SharedObj<_ThisCommonTrace, LibObjT, internal::TraceRefFuncs>;
 
     using Class = typename std::conditional<std::is_const<LibObjT>::value,
                                             CommonTraceClass<const bt_trace_class>,
@@ -742,19 +744,19 @@ public:
         ConstValue value;
     };
 
-    explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonTrace(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObj {trace}
+    CommonTrace(const CommonTrace<OtherLibObjT> trace) noexcept : _ThisBorrowedObject {trace}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonTrace& operator=(const CommonTrace<OtherLibObjT> trace) noexcept
     {
-        _ThisBorrowedObj::operator=(trace);
+        _ThisBorrowedObject::operator=(trace);
         return *this;
     }
 
@@ -788,9 +790,9 @@ 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
@@ -1046,11 +1048,11 @@ struct CommonEventClassSpec<const bt_event_class> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonEventClass final : public internal::BorrowedObj<LibObjT>
+class CommonEventClass final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonEventClassSpec<const bt_event_class>;
     using _Spec = internal::CommonEventClassSpec<LibObjT>;
     using _ThisCommonEventClass = CommonEventClass<LibObjT>;
@@ -1064,8 +1066,7 @@ private:
                                   StructureFieldClass>::type;
 
 public:
-    using Shared =
-        internal::SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
+    using Shared = SharedObj<_ThisCommonEventClass, LibObjT, internal::EventClassRefFuncs>;
 
     using UserAttributes =
         typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
@@ -1089,20 +1090,20 @@ public:
         DEBUG = BT_EVENT_CLASS_LOG_LEVEL_DEBUG,
     };
 
-    explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonEventClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
     CommonEventClass(const CommonEventClass<OtherLibObjT> eventClass) noexcept :
-        _ThisBorrowedObj {eventClass}
+        _ThisBorrowedObject {eventClass}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonEventClass& operator=(const CommonEventClass<OtherLibObjT> eventClass) noexcept
     {
-        _ThisBorrowedObj::operator=(eventClass);
+        _ThisBorrowedObject::operator=(eventClass);
         return *this;
     }
 
@@ -1422,11 +1423,11 @@ struct CommonStreamClassSpec<const bt_stream_class> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonStreamClass final : public internal::BorrowedObj<LibObjT>
+class CommonStreamClass final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonStreamClassSpec<const bt_stream_class>;
     using _Spec = internal::CommonStreamClassSpec<LibObjT>;
     using _ThisCommonStreamClass = CommonStreamClass<LibObjT>;
@@ -1447,26 +1448,26 @@ private:
         typename std::conditional<std::is_const<LibObjT>::value, ConstClockClass, ClockClass>::type;
 
 public:
-    using Shared =
-        internal::SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
+    using Shared = SharedObj<_ThisCommonStreamClass, LibObjT, internal::StreamClassRefFuncs>;
 
     using UserAttributes =
         typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
 
-    explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonStreamClass(const _LibObjPtr libObjPtr) noexcept :
+        _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
     CommonStreamClass(const CommonStreamClass<OtherLibObjT> streamClass) noexcept :
-        _ThisBorrowedObj {streamClass}
+        _ThisBorrowedObject {streamClass}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonStreamClass& operator=(const CommonStreamClass<OtherLibObjT> streamClass) noexcept
     {
-        _ThisBorrowedObj::operator=(streamClass);
+        _ThisBorrowedObject::operator=(streamClass);
         return *this;
     }
 
@@ -1915,11 +1916,11 @@ struct CommonTraceClassSpec<const bt_trace_class> final
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonTraceClass final : public internal::BorrowedObj<LibObjT>
+class CommonTraceClass final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ConstSpec = internal::CommonTraceClassSpec<const bt_trace_class>;
     using _Spec = internal::CommonTraceClassSpec<LibObjT>;
     using _ThisCommonTraceClass = CommonTraceClass<LibObjT>;
@@ -1929,26 +1930,25 @@ private:
                                                    CommonStreamClass<bt_stream_class>>::type;
 
 public:
-    using Shared =
-        internal::SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
+    using Shared = SharedObj<_ThisCommonTraceClass, LibObjT, internal::TraceClassRefFuncs>;
 
     using UserAttributes =
         typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
 
-    explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonTraceClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
     CommonTraceClass(const CommonTraceClass<OtherLibObjT> traceClass) noexcept :
-        _ThisBorrowedObj {traceClass}
+        _ThisBorrowedObject {traceClass}
     {
     }
 
     template <typename OtherLibObjT>
     _ThisCommonTraceClass& operator=(const CommonTraceClass<OtherLibObjT> traceClass) noexcept
     {
-        _ThisBorrowedObj::operator=(traceClass);
+        _ThisBorrowedObject::operator=(traceClass);
         return *this;
     }
 
@@ -2185,17 +2185,15 @@ public:
     VariantWithUnsignedIntegerSelectorFieldClass::Shared
     createVariantWithUnsignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
-        return VariantWithUnsignedIntegerSelectorFieldClass {
-            this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}
-            .shared();
+        return this->_createVariantWithIntegerSelectorFieldClass<
+            VariantWithUnsignedIntegerSelectorFieldClass>(selectorFieldClass);
     }
 
     VariantWithSignedIntegerSelectorFieldClass::Shared
     createVariantWithSignedIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
-        return VariantWithSignedIntegerSelectorFieldClass {
-            this->_createVariantWithIntegerSelectorFieldClass(selectorFieldClass)}
-            .shared();
+        return this->_createVariantWithIntegerSelectorFieldClass<
+            VariantWithSignedIntegerSelectorFieldClass>(selectorFieldClass);
     }
 
     void assignsAutomaticStreamClassId(const bool val) noexcept
@@ -2273,7 +2271,8 @@ public:
     }
 
 private:
-    bt_field_class *
+    template <typename ObjT>
+    typename ObjT::Shared
     _createVariantWithIntegerSelectorFieldClass(const IntegerFieldClass selectorFieldClass)
     {
         static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
@@ -2282,7 +2281,7 @@ private:
             bt_field_class_variant_create(this->libObjPtr(), selectorFieldClass.libObjPtr());
 
         internal::validateCreatedObjPtr(libObjPtr);
-        return libObjPtr;
+        return ObjT::Shared::createWithoutRef(libObjPtr);
     }
 };
 
This page took 0.028443 seconds and 4 git commands to generate.