X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/779cb6e326391280631d0b486957d5e576eb23ea..8e60bdc64c73787b8e7955a6a99ad5afe4a071ef:/lib/base/smartptr.h diff --git a/lib/base/smartptr.h b/lib/base/smartptr.h index f9d224b0..a2c6691f 100644 --- a/lib/base/smartptr.h +++ b/lib/base/smartptr.h @@ -5,6 +5,8 @@ #include #include +inline void ptrAssert(void *p) { if (!p) *(unsigned long*)0=0; } + template class ePtr { @@ -52,9 +54,12 @@ public: ptr->Release(); } +#ifndef SWIG T* grabRef() { if (!ptr) return 0; ptr->AddRef(); return ptr; } - T* &ptrref() { assert(!ptr); return ptr; } - T* operator->() const { 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; } }; @@ -127,9 +132,11 @@ public: } } +#ifndef SWIG T* grabRef() { if (!ptr) return 0; ptr->AddRef(); ptr->AddUse(); return ptr; } - T* &ptrref() { assert(!ptr); return ptr; } - T* operator->() const { assert(ptr); return ptr; } + T* &ptrref() { ASSERT(!ptr); return ptr; } +#endif + T* operator->() const { ptrAssert(ptr); return ptr; } operator T*() const { return this->ptr; } }; @@ -177,13 +184,13 @@ public: } - ePtrHelper operator->() { assert(ptr); return ePtrHelper(ptr); } + 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 */ /* eMutablePtrs note that they have to be const. */ - const T* operator->() const { assert(ptr); return ptr; } + const T* operator->() const { ptrAssert(ptr); return ptr; } }; #endif