+/*
+ * 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
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
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>
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()
{
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;
}
CbcPointer<Cbc>::operator *() const
{
Cbc *c = get();
- Must(c);
+ assert(c);
return *c;
}
CbcPointer<Cbc>::operator ->() const
{
Cbc *c = get();
- Must(c);
+ assert(c);
return c;
}
}
#endif /* SQUID_CBC_POINTER_H */
+