System documentation of the GNU Image-Finding Tool

CSelfDestroyPointer.h
1 /* -*- mode: c++ -*-
2 */
3 /*
4 
5  GIFT, a flexible content based image retrieval system.
6  Copyright (C) 1998, 1999, 2000, 2001, 2002, CUI University of Geneva
7 
8  Copyright (C) 2003, 2004 Bayreuth University
9  2005 Bamberg University
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 
24 */
25 #ifndef _CSELFDESTROYPOINTER
26 #define _CSELFDESTROYPOINTER
27 #include "libMRML/include/uses-declarations.h"
31 template<class T>
34  mutable bool mIsSelfDestroyer;
36  protected:
37  T* mPointer;
39 public:
41  void resetWithoutDeleting();
43  inline bool isSelfDestroyer()const;
45  inline void setIsSelfDestroyer(bool inisSelfDestroyer=true)const;
47  void unsetIsSelfDestroyer()const;
49  T* operator= (T* inPointer);
51  T& operator*();
53  T const& operator*()const;
55  T* operator -> ();
57  T const* operator -> ()const;
62  bool = true);
65  inSelfDestroyPointer);
69  operator bool()const;
71  operator T*()const;
72 };
73 
74 
76 template<class T>
78  mPointer=0;
79 }
80 
81 template<class T>
82 T* CSelfDestroyPointer<T>::operator=(T* inPointer){
83 
84  if(mIsSelfDestroyer){
85 #ifdef _DEBUG_SELF_DESTROY_
86  cout <<"£<<flush; #endif delete mPointer; } mPointer=inPointer; } template<class T> T const& CSelfDestroyPointer<T>::operator *()const{ return *mPointer; } template<class T> T const* CSelfDestroyPointer<T>::operator ->()const{ return mPointer; } template<class T> T& CSelfDestroyPointer<T>::operator *(){ return *mPointer; } template<class T> T* CSelfDestroyPointer<T>::operator ->(){ return mPointer; } template<class T> CSelfDestroyPointer<T>::CSelfDestroyPointer(T* inPointer, bool inIsSelfDestroyer): mPointer(inPointer), mIsSelfDestroyer(inIsSelfDestroyer) { } /// template<class T> CSelfDestroyPointer<T>::CSelfDestroyPointer(const CSelfDestroyPointer<T>& in): mPointer(in.mPointer), mIsSelfDestroyer(in.mIsSelfDestroyer) { }; template<class T> CSelfDestroyPointer<T>::CSelfDestroyPointer(): mPointer(0), mIsSelfDestroyer(true) { } template<class T> CSelfDestroyPointer<T>::~CSelfDestroyPointer() { if(mIsSelfDestroyer){ delete mPointer; } } template<class T> void CSelfDestroyPointer<T>::setIsSelfDestroyer(bool inIsSelfDestroyer)const{ mIsSelfDestroyer= inIsSelfDestroyer; }; template<class T> bool CSelfDestroyPointer<T>::isSelfDestroyer()const{ return mIsSelfDestroyer; }; template<class T> void CSelfDestroyPointer<T>::unsetIsSelfDestroyer()const{ mIsSelfDestroyer=0; }; template<class T> CSelfDestroyPointer<T>::operator bool()const{ return mPointer; }; template<class T> CSelfDestroyPointer<T>::operator T*()const{ return mPointer; }; template<class T> class CSelfClonePointer: public CSelfDestroyPointer<T>{ /// mutable bool mIsSelfCloner; /// public: /// CSelfClonePointer(T*, bool = true); /// CSelfClonePointer<T>& operator= (T* in); /// CSelfClonePointer<T>& operator= (const CSelfClonePointer<T>& in); /// CSelfClonePointer(const CSelfClonePointer<T>&); /// CSelfClonePointer(); /// operator bool()const; /// operator T*()const; }; template<class T> CSelfClonePointer<T>& CSelfClonePointer<T>::operator=(T* in){ CSelfDestroyPointer<T>::operator=(in); return *this; }; template<class T> CSelfClonePointer<T>& CSelfClonePointer<T>::operator= (const CSelfClonePointer<T>& in){ this->mPointer=in.mPointer; setIsSelfDestroyer(in.isSelfDestroyer()); return *this; }; template<class T> CSelfClonePointer<T>::CSelfClonePointer(T* inPointer,bool inIsSelfCloner): CSelfDestroyPointer<T>(inPointer, inIsSelfCloner) { } template<class T> CSelfClonePointer<T>::CSelfClonePointer(): CSelfDestroyPointer<T>(0, true) { } template<class T> CSelfClonePointer<T>::CSelfClonePointer(const CSelfClonePointer<T>& in): CSelfDestroyPointer<T>(in) { if(in.mPointer && in.isSelfDestroyer()){ this->mPointer=in.mPointer->clone(); }else{ this->mPointer=in.mPointer; } } #endif "<<flush;
87 #endif
88  delete mPointer;
89  }
90  mPointer=inPointer;
91 }
92 
93 template<class T>
95  return *mPointer;
96 }
97 
98 template<class T>
100  return mPointer;
101 }
102 
103 template<class T>
105  return *mPointer;
106 }
107 
108 template<class T>
110  return mPointer;
111 }
112 
113 template<class T>
115  bool inIsSelfDestroyer):
116  mPointer(inPointer),
117  mIsSelfDestroyer(inIsSelfDestroyer)
118 {
119 }
121 template<class T>
123  mPointer(in.mPointer),
124  mIsSelfDestroyer(in.mIsSelfDestroyer)
125 {
126 };
127 
128 template<class T>
130  mPointer(0),
131  mIsSelfDestroyer(true)
132 {
133 }
134 
135 template<class T>
137 {
138  if(mIsSelfDestroyer){
139 
140  delete mPointer;
141  }
142 }
143 
144 
145 template<class T>
146 void CSelfDestroyPointer<T>::setIsSelfDestroyer(bool inIsSelfDestroyer)const{
147  mIsSelfDestroyer= inIsSelfDestroyer;
148 };
149 
150 template<class T>
152  return mIsSelfDestroyer;
153 };
154 
155 template<class T>
157  mIsSelfDestroyer=0;
158 };
159 
160 template<class T>
162  return mPointer;
163 };
164 
165 template<class T>
167  return mPointer;
168 };
169 
170 template<class T>
173  mutable bool mIsSelfCloner;
175 public:
178  bool = true);
180  CSelfClonePointer<T>& operator= (T* in);
182  CSelfClonePointer<T>& operator= (const CSelfClonePointer<T>& in);
188  operator bool()const;
190  operator T*()const;
191 };
192 
193 
194 template<class T>
196 
197 
199  return *this;
200 };
201 
202 template<class T>
204 
205  this->mPointer=in.mPointer;
206  setIsSelfDestroyer(in.isSelfDestroyer());
207  return *this;
208 };
209 
210 template<class T>
211 CSelfClonePointer<T>::CSelfClonePointer(T* inPointer,bool inIsSelfCloner):
212  CSelfDestroyPointer<T>(inPointer,
213  inIsSelfCloner)
214 {
215 }
216 template<class T>
218  CSelfDestroyPointer<T>(0,
219  true)
220 {
221 }
222 template<class T>
224  CSelfDestroyPointer<T>(in)
225 {
226  if(in.mPointer && in.isSelfDestroyer()){
227  this->mPointer=in.mPointer->clone();
228  }else{
229  this->mPointer=in.mPointer;
230  }
231 }
232 
233 #endif
Definition: CSelfDestroyPointer.h:171
destroys the element it points to or not (depending on user's choice).
Definition: CSelfDestroyPointer.h:32

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