25 #ifndef _CSELFDESTROYPOINTER
26 #define _CSELFDESTROYPOINTER
27 #include "libMRML/include/uses-declarations.h"
34 mutable bool mIsSelfDestroyer;
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);
53 T
const& operator*()
const;
57 T
const* operator -> ()
const;
65 inSelfDestroyPointer);
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;
115 bool inIsSelfDestroyer):
117 mIsSelfDestroyer(inIsSelfDestroyer)
123 mPointer(in.mPointer),
124 mIsSelfDestroyer(in.mIsSelfDestroyer)
131 mIsSelfDestroyer(true)
138 if(mIsSelfDestroyer){
147 mIsSelfDestroyer= inIsSelfDestroyer;
152 return mIsSelfDestroyer;
173 mutable bool mIsSelfCloner;
188 operator bool()
const;
205 this->mPointer=in.mPointer;
206 setIsSelfDestroyer(in.isSelfDestroyer());
226 if(in.mPointer && in.isSelfDestroyer()){
227 this->mPointer=in.mPointer->clone();
229 this->mPointer=in.mPointer;
Definition: CSelfDestroyPointer.h:171
destroys the element it points to or not (depending on user's choice).
Definition: CSelfDestroyPointer.h:32