00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __ITBL_H_
00029 #define __ITBL_H_
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #include <assert.h>
00085 #include <stdlib.h>
00086
00087 #include "type_parite.h"
00088 #include "dim_tbl.h"
00089
00090
00115 class Itbl {
00116
00117
00118
00119 private:
00121 int etat ;
00122
00123 public:
00124 Dim_tbl dim ;
00125 int* t ;
00126
00127
00128
00129
00130 public:
00141 explicit Itbl(int size0) ;
00142
00156 Itbl(int size1, int size0) ;
00157
00174 Itbl(int size2, int size1, int size0) ;
00175
00176
00182 explicit Itbl(const Dim_tbl& ) ;
00183
00185 explicit Itbl(FILE* ) ;
00186
00187 Itbl(const Itbl& ) ;
00188
00189 ~Itbl() ;
00190
00191
00192
00193 void operator=(const Itbl& ) ;
00194 void operator=(int ) ;
00195
00196
00197
00198 private:
00202 void del_t() ;
00203
00204 public:
00205
00210 void set_etat_nondef() ;
00211
00216 void set_etat_zero() ;
00217
00224 void set_etat_qcq() ;
00225
00234 void annule_hard() ;
00235
00236
00237
00238 public:
00240 int& set(int i) {
00241 assert (etat == ETATQCQ) ;
00242 assert( dim.ndim == 1 ) ;
00243 assert( i >= 0 ) ;
00244 assert( i < dim.dim[0] ) ;
00245 return t[i] ;
00246 } ;
00247
00249 int operator()(int i) const {
00250 assert(etat != ETATNONDEF) ;
00251 assert( dim.ndim == 1 ) ;
00252 assert( i >= 0 ) ;
00253 assert( i < dim.dim[0] ) ;
00254 if (etat == ETATZERO) {
00255 int zero = 0 ;
00256 return zero ;
00257 }
00258 else return t[i] ;
00259 };
00260
00262 int& set(int j, int i) {
00263 assert (etat == ETATQCQ) ;
00264 assert( dim.ndim == 2 ) ;
00265 assert( (i>=0) && (i<dim.dim[0]) ) ;
00266 assert( (j>=0) && (j<dim.dim[1]) ) ;
00267 return t[dim.dim[0] * j + i] ;
00268 };
00269
00271 int operator()(int j, int i) const {
00272 assert(etat != ETATNONDEF) ;
00273 assert( dim.ndim == 2 ) ;
00274 assert( (i>=0) && (i<dim.dim[0]) ) ;
00275 assert( (j>=0) && (j<dim.dim[1]) ) ;
00276 if (etat == ETATZERO) {
00277 int zero = 0 ;
00278 return zero ;
00279 }
00280 else return t[dim.dim[0] * j + i] ;
00281 };
00282
00284 int& set(int k, int j, int i) {
00285 assert (etat == ETATQCQ) ;
00286 assert( dim.ndim == 3 ) ;
00287 assert( (i>=0) && (i<dim.dim[0]) ) ;
00288 assert( (j>=0) && (j<dim.dim[1]) ) ;
00289 assert( (k>=0) && (k<dim.dim[2]) ) ;
00290 return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
00291 };
00292
00294 int operator()(int k, int j, int i) const {
00295 assert(etat != ETATNONDEF) ;
00296 assert( dim.ndim == 3 ) ;
00297 assert( (i>=0) && (i<dim.dim[0]) ) ;
00298 assert( (j>=0) && (j<dim.dim[1]) ) ;
00299 assert( (k>=0) && (k<dim.dim[2]) ) ;
00300 if (etat == ETATZERO) {
00301 int zero = 0 ;
00302 return zero ;
00303 }
00304 else return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
00305 };
00306
00307
00308
00310 int get_etat() const { return etat ; } ;
00311
00313 int get_taille() const { return dim.taille ; };
00314
00316 int get_ndim() const { return dim.ndim ; };
00317
00319 int get_dim(int i) const {
00320 assert( (i>=0) && (i<dim.ndim) ) ;
00321 return dim.dim[i] ;
00322 };
00323
00324
00325
00326 public:
00327 void sauve(FILE* ) const ;
00328
00330 friend ostream& operator<<(ostream& , const Itbl& ) ;
00331
00332
00333
00334 public:
00335
00336 void operator+=(const Itbl &) ;
00337 void operator+=(int) ;
00338 void operator-=(const Itbl &) ;
00339 void operator-=(int) ;
00340 void operator*=(const Itbl &) ;
00341 void operator*=(int) ;
00342 } ;
00343 ostream& operator<<(ostream& , const Itbl& ) ;
00344
00345
00352 Itbl operator+(const Itbl&) ;
00353 Itbl operator-(const Itbl&) ;
00354 Itbl operator+(const Itbl&, const Itbl&) ;
00355 Itbl operator+(const Itbl&, int) ;
00356 Itbl operator+(int a, const Itbl& b) ;
00357 Itbl operator-(const Itbl&, const Itbl&) ;
00358 Itbl operator-(const Itbl&, int) ;
00359 Itbl operator-(int, const Itbl&) ;
00360 Itbl operator*(const Itbl&, const Itbl&) ;
00361 Itbl operator*(const Itbl&, int) ;
00362 Itbl operator*(int, const Itbl&) ;
00363
00364 Itbl abs(const Itbl& ) ;
00365 int max(const Itbl& ) ;
00366 int min(const Itbl& ) ;
00367
00369 int norme(const Itbl& ) ;
00370
00376 double diffrel(const Itbl& a, const Itbl& b) ;
00377
00383 double diffrelmax(const Itbl& a, const Itbl& b) ;
00384
00386 #endif