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(INTERLACING_POLICY::_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(INTERLACING_POLICY::_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(INTERLACING_POLICY::_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(INTERLACING_POLICY::_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(INTERLACING_POLICY::_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
129 // verifier l'appel des opérateurs de la policy
134 MED_EN::medModeSwitch getInterlacingType() const {
135 return InterlacingPolicy::getInterlacingType();
138 bool getGaussPresence() const {
139 return InterlacingPolicy::getGaussPresence();
142 ElementType * getPtr() {
146 void setPtr(ElementType * values, bool shallowCopy=false,
147 bool ownershipOfValues=false) {
151 if(ownershipOfValues)
152 _array.setShallowAndOwnership((const ElementType *)values);
154 _array.set((const ElementType*)values);
157 _array.set(INTERLACING_POLICY::_arraySize,values);
160 inline const ElementType * getRow(int i) const {
161 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_nbelem,i);
162 // Empêche l'utilisation de getRow en mode MED_NO_INTERLACE
163 // Ne devrait pas dépendre de la politique check
164 checkEquality("MEDMEM_Array (Interlace test)",
165 MED_EN::MED_NO_INTERLACE,
166 INTERLACING_POLICY::_interlacing );
167 return &(_array[ INTERLACING_POLICY::getIndex(i,1) ]);
171 void setRow(int i,const ElementType * const value) {
172 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_nbelem,i);
174 // dans les deux modes d'entrelacement.
176 for (int j =1; j <= INTERLACING_POLICY::getDim(); j++)
177 for (int k = 1 ; k <= INTERLACING_POLICY::getNbGauss(i); k++)
178 _array[INTERLACING_POLICY::getIndex(i,j,k)] = value[INTERLACING_POLICY::getIndex(1,j,k)];
181 inline const ElementType * getColumn(int j) const {
182 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_dim,j);
183 checkEquality("MEDMEM_Array (Interlace test)",
184 MED_EN::MED_FULL_INTERLACE, INTERLACING_POLICY::_interlacing );
185 return &(_array[ INTERLACING_POLICY::getIndex(1,j) ]);
188 void setColumn(int j, const ElementType * const value) {
189 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_dim,j);
190 // setColumn fonctionne
191 // dans les deux modes d'entrelacement.
193 for (int i=1; i <= INTERLACING_POLICY::getNbElem(); i++)
194 for (int k = 1 ; k <= INTERLACING_POLICY::getNbGauss(i); k++)
195 _array[INTERLACING_POLICY::getIndex(i,j,k)] = value[INTERLACING_POLICY::getIndex(i,1,k)];
199 inline const ElementType & getIJ(int i, int j) const {
200 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_nbelem,i);
201 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_dim,j);
202 return _array[ INTERLACING_POLICY::getIndex(i,j) ];
205 inline const ElementType & getIJK(int i, int j, int k ) const {
206 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_nbelem,i);
207 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_dim,j);
208 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::getNbGauss(i),k);
210 return _array[ INTERLACING_POLICY::getIndex(i,j,k) ];
213 inline void setIJ(int i, int j, const ElementType & value) { //autre signature avec
214 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_nbelem,i);
215 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_dim,j);
217 _array[ INTERLACING_POLICY::getIndex(i,j) ] = value; // retour ElementType & ?
220 inline void setIJK(int i, int j, int k, const ElementType & value) { //autre signature avec
221 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_nbelem,i);
222 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::_dim,j);
223 checkInInclusiveRange("MEDMEM_Array",1,INTERLACING_POLICY::getNbGauss(i),k);
225 _array[ INTERLACING_POLICY::getIndex(i,j,k) ] = value; // retour ElementType & ?
231 PointerOf<ElementType> _array;