X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/cceb3c9e6ec5c92240f592e3a435ca25ce1facca..HEAD:/lib/base/smartptr.h diff --git a/lib/base/smartptr.h b/lib/base/smartptr.h index 6c3dbc2f..be83528f 100644 --- a/lib/base/smartptr.h +++ b/lib/base/smartptr.h @@ -3,6 +3,7 @@ #include "object.h" #include +#include #include inline void ptrAssert(void *p) { if (!p) *(unsigned long*)0=0; } @@ -12,6 +13,18 @@ class ePtr { protected: T *ptr; + char m_ptrStr[sizeof(void*)*2+1]; + void updatePtrStr() + { + if (ptr) { + if (sizeof(void*) > 4) + sprintf(m_ptrStr, "%llx", (unsigned long long)ptr); + else + sprintf(m_ptrStr, "%lx", (unsigned long)ptr); + } + else + strcpy(m_ptrStr, "NIL"); + } public: T &operator*() { return *ptr; } ePtr(): ptr(0) @@ -21,12 +34,13 @@ public: { if (c) c->AddRef(); + updatePtrStr(); } - ePtr(const ePtr &c) + ePtr(const ePtr &c): ptr(c.ptr) { - ptr=c.ptr; if (ptr) ptr->AddRef(); + updatePtrStr(); } ePtr &operator=(T *c) { @@ -35,9 +49,9 @@ public: if (ptr) ptr->Release(); ptr=c; + updatePtrStr(); return *this; } - ePtr &operator=(ePtr &c) { if (c.ptr) @@ -45,21 +59,25 @@ public: if (ptr) ptr->Release(); ptr=c.ptr; + updatePtrStr(); return *this; } - ~ePtr() { if (ptr) ptr->Release(); } - + char *getPtrString() + { + return m_ptrStr; + } +#ifndef SWIG T* grabRef() { if (!ptr) return 0; ptr->AddRef(); return ptr; } - T* &ptrref() { assert(!ptr); return ptr; } + T* &ptrref() { ASSERT(!ptr); return ptr; } + operator bool() const { return !!this->ptr; } +#endif T* operator->() const { ptrAssert(ptr); return ptr; } operator T*() const { return this->ptr; } - - operator bool() const { return !!this->ptr; } }; @@ -105,7 +123,6 @@ public: ptr=c; return *this; } - eUsePtr &operator=(eUsePtr &c) { if (c.ptr) @@ -121,7 +138,6 @@ public: ptr=c.ptr; return *this; } - ~eUsePtr() { if (ptr) @@ -130,9 +146,10 @@ public: ptr->Release(); } } - +#ifndef SWIG T* grabRef() { if (!ptr) return 0; ptr->AddRef(); ptr->AddUse(); return ptr; } - T* &ptrref() { assert(!ptr); return ptr; } + T* &ptrref() { ASSERT(!ptr); return ptr; } +#endif T* operator->() const { ptrAssert(ptr); return ptr; } operator T*() const { return this->ptr; } }; @@ -165,24 +182,18 @@ public: eMutablePtr(): ePtr(0) { } - eMutablePtr(T *c): ePtr(c) { } - eMutablePtr(const eMutablePtr &c): ePtr(c) { } - eMutablePtr &operator=(T *c) { ePtr::operator=(c); return *this; } - - ePtrHelper operator->() { ptrAssert(ptr); return ePtrHelper(ptr); } - /* for const objects, we don't need the helper, as they can't */ /* be changed outside the program flow. at least this is */ /* what the compiler assumes, so in case you're using const */