itbl.h

00001 /*
00002  *  Definition of Lorene class Itbl
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 1999-2001 Philippe Grandclement
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License as published by
00013  *   the Free Software Foundation; either version 2 of the License, or
00014  *   (at your option) any later version.
00015  *
00016  *   LORENE is distributed in the hope that it will be useful,
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *   GNU General Public License for more details.
00020  *
00021  *   You should have received a copy of the GNU General Public License
00022  *   along with LORENE; if not, write to the Free Software
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 
00028 #ifndef __ITBL_H_
00029 #define __ITBL_H_
00030 
00031 /*
00032  * Classe de tableaux d'entiers de dimension determinee (actuellement 1, 2 et 3)
00033  *
00034  */
00035 
00036 /*
00037  * $Id: itbl.h,v 1.7 2004/03/24 14:53:39 j_novak Exp $
00038  * $Log: itbl.h,v $
00039  * Revision 1.7  2004/03/24 14:53:39  j_novak
00040  * Double declarations suppressed
00041  *
00042  * Revision 1.6  2004/03/22 13:12:41  j_novak
00043  * Modification of comments to use doxygen instead of doc++
00044  *
00045  * Revision 1.5  2003/11/06 14:43:37  e_gourgoulhon
00046  * Gave a name to const arguments in certain method prototypes (e.g.
00047  * constructors) to correct a bug of DOC++.
00048  *
00049  * Revision 1.4  2003/10/11 16:43:05  e_gourgoulhon
00050  *
00051  * IMPORTANT CHANGE: the standard constructors sets now the logical state
00052  *   to ETATQCQ, and no longer to ETATNONDEF.
00053  *
00054  * Revision 1.3  2002/10/16 14:36:29  j_novak
00055  * Reorganization of #include instructions of standard C++, in order to
00056  * use experimental version 3 of gcc.
00057  *
00058  * Revision 1.2  2002/06/17 14:05:16  j_novak
00059  * friend functions are now also declared outside the class definition
00060  *
00061  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00062  * LORENE
00063  *
00064  * Revision 2.2  1999/11/23  13:16:12  eric
00065  * Le constructeur Itbl::Itbl(const Dim_tbl ) devient desormais
00066  *   Itbl::Itbl(const Dim_tbl& ).
00067  * Modif commentaires (taille 0 autorisee).
00068  *
00069  * Revision 2.1  1999/11/19  12:02:17  phil
00070  * /
00071  *
00072  * Revision 2.0  1999/11/17  16:04:27  phil
00073  * *** empty log message ***
00074  *
00075  * Revision 1.1  1999/11/17  16:03:06  phil
00076  * Initial revision
00077  *
00078  *
00079  * $Header: /cvsroot/Lorene/C++/Include/itbl.h,v 1.7 2004/03/24 14:53:39 j_novak Exp $
00080  *
00081  */
00082  
00083 // Fichiers includes
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     // Data : 
00118     // -----
00119     private:
00121     int etat ;  
00122     
00123     public: 
00124     Dim_tbl dim ;       
00125     int*    t ;     
00126 
00127     // Constructors - Destructor
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     // Assignement
00192     // -----------
00193     void operator=(const Itbl& ) ;  
00194     void operator=(int ) ;   
00195 
00196     // Memory management
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     // Access to individual elements
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     // Extraction of information
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     // Outputs
00325     // -------
00326     public:
00327     void sauve(FILE* ) const ;  
00328 
00330     friend ostream& operator<<(ostream& , const Itbl& ) ;   
00331 
00332     // Member arithmetics
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

Generated on Tue Feb 7 01:35:17 2012 for LORENE by  doxygen 1.4.6