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.
*
* 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();
* 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();