X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.txx;h=3171c1672ac415a4cbc6b21f0f78d2079ffc9ac8;hb=be4c3bb042d5426fbbe54378b9d7b35173ab27ef;hp=71be0a297c8e51e4908267e03c109c32631948a3;hpb=800d142678be04bf1349fb5423ad647be4016ed0;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 71be0a297..3171c1672 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -61,9 +61,9 @@ namespace ParaMEDMEM template void MemArray::useArray(const T *array, bool ownership, DeallocType type, std::size_t nbOfElem) { + destroy(); _nb_of_elem=nbOfElem; _nb_of_elem_alloc=nbOfElem; - destroy(); if(ownership) _pointer.setInternal(const_cast(array)); else @@ -75,9 +75,9 @@ namespace ParaMEDMEM template void MemArray::useExternalArrayWithRWAccess(const T *array, std::size_t nbOfElem) { + destroy(); _nb_of_elem=nbOfElem; _nb_of_elem_alloc=nbOfElem; - destroy(); _pointer.setInternal(const_cast(array)); _ownership=false; _dealloc=CPPDeallocator; @@ -111,7 +111,7 @@ namespace ParaMEDMEM } template - void MemArray::pushBack(T elem) throw(INTERP_KERNEL::Exception) + void MemArray::pushBack(T elem) { if(_nb_of_elem>=_nb_of_elem_alloc) reserve(_nb_of_elem_alloc>0?2*_nb_of_elem_alloc:1); @@ -120,7 +120,7 @@ namespace ParaMEDMEM } template - T MemArray::popBack() throw(INTERP_KERNEL::Exception) + T MemArray::popBack() { if(_nb_of_elem>0) { @@ -133,8 +133,7 @@ namespace ParaMEDMEM template void MemArray::pack() const { - if(_nb_of_elem>=0) - (const_cast * >(this))->reserve(_nb_of_elem); + (const_cast * >(this))->reserve(_nb_of_elem); } template @@ -334,11 +333,9 @@ namespace ParaMEDMEM } template - void MemArray::alloc(std::size_t nbOfElements) throw(INTERP_KERNEL::Exception) + void MemArray::alloc(std::size_t nbOfElements) { destroy(); - if(nbOfElements<0) - throw INTERP_KERNEL::Exception("MemArray::alloc : request for negative length of data !"); _nb_of_elem=nbOfElements; _nb_of_elem_alloc=nbOfElements; _pointer.setInternal((T*)malloc(_nb_of_elem_alloc*sizeof(T))); @@ -356,16 +353,14 @@ namespace ParaMEDMEM * So this method should not be confused with MemArray::reserve that is close to MemArray::reAlloc but not same. */ template - void MemArray::reserve(std::size_t newNbOfElements) throw(INTERP_KERNEL::Exception) + void MemArray::reserve(std::size_t newNbOfElements) { - if(newNbOfElements<0) - throw INTERP_KERNEL::Exception("MemArray::reAlloc : request for negative length of data !"); if(_nb_of_elem_alloc==newNbOfElements) return ; T *pointer=(T*)malloc(newNbOfElements*sizeof(T)); std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min(_nb_of_elem,newNbOfElements),pointer); if(_ownership) - destroyPointer(const_cast(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external + DestroyPointer(const_cast(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external _pointer.setInternal(pointer); _nb_of_elem=std::min(_nb_of_elem,newNbOfElements); _nb_of_elem_alloc=newNbOfElements; @@ -382,16 +377,14 @@ namespace ParaMEDMEM * So this method should not be confused with MemArray::reserve that is close to MemArray::reAlloc but not same. */ template - void MemArray::reAlloc(std::size_t newNbOfElements) throw(INTERP_KERNEL::Exception) + void MemArray::reAlloc(std::size_t newNbOfElements) { - if(newNbOfElements<0) - throw INTERP_KERNEL::Exception("MemArray::reAlloc : request for negative length of data !"); if(_nb_of_elem==newNbOfElements) return ; T *pointer=(T*)malloc(newNbOfElements*sizeof(T)); std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min(_nb_of_elem,newNbOfElements),pointer); if(_ownership) - destroyPointer(const_cast(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external + DestroyPointer(const_cast(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external _pointer.setInternal(pointer); _nb_of_elem=newNbOfElements; _nb_of_elem_alloc=newNbOfElements; @@ -413,7 +406,7 @@ namespace ParaMEDMEM } template - typename MemArray::Deallocator MemArray::BuildFromType(DeallocType type) throw(INTERP_KERNEL::Exception) + typename MemArray::Deallocator MemArray::BuildFromType(DeallocType type) { switch(type) { @@ -427,7 +420,7 @@ namespace ParaMEDMEM } template - void MemArray::destroyPointer(T *pt, typename MemArray::Deallocator dealloc, void *param) + void MemArray::DestroyPointer(T *pt, typename MemArray::Deallocator dealloc, void *param) { if(dealloc) dealloc(pt,param); @@ -437,11 +430,13 @@ namespace ParaMEDMEM void MemArray::destroy() { if(_ownership) - destroyPointer(const_cast(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external + DestroyPointer(const_cast(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external _pointer.null(); _ownership=false; _dealloc=NULL; _param_for_deallocator=NULL; + _nb_of_elem=0; + _nb_of_elem_alloc=0; } template