13 #ifndef BERRYSMARTPOINTER_H_ 14 #define BERRYSMARTPOINTER_H_ 23 #include <Poco/Bugcheck.h> 25 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 44 template<
class TObjectType>
55 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 56 DebugInitSmartPointer();
68 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 69 DebugInitSmartPointer();
75 m_Pointer(p.m_Pointer)
79 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 80 DebugInitSmartPointer();
91 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 92 DebugInitSmartPointer();
102 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 103 if (m_Pointer) DebugRemoveSmartPointer();
110 template<
class Other>
113 Other* pOther =
dynamic_cast<Other*
> (m_Pointer);
131 poco_assert( m_Pointer !=
nullptr );
138 return m_Pointer !=
nullptr;
142 return m_Pointer ==
nullptr;
149 return m_Pointer ==
nullptr ?
nullptr: &Self::m_Pointer;
156 return (m_Pointer ==
nullptr ? o ==
nullptr : (o && m_Pointer->operator==(o)));
163 return (m_Pointer ==
nullptr ? o ==
nullptr : (o && m_Pointer->operator==(o)));
169 return m_Pointer ==
nullptr;
171 throw std::invalid_argument(
"Can only compare to 0");
189 return m_Pointer !=
nullptr;
191 throw std::invalid_argument(
"Can only compare to 0");
216 bool operator <(const SmartPointer<R>& r)
const 218 const R* o = r.GetPointer();
219 return m_Pointer ==
nullptr ? o == nullptr : o && m_Pointer->operator<(o);
227 return m_Pointer == 0 ? o == 0 : o && m_Pointer->operator>(o);
232 bool operator <=(const SmartPointer<R>& r)
const 262 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 263 DebugAssignSmartPointer(r, m_Pointer);
265 ObjectType* tmp = m_Pointer;
277 QDebug
Print(QDebug os)
const;
282 ObjectType* m_Pointer;
288 m_Pointer->Register();
296 m_Pointer->UnRegister();
300 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 305 void DebugInitSmartPointer();
307 void DebugRemoveSmartPointer();
309 void DebugAssignSmartPointer(
const ObjectType* newObject,
const ObjectType* oldObject);
320 std::ostream& operator<<(std::ostream& os, const SmartPointer<T>& p)
322 os << p->ToString().toStdString();
331 return sp->HashCode();
342 return sp->HashCode();
351 template<
class Other>
356 this->m_Pointer = wp.m_Pointer;
359 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 360 DebugInitSmartPointer();
365 throw BadWeakPointerException(
"Weak pointer is nullptr");
374 (*m_Pointer).Print(os);
380 #if defined(BLUEBERRY_DEBUG_SMARTPOINTER) 390 QMutexLocker lock(&m_Mutex);
407 QMutexLocker lock(&m_Mutex);
414 QMutexLocker lock(&m_Mutex);
static void RegisterSmartPointer(unsigned int smartPointerId, const Object *objectPointer, bool recordStack=false)
ObjectType * operator->() const
SmartPointer< Other > Cast() const
SmartPointer & operator=(const SmartPointer &r)
Implements transparent reference counting.
SmartPointer(const SmartPointer< ObjectType > &p)
implements a WeakPointer class to deal with circular reference problems.
SmartPointer< ObjectType > Lock() const
ObjectType *Self::* unspecified_bool_type
SmartPointer(const SmartPointer< Other > &ptr)
bool operator!=(const R *r) const
static void UnregisterSmartPointer(unsigned int smartPointerId, const Object *objectPointer)
bool operator>=(const SmartPointer< R > &r) const
uint qHash(const berry::SmartPointer< T > &sp)
static unsigned int & GetSmartPointerCounter()
ObjectType & operator*() const
bool operator>(const SmartPointer< R > &r) const
bool operator<(const SmartPointer< R > &r) const
bool operator==(const R *o) const
SmartPointer(ObjectType *p)
QDebug Print(QDebug os) const
ObjectType * GetPointer() const