X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMCAuto.hxx;h=06f728620b0bc836c2dbe4f7631c21d5e80f5ff1;hb=e7835cba1eb17f50ef4e130c2cb8d0f54bc25083;hp=99de255ca09f6f941e1bdbce081757f8bbfd83f4;hpb=e7b600309085fa6a411b31ec89c795471f272ae1;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index 99de255ca..06f728620 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -40,6 +40,7 @@ namespace MEDCoupling bool operator==(const T *other) const { return _ptr==other; } MCAuto &operator=(const MCAuto& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; } MCAuto &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } + void takeRef(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; if(_ptr) _ptr->incrRef(); } } T *operator->() { return _ptr ; } const T *operator->() const { return _ptr; } T& operator*() { return *_ptr; } @@ -78,6 +79,34 @@ namespace MEDCoupling ptr->incrRef(); return ret; } + + template + class MCConstAuto + { + public: + MCConstAuto(const MCConstAuto& other):_ptr(0) { referPtr(other._ptr); } + MCConstAuto(const typename MEDCoupling::MCAuto & other):_ptr(0) { referPtr( (const T*) other); } + MCConstAuto(const T *ptr=0):_ptr(ptr) { } + ~MCConstAuto() { destroyPtr(); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } + void nullify() { destroyPtr(); _ptr=0; } + bool operator==(const MCConstAuto& other) const { return _ptr==other._ptr; } + bool operator==(const T *other) const { return _ptr==other; } + MCConstAuto &operator=(const MCConstAuto& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; } + MCConstAuto &operator=(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } + void takeRef(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; if(_ptr) _ptr->incrRef(); } } + const T *operator->() { return _ptr ; } + const T *operator->() const { return _ptr; } + const T& operator*() { return *_ptr; } + const T& operator*() const { return *_ptr; } + operator const T *() const { return _ptr; } + private: + void referPtr(const T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } + void destroyPtr() { if(_ptr) _ptr->decrRef(); } + private: + const T *_ptr; + }; } #endif