X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/3bad22d5566624804a73b3791980bab2d84c8266..4bc08995411e21f3564f09e136809be68ddf96a8:/lib/base/smartptr.h diff --git a/lib/base/smartptr.h b/lib/base/smartptr.h index aafecf0e..906bba69 100644 --- a/lib/base/smartptr.h +++ b/lib/base/smartptr.h @@ -7,22 +7,6 @@ template class ePtr { - /* read doc/iObject about the ePtrHelper */ - template - class ePtrHelper - { - T1 *m_obj; - public: - inline ePtrHelper(T1 *obj): m_obj(obj) - { - m_obj->AddRef(); - } - inline ~ePtrHelper() - { - m_obj->Release(); - } - inline T1* operator->() { return m_obj; } - }; protected: T *ptr; public: @@ -69,15 +53,62 @@ public: T* grabRef() { if (!ptr) return 0; ptr->AddRef(); return ptr; } T* &ptrref() { assert(!ptr); return ptr; } + T* operator->() const { assert(ptr); return ptr; } + operator T*() const { return this->ptr; } +}; + + + +#ifndef SWIG +template +class eMutablePtr: public ePtr +{ + /* read doc/iObject about the ePtrHelper */ + template + class ePtrHelper + { + T1 *m_obj; + public: + inline ePtrHelper(T1 *obj): m_obj(obj) + { + m_obj->AddRef(); + } + inline ~ePtrHelper() + { + m_obj->Release(); + } + inline T1* operator->() { return m_obj; } + }; +protected: + T *ptr; +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->() { assert(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 */ - /* ePtrs note that they have to be const. */ + /* eMutablePtrs note that they have to be const. */ const T* operator->() const { assert(ptr); return ptr; } - operator T*() const { return this->ptr; } }; - +#endif #endif