Add bt2::internal::SharedObj::create{With,Without}Ref() methods
[babeltrace.git] / src / cpp-common / bt2 / internal / shared-obj.hpp
index da8df2380c098aa59131753a911e563610b6de20..d16eb94010e54ebd93f8f0f77d3efcf6877a0702 100644 (file)
@@ -45,37 +45,53 @@ class SharedObj final
     template <typename AnyObjT, typename AnyLibObjT, typename AnyRefFuncsT>
     friend class SharedObj;
 
+private:
+    /*
+     * Builds a shared object from `obj` without getting a reference.
+     */
+    explicit SharedObj(const ObjT& obj) noexcept : _mObj {obj}
+    {
+    }
+
 public:
-    /* This complete shared object */
-    using ThisSharedObj = SharedObj<ObjT, LibObjT, RefFuncsT>;
+    /*
+     * Builds a shared object from `obj` without getting a reference.
+     */
+    static SharedObj createWithoutRef(const ObjT& obj) noexcept
+    {
+        return SharedObj {obj};
+    }
 
     /*
-     * Builds a shared object from `obj` without an initial reference.
-     *
-     * Use this constructor to build a shared object wrapping a newly
-     * created libbabeltrace2 object.
-     *
-     * Use createWithInitialRef() to build a shared object having an
-     * initial reference count.
+     * Builds a shared object from `libObjPtr` without getting a
+     * reference.
      */
-    explicit SharedObj(const ObjT& obj) noexcept : _mObj {obj}
+    static SharedObj createWithoutRef(LibObjT * const libObjPtr) noexcept
     {
+        return SharedObj::createWithoutRef(ObjT {libObjPtr});
     }
 
     /*
-     * Builds a shared object from `obj` with an initial reference.
-     *
-     * Use this constructor to build a shared object wrapping a newly
-     * created libbabeltrace2 object.
+     * Builds a shared object from `obj`, immediately getting a new
+     * reference.
      */
-    static ThisSharedObj createWithInitialRef(const ObjT& obj) noexcept
+    static SharedObj createWithRef(const ObjT& obj) noexcept
     {
-        ThisSharedObj sharedObj {obj};
+        SharedObj sharedObj {obj};
 
         sharedObj._getRef();
         return sharedObj;
     }
 
+    /*
+     * Builds a shared object from `libObjPtr`, immediately getting a new
+     * reference.
+     */
+    static SharedObj createWithRef(LibObjT * const libObjPtr) noexcept
+    {
+        return SharedObj::createWithRef(ObjT {libObjPtr});
+    }
+
     /*
      * Generic copy constructor.
      *
@@ -106,7 +122,7 @@ public:
      * See the `friend class SharedObj` comment above.
      */
     template <typename OtherObjT, typename OtherLibObjT>
-    ThisSharedObj& operator=(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other) noexcept
+    SharedObj& operator=(const SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>& other) noexcept
     {
         /* Put current object's reference */
         this->_putRef();
@@ -124,7 +140,7 @@ public:
      * See the `friend class SharedObj` comment above.
      */
     template <typename OtherObjT, typename OtherLibObjT>
-    ThisSharedObj& operator=(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other) noexcept
+    SharedObj& operator=(SharedObj<OtherObjT, OtherLibObjT, RefFuncsT>&& other) noexcept
     {
         /* Put current object's reference */
         this->_putRef();
This page took 0.02501 seconds and 4 git commands to generate.