1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef __PARAMEDMEM_MEMARRAY_TXX__
20 #define __PARAMEDMEM_MEMARRAY_TXX__
22 #include "MemArray.hxx"
23 #include "NormalizedUnstructuredMesh.hxx"
24 #include "InterpKernelException.hxx"
32 void MemArray<T>::useArray(void *array, bool ownership, DeallocType type, int nbOfElem)
42 void MemArray<T>::writeOnPlace(int id, T element0, const T *others, int sizeOfOthers)
44 if(id+sizeOfOthers>=_nb_of_elem)
45 reAlloc(2*_nb_of_elem+sizeOfOthers+1);
46 _pointer[id]=element0;
47 memcpy(_pointer+id+1,others,sizeOfOthers*sizeof(T));
51 void MemArray<T>::alloc(int nbOfElements)
54 _nb_of_elem=nbOfElements;
55 _pointer=new T[_nb_of_elem];
61 void MemArray<T>::reAlloc(int newNbOfElements)
63 T *pointer=new T[newNbOfElements];
64 memcpy(pointer,_pointer,std::min<int>(_nb_of_elem,newNbOfElements)*sizeof(int));
65 destroyPointer(_pointer,_dealloc);
67 _nb_of_elem=newNbOfElements;
73 void MemArray<T>::destroyPointer(T *pt, DeallocType type)
88 std::stringstream stream;
89 stream << "Invalid deallocation requested for pointer " << pt;
90 throw INTERP_KERNEL::Exception(stream.str().c_str());
95 void MemArray<T>::destroy()
98 destroyPointer(_pointer,_dealloc);
104 MemArray<T> &MemArray<T>::operator=(const MemArray<T>& other)
106 alloc(other._nb_of_elem);
107 memcpy(_pointer,other._pointer,_nb_of_elem*sizeof(T));