X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMCAuto.hxx;h=bb2c6e7528ee9800ecf9220df232ada0549689c4;hb=2ae2dc6fcedbf241c7637284b3c7bde12aded04a;hp=76e00de3818303de1cce074041a9e68fbebc7721;hpb=e0c843a1fe827a90af91ada8d2033ffb3a7dd1d8;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index 76e00de38..bb2c6e752 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -24,6 +24,7 @@ #include "InterpKernelException.hxx" #include +#include namespace MEDCoupling { @@ -31,13 +32,14 @@ namespace MEDCoupling class MCAuto { public: - MCAuto(const MCAuto& other):_ptr(0) { referPtr(other._ptr); } - MCAuto(T *ptr=0):_ptr(ptr) { } + static MCAuto TakeRef(T *ptr) { MCAuto ret; ret.takeRef(ptr); return ret; } + MCAuto(const MCAuto& other):_ptr(nullptr) { referPtr(other._ptr); } + MCAuto(T *ptr=nullptr):_ptr(ptr) { } ~MCAuto() { destroyPtr(); } void checkNotNull() const { if(!_ptr) throw INTERP_KERNEL::Exception("Pointer is nullptr !"); } - bool isNull() const { return _ptr==0; } + bool isNull() const { return _ptr==nullptr; } bool isNotNull() const { return !isNull(); } - void nullify() { destroyPtr(); _ptr=0; } + void nullify() { destroyPtr(); _ptr=nullptr; } 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; } @@ -59,8 +61,38 @@ namespace MEDCoupling T *_ptr; }; + template + std::vector FromVecAutoToVecOfConst(const std::vector>& inputVec) + { + std::size_t size(inputVec.size()); + std::vector< const T *> ret(size); + typename std::vector< const T *>::iterator itArrays(ret.begin()); + std::for_each(inputVec.begin(),inputVec.end(),[&itArrays](MCAuto elt) { *itArrays++=elt; }); + return ret; + } + + template + std::vector> FromVecToVecAuto(const std::vector& inputVec) + { + std::size_t size(inputVec.size()); + std::vector> ret(size); + typename std::vector>::iterator itArrays(ret.begin()); + std::for_each(inputVec.begin(),inputVec.end(),[&itArrays](T *elt) { (*itArrays).takeRef(elt); itArrays++; }); + return ret; + } + + template + std::vector> FromVecConstToVecAuto(const std::vector& inputVec) + { + std::size_t size(inputVec.size()); + std::vector> ret(size); + typename std::vector>::iterator itArrays(ret.begin()); + std::for_each(inputVec.begin(),inputVec.end(),[&itArrays](const T *elt) { (*itArrays).takeRef(const_cast(elt)); itArrays++; }); + return ret; + } + template - typename MEDCoupling::MCAuto DynamicCast(typename MEDCoupling::MCAuto& autoSubPtr) throw() + typename MEDCoupling::MCAuto DynamicCast(typename MEDCoupling::MCAuto& autoSubPtr) noexcept(true) { T *subPtr(autoSubPtr); U *ptr(dynamic_cast(subPtr));