00001 #ifndef POINTER_H_INCLUDED
00002 #define POINTER_H_INCLUDED
00003
00004 template <class T>
00005 class Pointer{
00006 public:
00007
00008 Pointer (T* Object = NULL);
00009 Pointer (const Pointer& pointer);
00010 ~Pointer ();
00011
00012 operator T* () const{return pobject;}
00013 T& operator* () const;
00014 T* operator-> () const;
00015
00016 Pointer& operator= (T* Object);
00017 Pointer& operator= (const Pointer& reference);
00018
00019 bool operator== (T* pkObject) const;
00020 bool operator!= (T* pkObject) const;
00021 bool operator== (const Pointer& rkReference) const;
00022 bool operator!= (const Pointer& rkReference) const;
00023
00024 protected:
00025
00026 T* pobject;
00027 };
00028
00029
00030 template <class T>
00031 Pointer<T>::Pointer (T* object){
00032 pbject = object;
00033 if ( pobject )
00034 pobject->incRef();
00035 }
00036 template <class T>
00037 Pointer<T>::Pointer (const Pointer& pointer){
00038 pobject = pointer.pobject;
00039 if ( pobject )
00040 pobject->incRef();
00041 }
00042 template <class T>
00043 Pointer<T>::~Pointer (){
00044 if ( pobject )
00045 pobject->decRef();
00046 }
00047
00048
00049 template <class T>
00050 T& Pointer<T>::operator* () const{
00051 return *pobject;
00052 }
00053
00054 template <class T>
00055 T* Pointer<T>::operator-> () const{
00056 return pobject;
00057 }
00058
00059
00060 template <class T>
00061 Pointer<T>& Pointer<T>::operator= (T* pkObject){
00062
00063 if ( pobject != pkObject ){
00064
00065 if ( pkObject )
00066 pkObject->incRef();
00067
00068 if ( pobject )
00069 pobject->decRef();
00070
00071 pobject = pkObject;
00072 }
00073 return *this;
00074 }
00075
00076 template <class T>
00077 Pointer<T>& Pointer<T>::operator= (Pointer<T>& reference){
00078
00079 if ( reference.pobject )
00080 reference.pobject->incRef();
00081
00082 if ( pobject )
00083 pobject->decRef();
00084
00085 pobject = reference.pobject;
00086
00087 return *this;
00088 }
00089
00090
00091 template <class T>
00092 bool operator== (T* pkObject) const;
00093
00094 template <class T>
00095 bool operator!= (T* pkObject) const;
00096
00097 template <class T>
00098 bool operator== (const Pointer& rkReference) const;
00099
00100 template <class T>
00101 bool operator!= (const Pointer& rkReference) const;
00102
00103 #endif