LORENE
itbl.h
1 /*
2  * Definition of Lorene class Itbl
3  *
4  */
5 
6 /*
7  * Copyright (c) 1999-2001 Philippe Grandclement
8  *
9  * This file is part of LORENE.
10  *
11  * LORENE is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * LORENE is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with LORENE; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  *
25  */
26 
27 
28 #ifndef __ITBL_H_
29 #define __ITBL_H_
30 
31 /*
32  * Classe de tableaux d'entiers de dimension determinee (actuellement 1, 2 et 3)
33  *
34  */
35 
36 /*
37  * $Id: itbl.h,v 1.9 2014/10/13 08:52:35 j_novak Exp $
38  * $Log: itbl.h,v $
39  * Revision 1.9 2014/10/13 08:52:35 j_novak
40  * Lorene classes and functions now belong to the namespace Lorene.
41  *
42  * Revision 1.8 2014/10/06 15:09:39 j_novak
43  * Modified #include directives to use c++ syntax.
44  *
45  * Revision 1.7 2004/03/24 14:53:39 j_novak
46  * Double declarations suppressed
47  *
48  * Revision 1.6 2004/03/22 13:12:41 j_novak
49  * Modification of comments to use doxygen instead of doc++
50  *
51  * Revision 1.5 2003/11/06 14:43:37 e_gourgoulhon
52  * Gave a name to const arguments in certain method prototypes (e.g.
53  * constructors) to correct a bug of DOC++.
54  *
55  * Revision 1.4 2003/10/11 16:43:05 e_gourgoulhon
56  *
57  * IMPORTANT CHANGE: the standard constructors sets now the logical state
58  * to ETATQCQ, and no longer to ETATNONDEF.
59  *
60  * Revision 1.3 2002/10/16 14:36:29 j_novak
61  * Reorganization of #include instructions of standard C++, in order to
62  * use experimental version 3 of gcc.
63  *
64  * Revision 1.2 2002/06/17 14:05:16 j_novak
65  * friend functions are now also declared outside the class definition
66  *
67  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
68  * LORENE
69  *
70  * Revision 2.2 1999/11/23 13:16:12 eric
71  * Le constructeur Itbl::Itbl(const Dim_tbl ) devient desormais
72  * Itbl::Itbl(const Dim_tbl& ).
73  * Modif commentaires (taille 0 autorisee).
74  *
75  * Revision 2.1 1999/11/19 12:02:17 phil
76  * /
77  *
78  * Revision 2.0 1999/11/17 16:04:27 phil
79  * *** empty log message ***
80  *
81  * Revision 1.1 1999/11/17 16:03:06 phil
82  * Initial revision
83  *
84  *
85  * $Header: /cvsroot/Lorene/C++/Include/itbl.h,v 1.9 2014/10/13 08:52:35 j_novak Exp $
86  *
87  */
88 
89 // Fichiers includes
90 #include <cassert>
91 #include <cstdlib>
92 
93 #include "type_parite.h"
94 #include "dim_tbl.h"
95 
96 
97 namespace Lorene {
122 class Itbl {
123 
124  // Data :
125  // -----
126  private:
128  int etat ;
129 
130  public:
132  int* t ;
133 
134  // Constructors - Destructor
135  // -------------------------
136 
137  public:
148  explicit Itbl(int size0) ;
149 
163  Itbl(int size1, int size0) ;
164 
181  Itbl(int size2, int size1, int size0) ;
182 
183 
189  explicit Itbl(const Dim_tbl& ) ;
190 
192  explicit Itbl(FILE* ) ;
193 
194  Itbl(const Itbl& ) ;
195 
196  ~Itbl() ;
197 
198  // Assignement
199  // -----------
200  void operator=(const Itbl& ) ;
201  void operator=(int ) ;
202 
203  // Memory management
204  // -----------------
205  private:
209  void del_t() ;
210 
211  public:
212 
217  void set_etat_nondef() ;
218 
223  void set_etat_zero() ;
224 
231  void set_etat_qcq() ;
232 
241  void annule_hard() ;
242 
243  // Access to individual elements
244  // -----------------------------
245  public:
247  int& set(int i) {
248  assert (etat == ETATQCQ) ;
249  assert( dim.ndim == 1 ) ;
250  assert( i >= 0 ) ;
251  assert( i < dim.dim[0] ) ;
252  return t[i] ;
253  } ;
254 
256  int operator()(int i) const {
257  assert(etat != ETATNONDEF) ;
258  assert( dim.ndim == 1 ) ;
259  assert( i >= 0 ) ;
260  assert( i < dim.dim[0] ) ;
261  if (etat == ETATZERO) {
262  int zero = 0 ;
263  return zero ;
264  }
265  else return t[i] ;
266  };
267 
269  int& set(int j, int i) {
270  assert (etat == ETATQCQ) ;
271  assert( dim.ndim == 2 ) ;
272  assert( (i>=0) && (i<dim.dim[0]) ) ;
273  assert( (j>=0) && (j<dim.dim[1]) ) ;
274  return t[dim.dim[0] * j + i] ;
275  };
276 
278  int operator()(int j, int i) const {
279  assert(etat != ETATNONDEF) ;
280  assert( dim.ndim == 2 ) ;
281  assert( (i>=0) && (i<dim.dim[0]) ) ;
282  assert( (j>=0) && (j<dim.dim[1]) ) ;
283  if (etat == ETATZERO) {
284  int zero = 0 ;
285  return zero ;
286  }
287  else return t[dim.dim[0] * j + i] ;
288  };
289 
291  int& set(int k, int j, int i) {
292  assert (etat == ETATQCQ) ;
293  assert( dim.ndim == 3 ) ;
294  assert( (i>=0) && (i<dim.dim[0]) ) ;
295  assert( (j>=0) && (j<dim.dim[1]) ) ;
296  assert( (k>=0) && (k<dim.dim[2]) ) ;
297  return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
298  };
299 
301  int operator()(int k, int j, int i) const {
302  assert(etat != ETATNONDEF) ;
303  assert( dim.ndim == 3 ) ;
304  assert( (i>=0) && (i<dim.dim[0]) ) ;
305  assert( (j>=0) && (j<dim.dim[1]) ) ;
306  assert( (k>=0) && (k<dim.dim[2]) ) ;
307  if (etat == ETATZERO) {
308  int zero = 0 ;
309  return zero ;
310  }
311  else return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
312  };
313 
314  // Extraction of information
315  // -------------------------
317  int get_etat() const { return etat ; } ;
318 
320  int get_taille() const { return dim.taille ; };
321 
323  int get_ndim() const { return dim.ndim ; };
324 
326  int get_dim(int i) const {
327  assert( (i>=0) && (i<dim.ndim) ) ;
328  return dim.dim[i] ;
329  };
330 
331  // Outputs
332  // -------
333  public:
334  void sauve(FILE* ) const ;
335 
337  friend ostream& operator<<(ostream& , const Itbl& ) ;
338 
339  // Member arithmetics
340  // ------------------
341  public:
342 
343  void operator+=(const Itbl &) ;
344  void operator+=(int) ;
345  void operator-=(const Itbl &) ;
346  void operator-=(int) ;
347  void operator*=(const Itbl &) ;
348  void operator*=(int) ;
349 } ;
350 ostream& operator<<(ostream& , const Itbl& ) ;
351 
352 
359 Itbl operator+(const Itbl&) ;
360 Itbl operator-(const Itbl&) ;
361 Itbl operator+(const Itbl&, const Itbl&) ;
362 Itbl operator+(const Itbl&, int) ;
363 Itbl operator+(int a, const Itbl& b) ;
364 Itbl operator-(const Itbl&, const Itbl&) ;
365 Itbl operator-(const Itbl&, int) ;
366 Itbl operator-(int, const Itbl&) ;
367 Itbl operator*(const Itbl&, const Itbl&) ;
368 Itbl operator*(const Itbl&, int) ;
369 Itbl operator*(int, const Itbl&) ;
370 
371 Itbl abs(const Itbl& ) ;
372 int max(const Itbl& ) ;
373 int min(const Itbl& ) ;
374 
376 int norme(const Itbl& ) ;
377 
383 double diffrel(const Itbl& a, const Itbl& b) ;
384 
390 double diffrelmax(const Itbl& a, const Itbl& b) ;
391 
393 }
394 #endif
void del_t()
Logical destructor: dellocates the memory occupied by the array t and sets the logical state to ETATN...
Definition: itbl.C:243
Itbl(int size0)
1D constructor.
Definition: itbl.C:100
int get_taille() const
Gives the total size (ie dim.taille )
Definition: itbl.h:320
int get_ndim() const
Gives the number of dimensions (ie dim.ndim )
Definition: itbl.h:323
Lorene prototypes.
Definition: app_hor.h:67
void annule_hard()
Sets the Itbl to zero in a hard way.
Definition: itbl.C:275
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
void operator*=(const Itbl &)
Multiplication of this by a Itbl.
Definition: itbl_arithm.C:465
~Itbl()
Destructor.
Definition: itbl.C:170
int taille
Total size of the array Tbl::t.
Definition: dim_tbl.h:112
Basic integer array class.
Definition: itbl.h:122
int operator()(int i) const
Read-only of a particular element (index i ) (1D case)
Definition: itbl.h:256
Tbl min(const Cmp &)
Minimum values of a Cmp in each domain.
Definition: cmp_math.C:461
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition: cmp_math.C:507
void operator-=(const Itbl &)
Subtraction of a Itbl to this.
Definition: itbl_arithm.C:393
Dim_tbl dim
Number of dimensions, size,...
Definition: itbl.h:131
friend ostream & operator<<(ostream &, const Itbl &)
Display.
Definition: itbl.C:294
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition: cmp_math.C:484
Cmp operator+(const Cmp &)
Definition: cmp_arithm.C:107
void sauve(FILE *) const
Save in a file.
Definition: itbl.C:229
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition: itbl.C:257
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition: cmp_math.C:438
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: itbl.C:264
int operator()(int j, int i) const
Read-only of a particular element (index (j,i) ) (2D case)
Definition: itbl.h:278
int get_etat() const
Gives the logical state.
Definition: itbl.h:317
int operator()(int k, int j, int i) const
Read-only of a particular element (index (k,j,i) ) (3D case)
Definition: itbl.h:301
int ndim
Number of dimensions of the Tbl: can be 1, 2 or 3.
Definition: dim_tbl.h:101
Storage of array dimensions.
Definition: dim_tbl.h:99
void operator=(const Itbl &)
Assignment to another Itbl.
Definition: itbl.C:179
void operator+=(const Itbl &)
Addition of a Itbl to this.
Definition: itbl_arithm.C:321
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:413
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] )
Definition: itbl.h:326
Cmp operator-(const Cmp &)
- Cmp
Definition: cmp_arithm.C:111
int * t
The array of int &#39;s.
Definition: itbl.h:132
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: itbl.C:250
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition: cmp_math.C:542
int * dim
Array of dimensions (size: ndim).
Definition: dim_tbl.h:102
int etat
logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition: itbl.h:128