X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMCAuto.hxx;h=3a64be546b9d73740fe4cd91f090ef36e09f433a;hb=b8616069f6667dcec3f90574a05bfc9e66d87fa5;hp=1d83037b916a0c5e71112e3c721a3c5cba3826a2;hpb=1c9761aeac9192f62f324ad7a04430f2482bc843;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index 1d83037b9..3a64be546 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020 CEA/DEN, EDF R&D +// Copyright (C) 2007-2021 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 @@ -32,14 +32,14 @@ namespace MEDCoupling class MCAuto { public: - static MCAuto TakeRef(T *ptr) { MCAuto ret(MCAuto(nullptr)); ret.takeRef(ptr); return ret; } - 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; } @@ -71,8 +71,28 @@ namespace MEDCoupling 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));