Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

RCPtr.h

Go to the documentation of this file.
00001 
00002 #ifndef RCPTR_H
00003 #define RCPTR_H
00004 
00061 template <class T>
00062 class RCPtr 
00063 {
00064 public:
00065   RCPtr(T* realPtr = 0);
00066   RCPtr(const RCPtr &rhs);
00067   ~RCPtr();
00068 
00069   bool operator ==(const RCPtr& rhs );
00070   RCPtr& operator=(const RCPtr& rhs );
00071 
00072   T* operator->() const;
00073   T& operator*() const;
00074 
00075 private:
00076   T *pointee;
00077   void init();
00078 };
00079 
00080 
00081 template <class T>
00082 inline 
00083 void RCPtr<T>::init()
00084 {
00085   if (pointee != 0) {
00086     pointee->addReference();
00087   }
00088 } // init
00089 
00090 
00091 template<class T>
00092 inline 
00093 RCPtr<T>::RCPtr(T* realPtr) : pointee(realPtr)
00094 {
00095   init();
00096 }
00097 
00098 template<class T>
00099 inline 
00100 RCPtr<T>::RCPtr( const RCPtr& rhs) : pointee( rhs.pointee )
00101 {
00102   init();
00103 }
00104 
00105 
00106 template<class T>
00107 inline 
00108 RCPtr<T>::~RCPtr()
00109 {
00110   if (pointee) {
00111     pointee->removeReference();
00112   }
00113 }
00114 
00125 template <class T>
00126 inline 
00127 RCPtr<T>& RCPtr<T>::operator=(const RCPtr &rhs)
00128 {
00129   if (pointee != rhs.pointee) {
00130     T *oldPointee = pointee;
00131     pointee = rhs.pointee;
00132     init();
00133     if (oldPointee) {
00134       oldPointee->removeReference();
00135     }
00136   }
00137   return *this;
00138 }
00139 
00140 
00141 template <class T>
00142 inline
00143 bool RCPtr<T>::operator ==(const RCPtr &rhs)
00144 {
00145   bool rslt = (pointee == rhs.pointee);
00146   return rslt;
00147 }
00148 
00149 
00150 template <class T>
00151 inline 
00152 T* RCPtr<T>::operator->() const
00153 {
00154   return pointee;
00155 }
00156 
00157 
00158 template <class T>
00159 inline 
00160 T& RCPtr<T>::operator*() const
00161 {
00162   return *pointee;
00163 }
00164 
00165 
00166 #endif

Generated on Mon Sep 22 20:22:58 2003 by doxygen 1.3.3