00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MEDMEM_ARRAY_HXX
00024 #define MEDMEM_ARRAY_HXX
00025
00026 #include "MEDMEM.hxx"
00027
00028 #include "MEDMEM_InterlacingPolicy.hxx"
00029 #include "MEDMEM_IndexCheckingPolicy.hxx"
00030
00031 #include "MEDMEM_PointerOf.hxx"
00032 #include "MEDMEM_define.hxx"
00033
00034 namespace MEDMEM {
00035
00036 class MEDMEM_EXPORT MEDMEM_Array_ {
00037 public:
00038
00039 virtual bool getGaussPresence() const { return false; }
00040 virtual MED_EN::medModeSwitch getInterlacingType() const {return MED_EN::MED_UNDEFINED_INTERLACE;}
00041 virtual ~MEDMEM_Array_() {};
00042 };
00043
00044 template < class ARRAY_ELEMENT_TYPE,
00045 class INTERLACING_POLICY=FullInterlaceNoGaussPolicy,
00046 class CHECKING_POLICY=IndexCheckPolicy >
00047 class MEDMEM_Array : public INTERLACING_POLICY, public CHECKING_POLICY, public MEDMEM_Array_ {
00048
00049 public :
00050
00051 typedef ARRAY_ELEMENT_TYPE ElementType;
00052 typedef INTERLACING_POLICY InterlacingPolicy;
00053 typedef CHECKING_POLICY CheckingPolicy;
00054
00055 public :
00056 MEDMEM_Array():_array( ( ElementType *) NULL) {};
00057
00058 ~MEDMEM_Array() {
00059
00060 };
00061
00062
00063
00064
00065 inline MEDMEM_Array(int dim, int nbelem) : InterlacingPolicy(nbelem,dim)
00066 {
00067 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
00068 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
00069 _array.set(InterlacingPolicy::_arraySize);
00070 };
00071
00072
00073
00074
00075 inline MEDMEM_Array(int dim, int nbelem,
00076 int nbtypegeo, const int * const nbelgeoc)
00077 : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc)
00078 {
00079 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
00080 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
00081 _array.set(InterlacingPolicy::_arraySize);
00082 };
00083
00084
00085
00086
00087 inline MEDMEM_Array( ElementType * values, int dim, int nbelem,
00088 bool shallowCopy=false,
00089 bool ownershipOfValues=false) : InterlacingPolicy(nbelem,dim)
00090 {
00091 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
00092 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
00093 if(shallowCopy)
00094
00095 if(ownershipOfValues)
00096 _array.setShallowAndOwnership((const ElementType *)values);
00097 else
00098 _array.set((const ElementType*)values);
00099
00100 else
00101 _array.set(InterlacingPolicy::_arraySize,values);
00102
00103 }
00104
00105
00106
00107
00108 inline MEDMEM_Array( ElementType * values, int dim, int nbelem,
00109 int nbtypegeo, const int * const nbelgeoc,
00110 bool shallowCopy=false,
00111 bool ownershipOfValues=false)
00112 : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc)
00113 {
00114 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
00115 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
00116 if(shallowCopy)
00117
00118 if(ownershipOfValues)
00119 _array.setShallowAndOwnership((const ElementType *)values);
00120 else
00121 _array.set((const ElementType*)values);
00122
00123 else
00124 _array.set(InterlacingPolicy::_arraySize,values);
00125
00126 }
00127
00128
00129
00130
00131 inline MEDMEM_Array(int dim, int nbelem, int nbtypegeo,
00132 const int * const nbelgeoc, const int * const nbgaussgeo)
00133 : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc, nbgaussgeo)
00134 {
00135 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
00136 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
00137 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbtypegeo);
00138 _array.set(InterlacingPolicy::_arraySize);
00139 };
00140
00141
00142
00143
00144
00145 inline MEDMEM_Array(ElementType * values, int dim, int nbelem, int nbtypegeo,
00146 const int * const nbelgeoc, const int * const nbgaussgeo,
00147 bool shallowCopy=false,
00148 bool ownershipOfValues=false)
00149 : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc, nbgaussgeo)
00150 {
00151 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem);
00152 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim);
00153 CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbtypegeo);
00154
00155 if(shallowCopy)
00156
00157 if(ownershipOfValues)
00158 _array.setShallowAndOwnership((const ElementType *)values);
00159 else
00160 _array.set((const ElementType*)values);
00161
00162 else
00163 _array.set(InterlacingPolicy::_arraySize,values);
00164
00165 };
00166
00167
00168
00169 inline MEDMEM_Array(const MEDMEM_Array & array, bool shallowCopy=false)
00170 :InterlacingPolicy(array,shallowCopy)
00171 {
00172 if (shallowCopy)
00173 this->_array.set(array._array);
00174 else
00175 this->_array.set(InterlacingPolicy::_arraySize,array._array);
00176 }
00177
00178
00179
00180
00181 inline MEDMEM_Array<ElementType,InterlacingPolicy,CheckingPolicy> &
00182 operator=( const MEDMEM_Array & array) {
00183 if ( this == &array) return *this;
00184 const char* LOC = "MEDMEM_Array operator =";
00185 BEGIN_OF_MED(LOC);
00186 InterlacingPolicy::operator=(array);
00187
00188 this->_array.set(array._array);
00189
00190 return *this;
00191 }
00192
00193 MED_EN::medModeSwitch getInterlacingType() const {
00194 return InterlacingPolicy::getInterlacingType();
00195 }
00196
00197 bool getGaussPresence() const {
00198 return InterlacingPolicy::getGaussPresence();
00199 }
00200
00201 ElementType * getPtr() {
00202 return _array;
00203 }
00204
00205 const ElementType * getPtr() const {
00206 return _array;
00207 }
00208
00209 void setPtr(ElementType * values, bool shallowCopy=false,
00210 bool ownershipOfValues=false) {
00211
00212 if(shallowCopy)
00213
00214 if(ownershipOfValues)
00215 _array.setShallowAndOwnership((const ElementType *)values);
00216 else
00217 _array.set((const ElementType*)values);
00218
00219 else
00220 _array.set(InterlacingPolicy::_arraySize,values);
00221 }
00222
00223 inline const ElementType * getRow(int i) const {
00224 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00225
00226
00227 CHECKING_POLICY::checkEquality("MEDMEM_Array (Interlace test)",
00228 MED_EN::MED_NO_INTERLACE,
00229 InterlacingPolicy::_interlacing );
00230 return &(_array[ InterlacingPolicy::getIndex(i,1) ]);
00231
00232 }
00233
00234 void setRow(int i,const ElementType * const value) {
00235 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00236
00237
00238
00239
00240 for (int j =1; j <= InterlacingPolicy::getDim(); j++) {
00241 for (int k = 1 ; k <= InterlacingPolicy::getNbGauss(i); k++) {
00242 _array[InterlacingPolicy::getIndex(i,j,k)] = value[InterlacingPolicy::getIndex(1,j,k)];
00243
00244
00245 }
00246 }
00247 }
00248
00249 inline const ElementType * getColumn(int j) const {
00250 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00251 CHECKING_POLICY::checkEquality("MEDMEM_Array (Interlace test)",
00252 MED_EN::MED_FULL_INTERLACE, InterlacingPolicy::_interlacing );
00253 return &(_array[ InterlacingPolicy::getIndex(1,j) ]);
00254 }
00255
00256 void setColumn(int j, const ElementType * const value) {
00257 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00258
00259
00260
00261 int index = -1;
00262 for (int i=1; i <= InterlacingPolicy::getNbElem(); i++) {
00263 for (int k = 1 ; k <= InterlacingPolicy::getNbGauss(i); k++) {
00264
00265 index++;
00266 _array[InterlacingPolicy::getIndex(i,j,k)] = value[index];
00267 }
00268 }
00269 }
00270
00271
00272 inline const ElementType & getIJ(int i, int j) const {
00273 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00274 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00275 return _array[ InterlacingPolicy::getIndex(i,j) ];
00276 }
00277
00278 inline const ElementType & getIJK(int i, int j, int k ) const {
00279 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00280 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00281 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k);
00282
00283 return _array[ InterlacingPolicy::getIndex(i,j,k) ];
00284 };
00285
00286 inline const ElementType & getIJByType(int i, int j, int t) const {
00287 if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE )
00288 throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType()));
00289 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00290 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00291 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t);
00292 if ( InterlacingPolicy::getGaussPresence() )
00293 return _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,t) ];
00294 else
00295 return _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,t) ];
00296 }
00297
00298 inline const ElementType & getIJKByType(int i, int j, int k, int t) const {
00299 if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE )
00300 throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType()));
00301 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00302 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t);
00303 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00304
00305 if ( InterlacingPolicy::getGaussPresence() ) {
00306
00307
00308
00309 int kmax = ((NoInterlaceByTypeGaussPolicy*)this)->getNbGaussByType(t);
00310 if ( k < 1 || k > kmax )
00311 throw MEDEXCEPTION(LOCALIZED(STRING("MEDMEM_Array::getIJKByType(), ")
00312 << " k : " << k << " not in rang [1," << kmax <<"]"));
00313 return _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,k,t) ];
00314 }
00315 else {
00316 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k);
00317 return _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,k,t) ];
00318 }
00319 };
00320
00321 inline void setIJ(int i, int j, const ElementType & value) {
00322 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00323 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00324
00325 _array[ InterlacingPolicy::getIndex(i,j) ] = value;
00326 };
00327
00328 inline void setIJByType(int i, int j, int t, const ElementType & value) {
00329 if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE )
00330 throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType()));
00331 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00332 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00333 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t);
00334
00335 if ( InterlacingPolicy::getGaussPresence() )
00336 _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,t) ] = value;
00337 else
00338 _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,t) ] = value;
00339 };
00340
00341 inline void setIJK(int i, int j, int k, const ElementType & value) {
00342 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00343 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00344 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k);
00345
00346 _array[ InterlacingPolicy::getIndex(i,j,k) ] = value;
00347 };
00348
00349 inline void setIJKByType(int i, int j, int k, int t, const ElementType & value) {
00350 if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE )
00351 throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType()));
00352 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i);
00353 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j);
00354 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t);
00355
00356 if ( InterlacingPolicy::getGaussPresence() ) {
00357
00358
00359
00360 int kmax = ((NoInterlaceByTypeGaussPolicy*)this)->getNbGaussByType(t);
00361 if ( k < 1 || k > kmax )
00362 throw MEDEXCEPTION(LOCALIZED(STRING("MEDMEM_Array::getIJKByType(), ")
00363 << " k : " << k << " not in rang [1," << kmax <<"]"));
00364 _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,k,t) ] = value;
00365 }
00366 else {
00367 CHECKING_POLICY::checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k);
00368 _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,k,t) ] = value;
00369 }
00370 };
00371
00372 bool operator == (const MEDMEM_Array & array ) const {
00373
00374 if ( this == &array ) return true;
00375
00376 int size = array.getArraySize();
00377 if ( size != this->getArraySize() ) return false;
00378
00379 ARRAY_ELEMENT_TYPE * arrayPtr =
00380 const_cast<MEDMEM_Array &>(array).getPtr();
00381 for (int i=0; i < size; ++i)
00382 if (_array[i] != arrayPtr[i]) return false;
00383
00384 return true;
00385 }
00386
00387 friend ostream & operator<<(ostream & os, const MEDMEM_Array & array) {
00388
00389 for (int i=1;i<=array.getNbElem();++i) {
00390 for (int j=1; j<=array.getDim();++j)
00391 for (int k=1;k<=array.getNbGauss(i);++k)
00392 os << "Value [" << i << "," << j << "," << k << "] = " << array.getIJK(i,j,k) << ", ";
00393 os << endl;
00394 }
00395 return os;
00396 }
00397
00398 private:
00399
00400 PointerOf<ElementType> _array;
00401 };
00402
00403 }
00404 #endif