-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcellstate.cpp
More file actions
209 lines (179 loc) · 5.02 KB
/
cellstate.cpp
File metadata and controls
209 lines (179 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*******************************************************************
*
* DESCRIPTION: class CellState
*
* AUTHOR: Amir Barylko & Jorge Beyoglonian
* Version 2: Daniel Rodriguez.
*
* EMAIL: mailto://amir@dc.uba.ar
* mailto://jbeyoglo@dc.uba.ar
* mailto://drodrigu@dc.uba.ar
*
* DATE: 27/06/1998
* DATE: 22/11/1999 (v2)
*
*******************************************************************/
/** include files **/
#include <iomanip>
#include "cellstate.h"
#include "impresion.h"
using namespace std;
/** public functions **/
/*******************************************************************
* Function Name: CellState
********************************************************************/
CellState::CellState( nTupla &dim, bool wrap )
: wrapped( wrap )
{
dimList = new nTupla;
*dimList = dim;
matrix = new Real*[ dim.totalElements() ];
for (register long i = 0; i < dim.totalElements(); i++)
matrix[i] = new Real;
}
/*******************************************************************
* Function Name: ~CellState
********************************************************************/
CellState::~CellState()
{
for (long i = 0; i < dimList->totalElements(); i++)
delete matrix[i];
delete matrix;
delete dimList;
}
/*******************************************************************
* Function Name: operator []
********************************************************************/
const Real &CellState::operator[](CellPosition &pos) const
{
if ( this->isWrapped() )
pos.canonizar( *dimList );
else if ( !dimList->includes( pos ) )
return Real::tundef;
return *( matrix[ pos.calculateIndex( *dimList, false ) ] );
}
/*******************************************************************
* Function Name: operator []
********************************************************************/
Real &CellState::operator[](CellPosition &pos)
{
if ( this->isWrapped() )
pos.canonizar( *dimList );
else if ( ! dimList->includes( pos ) )
return Real::tundef;
return *( matrix[ pos.calculateIndex( *dimList, false ) ] );
}
/*******************************************************************
* Function Name: print
********************************************************************/
void CellState::print( ostream &os, char undefChar ) const
{
if ( dimList->dimension() != 2 && dimList->dimension() != 3){
printFormatedList( os );
return;
}
// SOLO IMPRIME EL ESTADO CUANDO LA DIMENSION ES 2 o 3
int width = Impresion::Default.Width(), prec = Impresion::Default.Precision();
register int tdim = 1;
if (dimList->dimension() == 3)
tdim = dimList->get(2);
if (!Impresion::Default.FlatLog())
{
for (register int k = 0; k < tdim; k++)
{
os << " " ;
for( register int j = 0; j < dimList->get(DIM_WIDTH); j++ )
{
os << setw( width ) << setprecision( prec );
if ( width < 2 )
os << j % 10; // Imprimo solo el ultimo digito
else
os << j;
}
os << " ";
}
os << endl ;
for ( register int k = 0; k < tdim; k++ )
{
os << " +" ;
for( register int j = 0; j < dimList->get(DIM_WIDTH) * width; j++ )
os << "-" ;
os << "+";
}
os << endl ;
}
int ndim = tdim;
int basedim = 0;
if (Impresion::Default.FlatLog())
{
if (Impresion::Default.FlatLogPlane() <= tdim)
{
ndim = Impresion::Default.FlatLogPlane();
basedim = Impresion::Default.FlatLogPlane() - 1;
}
else
ndim = 1;
}
for (register int i = 0; i < dimList->get(DIM_HEIGHT); i++ )
{
for (register int k = basedim; k < ndim; k++ )
{
if (!Impresion::Default.FlatLog())
os << setw(4) << i << "|" ;
for (register int j = 0; j < dimList->get(DIM_WIDTH); j++ )
{
nTupla nt;
nt.add(i,j);
if (dimList->dimension() == 3) // Si dim = 3
nt.add(k);
if( ((*this)[nt]).IsUndefined() )
{
for (register int w = 1; w < width; w++)
os << ' ';
os << undefChar ;
}
else if ( (*this)[nt] == Real::zero ){
if ( !Impresion::Default.PrintZero() )
{
for (register int w = 1; w <= width; w++)
os << ' ';
}
else
os << ((*this)[nt]).asString( width, prec );
}
else
os << ((*this)[nt]).asString( width, prec );
}
if (!Impresion::Default.FlatLog())
os << "|";
}
os << endl;
}
if (!Impresion::Default.FlatLog())
{
for (register int k = 0; k < tdim; k++)
{
os << " +" ;
for (register int j = 0; j < dimList->get(DIM_WIDTH) * width; j++)
os << "-" ;
os << "+";
}
os << endl << endl;
}
}
/*******************************************************************
* Function Name: printFormatedList
********************************************************************/
void CellState::printFormatedList( ostream &os ) const
{
// Esta funcion es utilizada para mostrar el estado cuando la
// dimension es mayor a 3. Si es 2 o 3 se debe usar la fn print.
CellPosition counter( dimList->dimension(), 0);
register bool overflow = false;
while (!overflow)
{
os << "\t" << counter << " = " << (*this)[counter] << "\n";
overflow = counter.next( *dimList );
}
os << endl << endl;
}