17 #ifndef BERRYSMARTPOINTER_H_
18 #define BERRYSMARTPOINTER_H_
27 #include <Poco/Bugcheck.h>
29 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
48 template<
class TObjectType>
59 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
60 DebugInitSmartPointer();
72 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
73 DebugInitSmartPointer();
79 m_Pointer(p.m_Pointer)
83 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
84 DebugInitSmartPointer();
90 m_Pointer(const_cast<Other*> (ptr.
GetPointer()))
95 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
96 DebugInitSmartPointer();
100 template<
class Other>
106 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
107 if (m_Pointer) DebugRemoveSmartPointer();
114 template<
class Other>
117 Other* pOther =
dynamic_cast<Other*
> (m_Pointer);
135 poco_assert( m_Pointer !=
nullptr );
142 return m_Pointer !=
nullptr;
146 return m_Pointer ==
nullptr;
153 return m_Pointer ==
nullptr ?
nullptr: &Self::m_Pointer;
160 return (m_Pointer ==
nullptr ? o ==
nullptr : (o && m_Pointer->operator==(o)));
167 return (m_Pointer ==
nullptr ? o ==
nullptr : (o && m_Pointer->operator==(o)));
173 return m_Pointer ==
nullptr;
175 throw std::invalid_argument(
"Can only compare to 0");
193 return m_Pointer !=
nullptr;
195 throw std::invalid_argument(
"Can only compare to 0");
220 bool operator <(const SmartPointer<R>& r)
const
222 const R* o = r.GetPointer();
223 return m_Pointer ==
nullptr ? o ==
nullptr : o && m_Pointer->operator<(o);
231 return m_Pointer == 0 ? o == 0 : o && m_Pointer->operator>(o);
236 bool operator <=(const SmartPointer<R>& r)
const
266 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
267 DebugAssignSmartPointer(r, m_Pointer);
269 ObjectType* tmp = m_Pointer;
281 QDebug
Print(QDebug os)
const;
286 ObjectType* m_Pointer;
292 m_Pointer->Register();
300 m_Pointer->UnRegister();
304 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
309 void DebugInitSmartPointer();
311 void DebugRemoveSmartPointer();
313 void DebugAssignSmartPointer(
const ObjectType* newObject,
const ObjectType* oldObject);
324 std::ostream& operator<<(std::ostream& os, const SmartPointer<T>& p)
326 os << p->ToString().toStdString();
335 return sp->HashCode();
346 return sp->HashCode();
355 template<
class Other>
360 this->m_Pointer = wp.m_Pointer;
363 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
364 DebugInitSmartPointer();
369 throw BadWeakPointerException(
"Weak pointer is NULL");
378 (*m_Pointer).Print(os);
384 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER)
391 void SmartPointer<T>::DebugInitSmartPointer()
394 QMutexLocker lock(&m_Mutex);
409 void SmartPointer<T>::DebugRemoveSmartPointer()
411 QMutexLocker lock(&m_Mutex);
416 void SmartPointer<T>::DebugAssignSmartPointer(
const ObjectType* newObject,
const ObjectType* oldObject)
418 QMutexLocker lock(&m_Mutex);
434 int SmartPointer<T>::GetId()
bool operator!=(const R *r) const
static void UnregisterSmartPointer(unsigned int smartPointerId, const Object *objectPointer)
void UnRegister(bool del=true) const
SmartPointer & operator=(const SmartPointer &r)
static unsigned int & GetSmartPointerCounter()
Implements transparent reference counting.
SmartPointer(const SmartPointer< ObjectType > &p)
implements a WeakPointer class to deal with circular reference problems.
QDebug Print(QDebug os) const
ObjectType *Self::* unspecified_bool_type
SmartPointer(const SmartPointer< Other > &ptr)
bool operator>(const SmartPointer< R > &r) const
uint qHash(const berry::SmartPointer< T > &sp)
static void RegisterSmartPointer(unsigned int smartPointerId, const Object *objectPointer, bool recordStack=false)
SmartPointer(ObjectType *p)
ObjectType * operator->() const
ObjectType * GetPointer() const
SmartPointer< Other > Cast() const
bool operator==(const R *o) const
SmartPointer< ObjectType > Lock() const
bool operator>=(const SmartPointer< R > &r) const
bool operator<(const SmartPointer< R > &r) const
ObjectType & operator*() const