X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FINTERP_KERNEL%2FBases%2FInterpKernelAutoPtr.hxx;h=312633862463f8fd88a42ab195c189846adbbeec;hb=5a8dfa8819c5f0ed754b0d0dc51dc51617b3e710;hp=1c805553a51b3e5512fdf4eedca563cdcec557a6;hpb=fb512e2b77325290aaa2b4c9fd8f22d5949b6369;p=tools%2Fmedcoupling.git diff --git a/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx b/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx index 1c805553a..312633862 100644 --- a/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx +++ b/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx @@ -29,7 +29,7 @@ namespace INTERP_KERNEL public: AutoPtr(T *ptr=0):_ptr(ptr) { } ~AutoPtr() { destroyPtr(); } - AutoPtr &operator=(T *ptr) { destroyPtr(); _ptr=ptr; return *this; } + AutoPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } T *operator->() { return _ptr ; } const T *operator->() const { return _ptr; } T& operator*() { return *_ptr; } @@ -42,13 +42,32 @@ namespace INTERP_KERNEL T *_ptr; }; + template + class AutoCppPtr + { + public: + AutoCppPtr(T *ptr=0):_ptr(ptr) { } + ~AutoCppPtr() { destroyPtr(); } + AutoCppPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } + T *operator->() { return _ptr ; } + const T *operator->() const { return _ptr; } + T& operator*() { return *_ptr; } + const T& operator*() const { return *_ptr; } + operator T *() { return _ptr; } + operator const T *() const { return _ptr; } + private: + void destroyPtr() { delete _ptr; } + private: + T *_ptr; + }; + template class AutoCPtr { public: AutoCPtr(T *ptr=0):_ptr(ptr) { } ~AutoCPtr() { destroyPtr(); } - AutoCPtr &operator=(T *ptr) { destroyPtr(); _ptr=ptr; return *this; } + AutoCPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } T *operator->() { return _ptr ; } const T *operator->() const { return _ptr; } T& operator*() { return *_ptr; }