itbl.h
/*
* Definition of Lorene class Itbl
*
*/
/*
* Copyright (c) 1999-2001 Philippe Grandclement
*
* This file is part of LORENE.
*
* LORENE is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LORENE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LORENE; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __ITBL_H_
#define __ITBL_H_
/*
* Classe de tableaux d'entiers de dimension determinee (actuellement 1, 2 et 3)
*
*/
/*
* $Id: itbl.h,v 1.9 2014/10/13 08:52:35 j_novak Exp $
* $Log: itbl.h,v $
* Revision 1.9 2014/10/13 08:52:35 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.8 2014/10/06 15:09:39 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.7 2004/03/24 14:53:39 j_novak
* Double declarations suppressed
*
* Revision 1.6 2004/03/22 13:12:41 j_novak
* Modification of comments to use doxygen instead of doc++
*
* Revision 1.5 2003/11/06 14:43:37 e_gourgoulhon
* Gave a name to const arguments in certain method prototypes (e.g.
* constructors) to correct a bug of DOC++.
*
* Revision 1.4 2003/10/11 16:43:05 e_gourgoulhon
*
* IMPORTANT CHANGE: the standard constructors sets now the logical state
* to ETATQCQ, and no longer to ETATNONDEF.
*
* Revision 1.3 2002/10/16 14:36:29 j_novak
* Reorganization of #include instructions of standard C++, in order to
* use experimental version 3 of gcc.
*
* Revision 1.2 2002/06/17 14:05:16 j_novak
* friend functions are now also declared outside the class definition
*
* Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
* LORENE
*
* Revision 2.2 1999/11/23 13:16:12 eric
* Le constructeur Itbl::Itbl(const Dim_tbl ) devient desormais
* Itbl::Itbl(const Dim_tbl& ).
* Modif commentaires (taille 0 autorisee).
*
* Revision 2.1 1999/11/19 12:02:17 phil
* /
*
* Revision 2.0 1999/11/17 16:04:27 phil
* *** empty log message ***
*
* Revision 1.1 1999/11/17 16:03:06 phil
* Initial revision
*
*
* $Header: /cvsroot/Lorene/C++/Include/itbl.h,v 1.9 2014/10/13 08:52:35 j_novak Exp $
*
*/
// Fichiers includes
#include <cassert>
#include <cstdlib>
#include "type_parite.h"
#include "dim_tbl.h"
namespace Lorene {
class Itbl {
// Data :
// -----
private:
int etat ;
public:
Dim_tbl dim ;
int* t ;
// Constructors - Destructor
// -------------------------
public:
explicit Itbl(int size0) ;
Itbl(int size1, int size0) ;
Itbl(int size2, int size1, int size0) ;
explicit Itbl(const Dim_tbl& ) ;
explicit Itbl(FILE* ) ;
Itbl(const Itbl& ) ;
~Itbl() ;
// Assignement
// -----------
void operator=(const Itbl& ) ;
void operator=(int ) ;
// Memory management
// -----------------
private:
void del_t() ;
public:
void set_etat_nondef() ;
void set_etat_zero() ;
void set_etat_qcq() ;
void annule_hard() ;
// Access to individual elements
// -----------------------------
public:
int& set(int i) {
assert (etat == ETATQCQ) ;
assert( dim.ndim == 1 ) ;
assert( i >= 0 ) ;
assert( i < dim.dim[0] ) ;
return t[i] ;
} ;
int operator()(int i) const {
assert(etat != ETATNONDEF) ;
assert( dim.ndim == 1 ) ;
assert( i >= 0 ) ;
assert( i < dim.dim[0] ) ;
if (etat == ETATZERO) {
int zero = 0 ;
return zero ;
}
else return t[i] ;
};
int& set(int j, int i) {
assert (etat == ETATQCQ) ;
assert( dim.ndim == 2 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
return t[dim.dim[0] * j + i] ;
};
int operator()(int j, int i) const {
assert(etat != ETATNONDEF) ;
assert( dim.ndim == 2 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
if (etat == ETATZERO) {
int zero = 0 ;
return zero ;
}
else return t[dim.dim[0] * j + i] ;
};
int& set(int k, int j, int i) {
assert (etat == ETATQCQ) ;
assert( dim.ndim == 3 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
assert( (k>=0) && (k<dim.dim[2]) ) ;
return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
};
int operator()(int k, int j, int i) const {
assert(etat != ETATNONDEF) ;
assert( dim.ndim == 3 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
assert( (k>=0) && (k<dim.dim[2]) ) ;
if (etat == ETATZERO) {
int zero = 0 ;
return zero ;
}
else return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
};
// Extraction of information
// -------------------------
int get_etat() const { return etat ; } ;
int get_taille() const { return dim.taille ; };
int get_ndim() const { return dim.ndim ; };
int get_dim(int i) const {
assert( (i>=0) && (i<dim.ndim) ) ;
return dim.dim[i] ;
};
// Outputs
// -------
public:
void sauve(FILE* ) const ;
friend ostream& operator<<(ostream& , const Itbl& ) ;
// Member arithmetics
// ------------------
public:
void operator+=(const Itbl &) ;
void operator+=(int) ;
void operator-=(const Itbl &) ;
void operator-=(int) ;
void operator*=(const Itbl &) ;
void operator*=(int) ;
} ;
ostream& operator<<(ostream& , const Itbl& ) ;
Itbl operator+(const Itbl&) ;
Itbl operator-(const Itbl&) ;
Itbl operator+(const Itbl&, const Itbl&) ;
Itbl operator+(const Itbl&, int) ;
Itbl operator+(int a, const Itbl& b) ;
Itbl operator-(const Itbl&, const Itbl&) ;
Itbl operator-(const Itbl&, int) ;
Itbl operator-(int, const Itbl&) ;
Itbl operator*(const Itbl&, const Itbl&) ;
Itbl operator*(const Itbl&, int) ;
Itbl operator*(int, const Itbl&) ;
Itbl abs(const Itbl& ) ;
int max(const Itbl& ) ;
int min(const Itbl& ) ;
int norme(const Itbl& ) ;
double diffrel(const Itbl& a, const Itbl& b) ;
double diffrelmax(const Itbl& a, const Itbl& b) ;
}
#endif
Lorene::Dim_tbl
Storage of array dimensions.
Definition dim_tbl.h:99
Lorene::Itbl
Basic integer array class.
Definition itbl.h:122
Lorene::Itbl::operator-=
void operator-=(const Itbl &)
Subtraction of a Itbl to this.
Definition itbl_arithm.C:390
Lorene::Itbl::~Itbl
~Itbl()
Destructor.
Definition itbl.C:167
Lorene::Itbl::Itbl
Itbl(int size0)
1D constructor.
Definition itbl.C:97
Lorene::Itbl::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition itbl.C:261
Lorene::Itbl::del_t
void del_t()
Logical destructor: dellocates the memory occupied by the array t and sets the logical state to ETATN...
Definition itbl.C:240
Lorene::Itbl::operator*=
void operator*=(const Itbl &)
Multiplication of this by a Itbl.
Definition itbl_arithm.C:462
Lorene::Itbl::etat
int etat
logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition itbl.h:128
Lorene::Itbl::set_etat_nondef
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition itbl.C:254
Lorene::Itbl::operator()
int operator()(int i) const
Read-only of a particular element (index i ) (1D case).
Definition itbl.h:256
Lorene::Itbl::dim
Dim_tbl dim
Number of dimensions, size,...
Definition itbl.h:131
Lorene::Itbl::operator()
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
Lorene::Itbl::set_etat_zero
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition itbl.C:247
Lorene::Itbl::get_dim
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] ).
Definition itbl.h:326
Lorene::Itbl::set
int & set(int i)
Read/write of a particular element (index i ) (1D case).
Definition itbl.h:247
Lorene::Itbl::get_etat
int get_etat() const
Gives the logical state.
Definition itbl.h:317
Lorene::Itbl::t
int * t
The array of int 's.
Definition itbl.h:132
Lorene::Itbl::annule_hard
void annule_hard()
Sets the Itbl to zero in a hard way.
Definition itbl.C:272
Lorene::Itbl::operator+=
void operator+=(const Itbl &)
Addition of a Itbl to this.
Definition itbl_arithm.C:318
Lorene::Itbl::sauve
void sauve(FILE *) const
Save in a file.
Definition itbl.C:226
Lorene::Itbl::set
int & set(int k, int j, int i)
Read/write of a particular element (index (k,j,i) ) (3D case).
Definition itbl.h:291
Lorene::Itbl::set
int & set(int j, int i)
Read/write of a particular element (index (j,i) ) (2D case).
Definition itbl.h:269
Lorene::Itbl::get_taille
int get_taille() const
Gives the total size (ie dim.taille ).
Definition itbl.h:320
Lorene::Itbl::operator()
int operator()(int j, int i) const
Read-only of a particular element (index (j,i) ) (2D case).
Definition itbl.h:278
Lorene::Itbl::operator=
void operator=(const Itbl &)
Assignment to another Itbl.
Definition itbl.C:176
Lorene::Itbl::operator<<
friend ostream & operator<<(ostream &, const Itbl &)
Display.
Definition itbl.C:291
Lorene::Itbl::get_ndim
int get_ndim() const
Gives the number of dimensions (ie dim.ndim ).
Definition itbl.h:323
Lorene::operator*
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Definition base_val_mult.C:102
Lorene::operator-
Cmp operator-(const Cmp &)
- Cmp
Definition cmp_arithm.C:108
Lorene::diffrel
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition cmp_math.C:504
Lorene::norme
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition cmp_math.C:481
Lorene::min
Tbl min(const Cmp &)
Minimum values of a Cmp in each domain.
Definition cmp_math.C:458
Lorene::max
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition cmp_math.C:435
Lorene::abs
Cmp abs(const Cmp &)
Absolute value.
Definition cmp_math.C:410
Lorene::diffrelmax
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition cmp_math.C:539
Lorene::operator+
Cmp operator+(const Cmp &)
Definition cmp_arithm.C:104
Lorene
Lorene prototypes.
Definition app_hor.h:64