cpp-common/bt2: use `bt2::OptionalBorrowedObject` where possible
[babeltrace.git] / src / cpp-common / bt2 / shared-object.hpp
index 3b5ccfa259d93996a7c1b925385608d8180d1146..406172d80577b929ea0a8745e6544425fd6a7791 100644 (file)
@@ -7,8 +7,11 @@
 #ifndef BABELTRACE_CPP_COMMON_BT2_SHARED_OBJECT_HPP
 #define BABELTRACE_CPP_COMMON_BT2_SHARED_OBJECT_HPP
 
+#include <utility>
+
 #include "common/assert.h"
-#include "cpp-common/bt2s/optional.hpp"
+
+#include "optional-borrowed-object.hpp"
 
 namespace bt2 {
 
@@ -230,33 +233,21 @@ public:
         this->_putRef();
     }
 
-    ObjT& operator*() noexcept
-    {
-        BT_ASSERT_DBG(_mObj);
-        return *_mObj;
-    }
-
-    const ObjT& operator*() const noexcept
+    ObjT operator*() const noexcept
     {
         BT_ASSERT_DBG(_mObj);
         return *_mObj;
     }
 
-    ObjT *operator->() noexcept
+    BorrowedObjectProxy<ObjT> operator->() const noexcept
     {
         BT_ASSERT_DBG(_mObj);
-        return &*_mObj;
-    }
-
-    const ObjT *operator->() const noexcept
-    {
-        BT_ASSERT_DBG(_mObj);
-        return &*_mObj;
+        return _mObj.operator->();
     }
 
     operator bool() const noexcept
     {
-        return _mObj.has_value();
+        return _mObj.hasObject();
     }
 
     /*
@@ -304,9 +295,7 @@ private:
      */
     void _getRef() const noexcept
     {
-        if (_mObj) {
-            RefFuncsT::get(_mObj->libObjPtr());
-        }
+        RefFuncsT::get(_mObj.libObjPtr());
     }
 
     /*
@@ -315,12 +304,10 @@ private:
      */
     void _putRef() const noexcept
     {
-        if (_mObj) {
-            RefFuncsT::put(_mObj->libObjPtr());
-        }
+        RefFuncsT::put(_mObj.libObjPtr());
     }
 
-    bt2s::optional<ObjT> _mObj;
+    OptionalBorrowedObject<ObjT> _mObj;
 };
 
 } /* namespace bt2 */
This page took 0.024433 seconds and 4 git commands to generate.