diff options
Diffstat (limited to 'mgizapp/src/Pointer.h')
-rw-r--r-- | mgizapp/src/Pointer.h | 200 |
1 files changed, 124 insertions, 76 deletions
diff --git a/mgizapp/src/Pointer.h b/mgizapp/src/Pointer.h index fd05688..1552678 100644 --- a/mgizapp/src/Pointer.h +++ b/mgizapp/src/Pointer.h @@ -9,14 +9,14 @@ modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. -This program is distributed in the hope that it will be useful, +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -29,141 +29,189 @@ USA. template<class T> class SmartPointer { - protected: +protected: T*p; - public: - SmartPointer(T*_p=0) +public: + SmartPointer(T*_p=0) : p(_p) {} - inline T&operator*() const - {return *p;} - inline T*operator->() const - {return p;} - inline operator bool() const - {return p!=0;} - inline T*ptr() const - { return p; } + inline T&operator*() const { + return *p; + } + inline T*operator->() const { + return p; + } + inline operator bool() const { + return p!=0; + } + inline T*ptr() const { + return p; + } }; template<class T> inline ostream &operator<<(ostream&out,const SmartPointer<T>&s) -{if( s.ptr() )return out << *s;else return out <<"nullpointer";} +{ + if( s.ptr() )return out << *s; + else return out <<"nullpointer"; +} template<class T> class SmartPointerConst { - protected: +protected: const T*p; - public: - SmartPointerConst(const T*_p=0) +public: + SmartPointerConst(const T*_p=0) : p(_p) {} - inline const T&operator*() const - {return *p;} - inline const T*operator->() const - {return p;} - inline operator bool() const - {return p!=0;} - inline const T*ptr() const - { return p; } + inline const T&operator*() const { + return *p; + } + inline const T*operator->() const { + return p; + } + inline operator bool() const { + return p!=0; + } + inline const T*ptr() const { + return p; + } }; template<class T> inline ostream &operator<<(ostream&out,const SmartPointerConst<T>&s) -{if( s.ptr() )return out << *s;else return out <<"nullpointer";} +{ + if( s.ptr() )return out << *s; + else return out <<"nullpointer"; +} template <class T> class UP : public SmartPointer<T> { - public: - UP(T*_p=0) +public: + UP(T*_p=0) : SmartPointer<T>(_p) {} }; template<class T> inline bool operator==(const UP<T>&s1,const UP<T>&s2) -{return s1.ptr()==s2.ptr();} +{ + return s1.ptr()==s2.ptr(); +} template<class T> inline bool operator<(const UP<T>&s1,const UP<T>&s2) -{return s1.ptr() < s2.ptr();} +{ + return s1.ptr() < s2.ptr(); +} template<class T> inline int Hash(const UP<T> &wp) -{if(wp.ptr())return Hash(*wp);else return 0;} +{ + if(wp.ptr())return Hash(*wp); + else return 0; +} template <class T> class UPConst : public SmartPointerConst<T> { - public: - UPConst(const T*_p=0) +public: + UPConst(const T*_p=0) : SmartPointerConst<T>(_p) {} }; template<class T> inline bool operator==(const UPConst<T>&s1,const UPConst<T>&s2) -{return s1.ptr()==s2.ptr();} +{ + return s1.ptr()==s2.ptr(); +} template<class T> inline bool operator<(const UPConst<T>&s1,const UPConst<T>&s2) -{return s1.ptr()<s2.ptr();} +{ + return s1.ptr()<s2.ptr(); +} template<class T> inline int Hash(const UPConst<T> &wp) -{if(wp.ptr())return Hash(*wp);else return 0;} +{ + if(wp.ptr())return Hash(*wp); + else return 0; +} + - template <class T> class MP : public SmartPointer<T> { - public: - MP(T*_p=0) +public: + MP(T*_p=0) : SmartPointer<T>(_p) {} }; template <class T> inline bool operator==(const MP<T>&s1,const MP<T>&s2) -{assert(s1);assert(s2);return *s1==*s2;} +{ + assert(s1); + assert(s2); + return *s1==*s2; +} template <class T> inline bool operator<(const MP<T>&s1,const MP<T>&s2) -{assert(s1);assert(s2);return *s1 < *s2;} +{ + assert(s1); + assert(s2); + return *s1 < *s2; +} template <class T> inline int Hash(const MP<T> &wp) -{if(wp.ptr())return Hash(*wp);else return 0;} +{ + if(wp.ptr())return Hash(*wp); + else return 0; +} template <class T> class MPConst : public SmartPointerConst<T> { - public: - MPConst(const T*_p=0) +public: + MPConst(const T*_p=0) : SmartPointerConst<T>(_p) {} }; template <class T> inline bool operator==(const MPConst<T>&s1,const MPConst<T>&s2) -{assert(s1);assert(s2);return *s1== *s2;} +{ + assert(s1); + assert(s2); + return *s1== *s2; +} template <class T> inline bool operator<(const MPConst<T>&s1,const MPConst<T>&s2) -{assert(s1);assert(s2);return *s1 < *s2;} +{ + assert(s1); + assert(s2); + return *s1 < *s2; +} template <class T> inline int Hash(const MPConst<T> &wp) -{if(wp.ptr())return Hash(*wp);else return 0;} +{ + if(wp.ptr())return Hash(*wp); + else return 0; +} -template <class T> +template <class T> class DELP : public SmartPointer<T> { - private: +private: DELP(const DELP<T>&x); - public: - const DELP<T>&operator=(DELP<T>&x) - { +public: + const DELP<T>&operator=(DELP<T>&x) { delete this->p; - this->p=x.p;x.p=0; + this->p=x.p; + x.p=0; return *this; } - ~DELP() - { delete this->p;this->p=0;} - DELP(T*_p=0) + ~DELP() { + delete this->p; + this->p=0; + } + DELP(T*_p=0) : SmartPointer<T>(_p) {} - void set(T*_p) - { - delete this->p; - this->p=_p; - } - friend bool operator==(const DELP<T>&s1,const DELP<T>&s2) - { - return *(s1.p)== *(s2.p); - } - friend bool operator<(const DELP<T>&s1,const DELP<T>&s2) - { - return *(s1.p) < *(s2.p); - } - friend inline int Hash(const DELP<T> &wp) - { - if(wp.p) - return Hash(*wp.p); - else - return 0; - } + void set(T*_p) { + delete this->p; + this->p=_p; + } + friend bool operator==(const DELP<T>&s1,const DELP<T>&s2) { + return *(s1.p)== *(s2.p); + } + friend bool operator<(const DELP<T>&s1,const DELP<T>&s2) { + return *(s1.p) < *(s2.p); + } + friend inline int Hash(const DELP<T> &wp) { + if(wp.p) + return Hash(*wp.p); + else + return 0; + } }; #endif |