System documentation of the GNU Image-Finding Tool

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

CSelfDestroyPointer.h

00001 /* -*- mode: c++ -*- 
00002 */
00003 /* 
00004 
00005     GIFT, a flexible content based image retrieval system.
00006     Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 */
00023 #ifndef _CSELFDESTROYPOINTER
00024 #define _CSELFDESTROYPOINTER
00025 #include "libMRML/include/uses-declarations.h"
00029 template<class T>
00030 class CSelfDestroyPointer{
00032   mutable bool mIsSelfDestroyer;
00034  protected:
00035   T* mPointer;
00037 public:
00039   void resetWithoutDeleting();
00041   inline bool isSelfDestroyer()const;
00043   inline void setIsSelfDestroyer(bool inisSelfDestroyer=true)const;
00045   void unsetIsSelfDestroyer()const;
00047   T* operator= (T* inPointer);
00049   T& operator*();
00051   T const& operator*()const;
00053   T* operator -> ();
00055   T const* operator -> ()const;
00057   ~CSelfDestroyPointer();
00059   CSelfDestroyPointer(T*,
00060                       bool = true);
00062   CSelfDestroyPointer(const CSelfDestroyPointer<T>& 
00063                       inSelfDestroyPointer);
00065   CSelfDestroyPointer();
00067   operator bool()const;
00069   operator T*()const;
00070 };
00071 
00072 
00074 template<class T>
00075 void CSelfDestroyPointer<T>::resetWithoutDeleting(){
00076   mPointer=0;
00077 }
00078 
00079 template<class T>
00080 T* CSelfDestroyPointer<T>::operator=(T* inPointer){
00081 
00082   if(mIsSelfDestroyer){
00083 #ifdef _DEBUG_SELF_DESTROY_
00084     cout <<"£"<<flush;
00085 #endif
00086     delete mPointer;
00087   }
00088   mPointer=inPointer;
00089 }
00090 
00091 template<class T>
00092 T const& CSelfDestroyPointer<T>::operator *()const{
00093   return *mPointer;
00094 }
00095 
00096 template<class T>
00097 T const* CSelfDestroyPointer<T>::operator ->()const{
00098   return mPointer;
00099 }
00100 
00101 template<class T>
00102 T& CSelfDestroyPointer<T>::operator *(){
00103   return *mPointer;
00104 }
00105 
00106 template<class T>
00107 T* CSelfDestroyPointer<T>::operator ->(){
00108   return mPointer;
00109 }
00110 
00111 template<class T>
00112 CSelfDestroyPointer<T>::CSelfDestroyPointer(T* inPointer,
00113                                             bool inIsSelfDestroyer):
00114   mPointer(inPointer),
00115   mIsSelfDestroyer(inIsSelfDestroyer)
00116 {
00117 }
00119 template<class T>
00120 CSelfDestroyPointer<T>::CSelfDestroyPointer(const CSelfDestroyPointer<T>& in):
00121   mPointer(in.mPointer),
00122   mIsSelfDestroyer(in.mIsSelfDestroyer)
00123 {
00124 };
00125 
00126 template<class T>
00127 CSelfDestroyPointer<T>::CSelfDestroyPointer():
00128   mPointer(0),
00129   mIsSelfDestroyer(true)
00130 {
00131 }
00132 
00133 template<class T>
00134 CSelfDestroyPointer<T>::~CSelfDestroyPointer()
00135 {
00136   if(mIsSelfDestroyer){
00137 
00138     delete mPointer;
00139   }
00140 }
00141 
00142 
00143 template<class T>
00144 void CSelfDestroyPointer<T>::setIsSelfDestroyer(bool inIsSelfDestroyer)const{
00145   mIsSelfDestroyer= inIsSelfDestroyer;
00146 };
00147 
00148 template<class T>
00149 bool CSelfDestroyPointer<T>::isSelfDestroyer()const{
00150   return mIsSelfDestroyer;
00151 };
00152 
00153 template<class T>
00154 void CSelfDestroyPointer<T>::unsetIsSelfDestroyer()const{
00155   mIsSelfDestroyer=0;
00156 };
00157 
00158 template<class T>
00159 CSelfDestroyPointer<T>::operator bool()const{
00160   return mPointer;
00161 };
00162 
00163 template<class T>
00164 CSelfDestroyPointer<T>::operator T*()const{
00165   return mPointer;
00166 };
00167 
00168 template<class T>
00169 class CSelfClonePointer: public CSelfDestroyPointer<T>{
00171   mutable bool mIsSelfCloner;
00173 public:
00175   CSelfClonePointer(T*,
00176                     bool = true);
00178   CSelfClonePointer<T>& operator= (T* in);
00180   CSelfClonePointer<T>& operator= (const CSelfClonePointer<T>& in);
00182   CSelfClonePointer(const CSelfClonePointer<T>&);
00184   CSelfClonePointer();
00186   operator bool()const;
00188   operator T*()const;
00189 };
00190 
00191 
00192 template<class T>
00193 CSelfClonePointer<T>& CSelfClonePointer<T>::operator=(T* in){
00194 
00195 
00196   CSelfDestroyPointer<T>::operator=(in);
00197   return *this;
00198 };
00199 
00200 template<class T>
00201 CSelfClonePointer<T>& CSelfClonePointer<T>::operator= (const CSelfClonePointer<T>& in){
00202 
00203   this->mPointer=in.mPointer;
00204   setIsSelfDestroyer(in.isSelfDestroyer());
00205   return *this;
00206 };
00207 
00208 template<class T>
00209 CSelfClonePointer<T>::CSelfClonePointer(T* inPointer,bool inIsSelfCloner):
00210   CSelfDestroyPointer<T>(inPointer,
00211                       inIsSelfCloner)
00212 {
00213 }
00214 template<class T>
00215 CSelfClonePointer<T>::CSelfClonePointer():
00216   CSelfDestroyPointer<T>(0,
00217                       true)
00218 {
00219 }
00220 template<class T>
00221 CSelfClonePointer<T>::CSelfClonePointer(const CSelfClonePointer<T>& in):
00222   CSelfDestroyPointer<T>(in)
00223 {
00224   if(in.mPointer && in.isSelfDestroyer()){
00225     this->mPointer=in.mPointer->clone();
00226   }else{
00227     this->mPointer=in.mPointer;
00228   }  
00229 }
00230 
00231 #endif

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