Escript
Revision_4320
Main Page
Namespaces
Classes
Files
File List
File Members
escript
src
DataBlocks2D.h
Go to the documentation of this file.
1
2
/*****************************************************************************
3
*
4
* Copyright (c) 2003-2013 by University of Queensland
5
* http://www.uq.edu.au
6
*
7
* Primary Business: Queensland, Australia
8
* Licensed under the Open Software License version 3.0
9
* http://www.opensource.org/licenses/osl-3.0.php
10
*
11
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12
* Development since 2012 by School of Earth Sciences
13
*
14
*****************************************************************************/
15
16
17
#if !defined escript_DataBlocks2D_20040405_H
18
#define escript_DataBlocks2D_20040405_H
19
#include "
system_dep.h
"
20
21
#include "
DataVector.h
"
22
23
#include <sstream>
24
#include <iostream>
25
26
namespace
escript {
27
37
class
DataBlocks2D
{
38
39
public
:
40
41
//
42
// The type of the underlying data array under management.
43
// The multi-dimensional data points are flattened and stored
44
// serially as a vector of doubles.
45
typedef
DataVector
ValueType
;
46
55
ESCRIPT_DLL_API
56
DataBlocks2D
();
57
65
ESCRIPT_DLL_API
66
DataBlocks2D
(
const
DataBlocks2D
& other);
67
81
ESCRIPT_DLL_API
82
DataBlocks2D
(
int
numRows,
int
numCols,
int
blockSize);
83
91
ESCRIPT_DLL_API
92
~DataBlocks2D
();
93
99
ESCRIPT_DLL_API
100
inline
101
ValueType::size_type
102
size
()
const
;
103
108
ESCRIPT_DLL_API
109
inline
110
ValueType::size_type
111
getNumRows
()
const
;
112
117
ESCRIPT_DLL_API
118
inline
119
ValueType::size_type
120
getNumCols
()
const
;
121
126
ESCRIPT_DLL_API
127
inline
128
ValueType::size_type
129
getBlockSize
()
const
;
130
142
ESCRIPT_DLL_API
143
void
144
resize
(
int
numRows,
int
numCols,
int
blockSize);
145
151
ESCRIPT_DLL_API
152
DataBlocks2D
&
153
operator=
(
const
DataBlocks2D
& other);
154
159
ESCRIPT_DLL_API
160
void
161
Swap
(
DataBlocks2D
& other);
162
171
ESCRIPT_DLL_API
172
inline
173
ValueType::size_type
174
index
(
int
row,
int
col)
const
;
175
181
ESCRIPT_DLL_API
182
inline
183
ValueType::reference
184
operator[]
(
ValueType::size_type
i);
185
186
ESCRIPT_DLL_API
187
inline
188
ValueType::const_reference
189
operator[]
(
ValueType::size_type
i)
const
;
190
195
ESCRIPT_DLL_API
196
inline
197
ValueType::reference
198
operator()
(
int
row,
int
col);
199
200
ESCRIPT_DLL_API
201
inline
202
ValueType::const_reference
203
operator()
(
int
row,
int
col)
const
;
204
211
ESCRIPT_DLL_API
212
inline
213
ValueType
&
214
getData
();
215
216
ESCRIPT_DLL_API
217
inline
218
const
ValueType
&
219
getData
()
const
;
220
221
222
protected
:
223
224
private
:
225
226
//
227
// The underlying array of data values.
228
// The two dimensional array of multi-dimensional data points is flattened
229
// and serialised within this one dimensional array of doubles.
230
ValueType
m_data
;
231
232
//
233
// The dimensions of the 2D array of data points.
234
ValueType::size_type
m_numRows
;
235
ValueType::size_type
m_numCols
;
236
237
//
238
// The number of values per data point.
239
ValueType::size_type
m_blockSize
;
240
241
};
242
243
inline
244
DataBlocks2D::ValueType::size_type
245
DataBlocks2D::size
()
const
246
{
247
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
248
return
m_data
.
size
();
249
}
250
251
inline
252
DataBlocks2D::ValueType::size_type
253
DataBlocks2D::getNumRows
()
const
254
{
255
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
256
return
m_numRows
;
257
}
258
259
inline
260
DataBlocks2D::ValueType::size_type
261
DataBlocks2D::getNumCols
()
const
262
{
263
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
264
return
m_numCols
;
265
}
266
267
inline
268
DataBlocks2D::ValueType::size_type
269
DataBlocks2D::getBlockSize
()
const
270
{
271
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
272
return
m_blockSize
;
273
}
274
275
inline
276
DataBlocks2D::ValueType::size_type
277
DataBlocks2D::index
(
int
row,
int
col)
const
278
{
279
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
280
EsysAssert
(((row >= 0) && (col >= 0) && (
m_data
.
size
() > 0)),
"(DataBlocks2D) Index value out of range."
);
281
ValueType::size_type
temp=(row*
m_numCols
+col)*
m_blockSize
;
282
EsysAssert
((temp <= (
m_data
.
size
()-
m_blockSize
)),
"(DataBlocks2D) Index value out of range."
);
283
return
(temp);
284
}
285
286
inline
287
DataBlocks2D::ValueType::reference
288
DataBlocks2D::operator[]
(
DataBlocks2D::ValueType::size_type
i)
289
{
290
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
291
return
m_data
[i];
292
}
293
294
inline
295
DataBlocks2D::ValueType::const_reference
296
DataBlocks2D::operator[]
(
DataBlocks2D::ValueType::size_type
i)
const
297
{
298
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
299
return
m_data
[i];
300
}
301
302
inline
303
DataBlocks2D::ValueType::reference
304
DataBlocks2D::operator()
(
int
row,
int
col)
305
{
306
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
307
return
m_data
[
index
(row,col)];
308
}
309
310
inline
311
DataBlocks2D::ValueType::const_reference
312
DataBlocks2D::operator()
(
int
row,
int
col)
const
313
{
314
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
315
return
m_data
[
index
(row,col)];
316
}
317
318
inline
319
DataBlocks2D::ValueType
&
320
DataBlocks2D::getData
()
321
{
322
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
323
return
m_data
;
324
}
325
326
inline
327
const
DataBlocks2D::ValueType
&
328
DataBlocks2D::getData
()
const
329
{
330
EsysAssert
(((
m_numRows
>= 0) && (
m_numCols
>= 0) && (
m_blockSize
>= 0)),
"(DataBlocks2D) Invalid object."
);
331
return
m_data
;
332
}
333
334
}
// end of namespace
335
336
#endif
Generated on Fri Mar 15 2013 14:07:49 for Escript by
1.8.1.2