]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/base/CbcPointer.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / base / CbcPointer.h
index 3bed8db2aae112acb80130d997aeb9d7c9410ca8..e84449668103b338c09eabaf963dfbb7bb7a9e6d 100644 (file)
@@ -1,8 +1,17 @@
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #ifndef SQUID_CBC_POINTER_H
 #define SQUID_CBC_POINTER_H
 
 #include "base/TextException.h"
 #include "cbdata.h"
+#include "Debug.h"
 
 /**
  \ingroup CBDATAAPI
@@ -19,6 +28,7 @@ public:
     CbcPointer(); // a nil pointer
     CbcPointer(Cbc *aCbc);
     CbcPointer(const CbcPointer &p);
+    CbcPointer(CbcPointer &&);
     ~CbcPointer();
 
     Cbc *raw() const; ///< a temporary raw Cbc pointer; may be invalid
@@ -33,6 +43,7 @@ public:
     bool operator ==(const CbcPointer<Cbc> &o) const { return lock == o.lock; }
 
     CbcPointer &operator =(const CbcPointer &p);
+    CbcPointer &operator =(CbcPointer &&);
 
     /// support converting a child cbc pointer into a parent cbc pointer
     template <typename Other>
@@ -90,6 +101,13 @@ CbcPointer<Cbc>::CbcPointer(const CbcPointer &d): cbc(d.cbc), lock(NULL)
         lock = cbdataReference(d.lock);
 }
 
+template<class Cbc>
+CbcPointer<Cbc>::CbcPointer(CbcPointer &&d): cbc(d.cbc), lock(d.lock)
+{
+    d.cbc = nullptr;
+    d.lock = nullptr;
+}
+
 template<class Cbc>
 CbcPointer<Cbc>::~CbcPointer()
 {
@@ -108,10 +126,26 @@ CbcPointer<Cbc> &CbcPointer<Cbc>::operator =(const CbcPointer &d)
     return *this;
 }
 
+template<class Cbc>
+CbcPointer<Cbc> &CbcPointer<Cbc>::operator =(CbcPointer &&d)
+{
+    if (this != &d) { // assignment to self
+        clear();
+        cbc = d.cbc;
+        d.cbc = nullptr;
+        lock = d.lock;
+        d.lock = nullptr;
+    }
+    return *this;
+}
+
 template<class Cbc>
 void
 CbcPointer<Cbc>::clear()
 {
+#if USE_CBDATA_DEBUG
+    debugs(45, 3, "cbc=" << (void*)cbc << ", lock=" << (void*)lock);
+#endif
     cbdataReferenceDone(lock); // lock may be nil before and will be nil after
     cbc = NULL;
 }
@@ -155,3 +189,4 @@ std::ostream &CbcPointer<Cbc>::print(std::ostream &os) const
 }
 
 #endif /* SQUID_CBC_POINTER_H */
+