1 #ifndef MEDMEM_ARRAY_HXX
2 #define MEDMEM_ARRAY_HXX
4 #include "MEDMEM_InterlacingPolicy.hxx"
5 #include "MEDMEM_IndexCheckingPolicy.hxx"
7 #include "MEDMEM_PointerOf.hxx"
8 #include "MEDMEM_define.hxx"
14 //virtual void dummy() {};
15 virtual bool getGaussPresence() const { return false; }
16 virtual MED_EN::medModeSwitch getInterlacingType() const {return MED_EN::MED_UNDEFINED_INTERLACE;}
17 virtual ~MEDMEM_Array_() {}; //Indispensable pour détruire le vrai objet pointé
20 template < class ARRAY_ELEMENT_TYPE,
21 class INTERLACING_POLICY=FullInterlaceNoGaussPolicy,
22 class CHECKING_POLICY=IndexCheckPolicy >
23 class MEDMEM_Array : public INTERLACING_POLICY, public CHECKING_POLICY, public MEDMEM_Array_ {
27 typedef ARRAY_ELEMENT_TYPE ElementType;
28 typedef INTERLACING_POLICY InterlacingPolicy;
29 typedef CHECKING_POLICY CheckingPolicy;
32 MEDMEM_Array():_array( ( ElementType *) NULL) {}; //Interdit le constructeur par défaut, peut pas à cause du FIELD
35 // PointerOf s'occupe de la desallocation.
38 // Le mot clé inline permettra d'instancier le constructeur uniquement
39 // s'il est appelé ( ...NoGaussPolicy)
40 // Rem : Le constructeur de la policy demandée est appelé
41 inline MEDMEM_Array(int dim, int nbelem) : InterlacingPolicy(nbelem,dim)
43 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
44 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
45 _array.set(InterlacingPolicy::_arraySize);
48 // Le mot clé inline permettra d'instancier le constructeur uniquement
49 // s'il est appelé ( ...NoGaussPolicy)
50 // Rem : Le constructeur de la policy demandée est appelé
51 inline MEDMEM_Array( ElementType * values, int dim, int nbelem,
52 bool shallowCopy=false,
53 bool ownershipOfValues=false) : InterlacingPolicy(nbelem,dim)
55 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
56 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
60 _array.setShallowAndOwnership((const ElementType *)values);
62 _array.set((const ElementType*)values);
64 else // Cas par défaut
65 _array.set(InterlacingPolicy::_arraySize,values);
69 // Le mot clé inline permettra d'instancier le constructeur uniquement
70 // s'il est appelé ( ...GaussPolicy)
71 // Rem : Le constructeur de la policy demandée est appelé
72 inline MEDMEM_Array(int dim, int nbelem, int nbtypegeo,
73 const int * const nbelgeoc, const int * const nbgaussgeo)
74 : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc, nbgaussgeo)
76 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
77 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
78 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbtypegeo);
79 _array.set(InterlacingPolicy::_arraySize);
83 // Le mot clé inline permettra d'instancier le constructeur uniquement
84 // s'il est appelé ( ...GaussPolicy)
85 // Rem : Le constructeur de la policy demandée est appelé
86 inline MEDMEM_Array(ElementType * values, int dim, int nbelem, int nbtypegeo,
87 const int * const nbelgeoc, const int * const nbgaussgeo,
88 bool shallowCopy=false,
89 bool ownershipOfValues=false)
90 : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc, nbgaussgeo)
92 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
93 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
94 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbtypegeo);
99 _array.setShallowAndOwnership((const ElementType *)values);
101 _array.set((const ElementType*)values);
104 _array.set(InterlacingPolicy::_arraySize,values);
108 // Constructeur de recopie pour un MEDMEM_Array avec les mêmes
109 // paramètres template qu'à la construction
110 inline MEDMEM_Array(const MEDMEM_Array & array, bool shallowCopy=false)
111 :InterlacingPolicy(array,shallowCopy)
114 this->_array.set(array._array); // Le propriétaire reste le ARRAY initial
116 this->_array.set(InterlacingPolicy::_arraySize,array._array);
120 // L'utilisation d'une copie superficielle pour l'opérateur d'affectation
121 // ne me parait pas être une bonne ideé : Compatibilité ancienne version MEDARRAY?
122 inline MEDMEM_Array<ElementType,InterlacingPolicy,CheckingPolicy> &
123 operator=( const MEDMEM_Array & array) {
124 if ( this == &array) return *this;
125 BEGIN_OF("MEDMEM_Array operator =");
126 InterlacingPolicy::operator=(array); //Appel des classes de base ?
128 this->_array.set(array._array); // Le propriétaire reste le ARRAY initial
133 MED_EN::medModeSwitch getInterlacingType() const {
134 return InterlacingPolicy::getInterlacingType();
137 bool getGaussPresence() const {
138 return InterlacingPolicy::getGaussPresence();
141 ElementType * getPtr() {
145 void setPtr(ElementType * values, bool shallowCopy=false,
146 bool ownershipOfValues=false) {
150 if(ownershipOfValues)
151 _array.setShallowAndOwnership((const ElementType *)values);
153 _array.set((const ElementType*)values);
156 _array.set(InterlacingPolicy::_arraySize,values);
159 inline const ElementType * getRow(int i) const {
160 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
161 // Empêche l'utilisation de getRow en mode MED_NO_INTERLACE
162 // Ne devrait pas dépendre de la politique check
163 checkEquality("MEDMEM_Array (Interlace test)",
164 MED_EN::MED_NO_INTERLACE,
165 InterlacingPolicy::_interlacing );
166 return &(_array[ InterlacingPolicy::getIndex(i,1) ]);
170 void setRow(int i,const ElementType * const value) {
171 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
173 // dans les deux modes d'entrelacement.
175 for (int j =1; j <= InterlacingPolicy::getDim(); j++)
176 for (int k = 1 ; k <= InterlacingPolicy::getNbGauss(i); k++)
177 _array[InterlacingPolicy::getIndex(i,j,k)] = value[InterlacingPolicy::getIndex(1,j,k)];
180 inline const ElementType * getColumn(int j) const {
181 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
182 checkEquality("MEDMEM_Array (Interlace test)",
183 MED_EN::MED_FULL_INTERLACE, InterlacingPolicy::_interlacing );
184 return &(_array[ InterlacingPolicy::getIndex(1,j) ]);
187 void setColumn(int j, const ElementType * const value) {
188 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
189 // setColumn fonctionne
190 // dans les deux modes d'entrelacement.
192 for (int i=1; i <= InterlacingPolicy::getNbElem(); i++)
193 for (int k = 1 ; k <= InterlacingPolicy::getNbGauss(i); k++)
194 _array[InterlacingPolicy::getIndex(i,j,k)] = value[InterlacingPolicy::getIndex(i,1,k)];
198 inline const ElementType & getIJ(int i, int j) const {
199 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
200 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
201 return _array[ InterlacingPolicy::getIndex(i,j) ];
204 inline const ElementType & getIJK(int i, int j, int k ) const {
205 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
206 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
207 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k);
209 return _array[ InterlacingPolicy::getIndex(i,j,k) ];
212 inline void setIJ(int i, int j, const ElementType & value) { //autre signature avec
213 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
214 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
216 _array[ InterlacingPolicy::getIndex(i,j) ] = value; // retour ElementType & ?
219 inline void setIJK(int i, int j, int k, const ElementType & value) { //autre signature avec
220 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
221 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
222 checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k);
224 _array[ InterlacingPolicy::getIndex(i,j,k) ] = value; // retour ElementType & ?
227 bool operator == (const MEDMEM_Array & array ) const {
229 if ( this == &array ) return true;
231 int size = array.getArraySize();
232 if ( size != getArraySize() ) return false;
234 ARRAY_ELEMENT_TYPE * arrayPtr =
235 const_cast<MEDMEM_Array &>(array).getPtr();
236 for (int i=0; i < size; ++i)
237 if (_array[i] != arrayPtr[i]) return false;
242 friend ostream & operator<<(ostream & os, const MEDMEM_Array & array) {
244 for (int i=1;i<=array.getNbElem();++i) {
245 for (int j=1; j<=array.getDim();++j)
246 for (int k=1;k<=array.getNbGauss(i);++k)
247 os << "Value [" << i << "," << j << "," << k << "] = " << array.getIJK(i,j,k) << ", ";
255 PointerOf<ElementType> _array;