X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMCAuto.hxx;h=76e00de3818303de1cce074041a9e68fbebc7721;hb=ffb8188e28b2b60ee207a8644286821bc4e8fcdc;hp=e7b2b65d416ad9b4371a84cdd4efe613eb3651c5;hpb=3b1d77efdd048ef4aad858e96138bf79318119df;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index e7b2b65d4..76e00de38 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -18,12 +18,13 @@ // // Author : Anthony Geay (CEA/DEN) -#ifndef __PARAMEDMEM_MEDCOUPLINGAUTOREFCOUNTOBJECTPTR_HXX__ -#define __PARAMEDMEM_MEDCOUPLINGAUTOREFCOUNTOBJECTPTR_HXX__ +#pragma once #include "MEDCouplingRefCountObject.hxx" #include "InterpKernelException.hxx" +#include + namespace MEDCoupling { template @@ -33,10 +34,15 @@ namespace MEDCoupling MCAuto(const MCAuto& other):_ptr(0) { referPtr(other._ptr); } MCAuto(T *ptr=0):_ptr(ptr) { } ~MCAuto() { destroyPtr(); } + void checkNotNull() const { if(!_ptr) throw INTERP_KERNEL::Exception("Pointer is nullptr !"); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } + void nullify() { destroyPtr(); _ptr=0; } bool operator==(const MCAuto& other) const { return _ptr==other._ptr; } 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; } @@ -44,6 +50,8 @@ namespace MEDCoupling operator T *() { return _ptr; } operator const T *() const { return _ptr; } T *retn() { if(_ptr) _ptr->incrRef(); return _ptr; } + T *retnConstCast() const { if(_ptr) _ptr->incrRef(); return _ptr; } + T *iAmATrollConstCast() const { return _ptr; } private: void referPtr(T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } void destroyPtr() { if(_ptr) _ptr->decrRef(); } @@ -74,6 +82,43 @@ namespace MEDCoupling ptr->incrRef(); return ret; } -} -#endif + template + typename std::vector ToConstVect(const typename std::vector< MCAuto >& vec) + { + std::size_t sz(vec.size()); + std::vector ret(sz); + for(std::size_t i=0;i + 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; } + T *shameOnMeConstCast() const { return const_cast(_ptr); } + private: + void referPtr(const T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } + void destroyPtr() { if(_ptr) _ptr->decrRef(); } + private: + const T *_ptr; + }; +}