System documentation of the GNU Image-Finding Tool

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members

CArraySelfDestroyPointer.h

00001 #ifndef _CARRAYSELFDESTROYPOINTER
00002 #define _CARRAYSELFDESTROYPOINTER
00003 /*
00004 #include "libMRML/include/uses-declarations.h"
00005 
00006   destroys the element it points to
00007 */
00008 
00009 template<class T>
00010 class CArraySelfDestroyPointer{
00012   mutable bool mIsSelfDestroyer;
00014  protected:
00015   T* mPointer;
00017 public:
00019   void resetWithoutDeleting();
00021   inline bool isSelfDestroyer()const;
00023   inline void setIsSelfDestroyer(bool inisSelfDestroyer=true)const;
00025   void unsetIsSelfDestroyer()const;
00027   T* operator= (T* inPointer);
00029   T& operator*();
00031   T const& operator*()const;
00033   T* operator -> ();
00035   T const* operator -> ()const;
00037   ~CArraySelfDestroyPointer();
00039   CArraySelfDestroyPointer(T*,
00040                       bool = true);
00042   CArraySelfDestroyPointer(const CArraySelfDestroyPointer<T>& 
00043                       inSelfDestroyPointer);
00045   CArraySelfDestroyPointer();
00047   operator bool()const;
00049   operator T*()const;
00050 };
00051 
00052 
00054 template<class T>
00055 void CArraySelfDestroyPointer<T>::resetWithoutDeleting(){
00056   mPointer=0;
00057 }
00058 
00059 template<class T>
00060 T* CArraySelfDestroyPointer<T>::operator=(T* inPointer){
00061 
00062   if(mIsSelfDestroyer){
00063     delete[] mPointer;
00064   }
00065   return mPointer=inPointer;
00066 }
00067 
00068 template<class T>
00069 T const& CArraySelfDestroyPointer<T>::operator *()const{
00070   return *mPointer;
00071 }
00072 
00073 template<class T>
00074 T const* CArraySelfDestroyPointer<T>::operator ->()const{
00075   return mPointer;
00076 }
00077 
00078 template<class T>
00079 T& CArraySelfDestroyPointer<T>::operator *(){
00080   return *mPointer;
00081 }
00082 
00083 template<class T>
00084 T* CArraySelfDestroyPointer<T>::operator ->(){
00085   return mPointer;
00086 }
00087 
00088 template<class T>
00089 CArraySelfDestroyPointer<T>::CArraySelfDestroyPointer(T* inPointer,
00090                                             bool inIsSelfDestroyer):
00091   mPointer(inPointer),
00092   mIsSelfDestroyer(inIsSelfDestroyer)
00093 {
00094 }
00096 template<class T>
00097 CArraySelfDestroyPointer<T>::CArraySelfDestroyPointer(const CArraySelfDestroyPointer<T>& in):
00098   mPointer(in.mPointer),
00099   mIsSelfDestroyer(in.mIsSelfDestroyer)
00100 {
00101 };
00102 
00103 template<class T>
00104 CArraySelfDestroyPointer<T>::CArraySelfDestroyPointer():
00105   mPointer(0),
00106   mIsSelfDestroyer(true)
00107 {
00108 }
00109 
00110 template<class T>
00111 CArraySelfDestroyPointer<T>::~CArraySelfDestroyPointer()
00112 {
00113   if(mIsSelfDestroyer){
00114 
00115     delete[] mPointer;
00116   }
00117 }
00118 
00119 
00120 template<class T>
00121 void CArraySelfDestroyPointer<T>::setIsSelfDestroyer(bool inIsSelfDestroyer)const{
00122   mIsSelfDestroyer= inIsSelfDestroyer;
00123 };
00124 
00125 template<class T>
00126 bool CArraySelfDestroyPointer<T>::isSelfDestroyer()const{
00127   return mIsSelfDestroyer;
00128 };
00129 
00130 template<class T>
00131 void CArraySelfDestroyPointer<T>::unsetIsSelfDestroyer()const{
00132   mIsSelfDestroyer=0;
00133 };
00134 
00135 template<class T>
00136 CArraySelfDestroyPointer<T>::operator bool()const{
00137   return mPointer;
00138 };
00139 
00140 template<class T>
00141 CArraySelfDestroyPointer<T>::operator T*()const{
00142   return mPointer;
00143 };
00144 #endif

Need for discussion? Want to contribute? Contact
help-gift@gnu.org Generated using Doxygen