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_HXX__
20 #define __PARAMEDMEM_MEMARRAY_HXX__
22 #include "RefCountObject.hxx"
33 MemArray():_nb_of_elem(-1),_ownership(false),_pointer(0),_dealloc(CPP_DEALLOC) { }
34 T *getPointer() const { return _pointer; }
35 MemArray<T> &operator=(const MemArray<T>& other);
36 T operator[](int id) const { return _pointer[id]; }
37 T& operator[](int id) { return _pointer[id]; }
38 void alloc(int nbOfElements);
39 void reAlloc(int newNbOfElements);
40 void useArray(void *array, bool ownership, DeallocType type, int nbOfElem);
41 void writeOnPlace(int id, T element0, const T *others, int sizeOfOthers);
42 ~MemArray() { destroy(); }
45 static void destroyPointer(T *pt, DeallocType type);
53 class DataArray : public RefCountObject
56 void setName(const char *name);
57 std::string getName() const { return _name; }
58 std::string getInfoOnComponent(int i) const { return _info_on_compo[i]; }
59 void setInfoOnComponent(int i, const char *info) { _info_on_compo[i]=info; }
60 int getNumberOfComponents() const { return _info_on_compo.size(); }
61 int getNumberOfTuples() const { return _nb_of_tuples; }
62 int getNbOfElems() const { return _info_on_compo.size()*_nb_of_tuples; }
64 DataArray():_nb_of_tuples(-1) { }
68 std::vector<std::string> _info_on_compo;
72 #include "MemArray.txx"
76 class DataArrayDouble : public DataArray
79 static DataArrayDouble *New();
80 void alloc(int nbOfTuple, int nbOfCompo);
81 //!alloc or useArray should have been called before.
82 void reAlloc(int nbOfTuples);
83 double getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
84 void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; }
85 double *getPointer() const { return _mem.getPointer(); }
86 void useArray(double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
87 void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
88 //! nothing to do here because this class does not aggregate any TimeLabel instance.
93 MemArray<double> _mem;
96 class DataArrayInt : public DataArray
99 static DataArrayInt *New();
100 void alloc(int nbOfTuple, int nbOfCompo);
101 //!alloc or useArray should have been called before.
102 void reAlloc(int nbOfTuples);
103 int getIJ(int tupleId, int compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
104 int *getPointer() const { return _mem.getPointer(); }
105 void useArray(int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
106 void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
107 //! nothing to do here because this class does not aggregate any TimeLabel instance.
108 void updateTime() { }