author | alwin <alwin> | 2004-03-11 22:52:07 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-03-11 22:52:07 (UTC) |
commit | 83b7f42d5f93e1657705584d3d626b8d8fde28ac (patch) (side-by-side diff) | |
tree | 6510078c79ae4b5f1fb2fdcfb71ad5a1247c8ad0 | |
parent | 31fe5681a49cbcf291abf755ee5f2f2fb1e4a582 (diff) | |
download | opie-83b7f42d5f93e1657705584d3d626b8d8fde28ac.zip opie-83b7f42d5f93e1657705584d3d626b8d8fde28ac.tar.gz opie-83b7f42d5f93e1657705584d3d626b8d8fde28ac.tar.bz2 |
*sigh* forgot to test before first checkin. sorry.
-rw-r--r-- | libopie2/opiecore/osmart_pointer.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opiecore/osmart_pointer.h b/libopie2/opiecore/osmart_pointer.h index a362a60..2a2518f 100644 --- a/libopie2/opiecore/osmart_pointer.h +++ b/libopie2/opiecore/osmart_pointer.h @@ -46,99 +46,99 @@ class oref_count { protected: //! reference count member long m_RefCount; public: //! first reference must be added after "new" via Pointer() oref_count() : m_RefCount(0) {} virtual ~oref_count() {} //! add a reference void Incr() { ++m_RefCount; } //! delete a reference void Decr() { --m_RefCount; } //! is it referenced bool Shared() { return (m_RefCount > 0); } }; //! reference counting wrapper class template<class T> class osmart_pointer { //! pointer to object /*! * this object must contain Incr(), Decr() and Shared() * methode as public members. The best way is, that it will be a child * class of RefCount */ T *ptr; public: //! standart constructor osmart_pointer() { ptr = NULL; } //! standart destructor /*! * release the reference, if it were the last reference, destroys * ptr */ ~osmart_pointer() { if (ptr){ ptr->Decr(); if (!ptr->Shared()) delete ptr; } } //! construction osmart_pointer(T* t) { if (ptr = t) ptr->Incr(); } //! Pointer copy - osmart_pointer(const smart_pointer<T>& p) + osmart_pointer(const osmart_pointer<T>& p) { if (ptr = p.ptr) ptr->Incr(); } //! pointer copy by assignment - osmart_pointer<T>& operator= (const smart_pointer<T>& p) + osmart_pointer<T>& operator= (const osmart_pointer<T>& p) { // already same: nothing to do if (ptr == p.ptr) return *this; // decouple reference if (ptr) { ptr->Decr(); if (!ptr->Shared()) delete ptr; } // establish new reference if (ptr = p.ptr) ptr->Incr(); return *this; } osmart_pointer<T>& operator= (T*p) { if (ptr==p)return *this; if (ptr) { ptr->Decr(); if (!ptr->Shared()) delete ptr; } if (ptr=p) ptr->Incr(); return *this; } //! cast to conventional pointer operator T* () const { return ptr; } //! deref: fails for NULL pointer T& operator* () {return *ptr; } //! deref: fails for NULL pointer const T& operator* ()const {return *ptr; } //! deref with method call T* operator-> () {return ptr; } //! deref with const method call const T* operator-> ()const {return ptr; } //! supports "if (pointer)" operator bool () const { return (ptr != NULL); } //! "if (pointer)" as non const operator bool () { return ptr != NULL;} //! support if (!pointer)" bool operator! () const { return (ptr == NULL); } //! support if (!pointer)" as non const bool operator! () { return (ptr == NULL); } }; } #endif |