/[escript]/trunk/escript/src/DataBlocks2D.h
ViewVC logotype

Contents of /trunk/escript/src/DataBlocks2D.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (show annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 7 months ago) by trankine
File MIME type: text/plain
File size: 8830 byte(s)
And get the *(&(*&(* name right
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #if !defined escript_DataBlocks2D_20040405_H
17 #define escript_DataBlocks2D_20040405_H
18 #include "system_dep.h"
19
20 #include "DataVector.h"
21
22 #include <sstream>
23 #include <iostream>
24
25 namespace escript {
26
27 /**
28 \brief
29 DataBlocks2D manages a 2D array of multi-dimensional data points.
30
31 Description:
32 This class is used to manage the data held by instances of
33 the DataExpanded class.
34 */
35
36 class DataBlocks2D {
37
38 public:
39
40 //
41 // The type of the underlying data array under management.
42 // The multi-dimensional data points are flattened and stored
43 // serially as a vector of doubles.
44 typedef DataVector ValueType;
45
46 /**
47 \brief
48 Default constructor for DataBlocks2D.
49
50 Description:
51 Default constructor for DataBlocks2D.
52 Creates an empty DataBlocks2D object.
53 */
54 ESCRIPT_DLL_API
55 DataBlocks2D();
56
57 /**
58 \brief
59 Copy constructor for DataBlocks2D.
60
61 Description:
62 Copy constructor for DataBlocks2D.
63 */
64 ESCRIPT_DLL_API
65 DataBlocks2D(const DataBlocks2D& other);
66
67 /**
68 \brief
69 Constructor for DataBlocks2D.
70
71 Description:
72 Constructor for DataBlocks2D.
73
74 \param numRows - Input - Number of rows(samples).
75 \param numCols - Input - Number of columns(data-points per sample).
76 \param blockSize - Input - Number of elements per block(per data-point).
77
78 All parameters must be >0, else an exception will be thrown.
79 */
80 ESCRIPT_DLL_API
81 DataBlocks2D(int numRows, int numCols, int blockSize);
82
83 /**
84 \brief
85 Default destructor for DataBlocks2D.
86
87 Description:
88 Default destructor for DataBlocks2D.
89 */
90 ESCRIPT_DLL_API
91 ~DataBlocks2D();
92
93 /**
94 \brief
95 Return the size of the underlying data array.
96 ie: Number of rows * Number of columns * Number of elements per data point.
97 */
98 ESCRIPT_DLL_API
99 inline
100 ValueType::size_type
101 size() const;
102
103 /**
104 \brief
105 Return the number of rows in this DataBlocks2D array.
106 */
107 ESCRIPT_DLL_API
108 inline
109 ValueType::size_type
110 getNumRows() const;
111
112 /**
113 \brief
114 Return the number of columns in this DataBlocks2D array.
115 */
116 ESCRIPT_DLL_API
117 inline
118 ValueType::size_type
119 getNumCols() const;
120
121 /**
122 \brief
123 Return the data point size for this DataBlocks2D array.
124 */
125 ESCRIPT_DLL_API
126 inline
127 ValueType::size_type
128 getBlockSize() const;
129
130 /**
131 \brief
132 Resize the underlying data array. All current data is lost.
133 The new data elements are initialised to 0.
134
135 \param numRows - Input - Number of rows.
136 \param numCols - Input - Number of columns.
137 \param blockSize - Input - Number of elements per block.
138
139 All parameters must be >0, else an exception will be thrown.
140 */
141 ESCRIPT_DLL_API
142 void
143 resize(int numRows, int numCols, int blockSize);
144
145 /**
146 \brief
147 DataBlocks2D assignment operator =
148 Assign the given DataBlocks2D object to this one.
149 */
150 ESCRIPT_DLL_API
151 DataBlocks2D&
152 operator=(const DataBlocks2D& other);
153
154 /**
155 \brief
156 Swap all the values managed by the given DataBlocks2D objects.
157 */
158 ESCRIPT_DLL_API
159 void
160 Swap(DataBlocks2D& other);
161
162 /**
163 \brief
164 Return the 1 dimensional index of the first element for data-point (i,j)
165 within the underlying data array.
166 Provides an index for accessing this data value via the [] operator.
167 Subsequent elements of this data point can be accessed by manually
168 incrementing the returned index value.
169 */
170 ESCRIPT_DLL_API
171 inline
172 ValueType::size_type
173 index(int row, int col) const;
174
175 /**
176 \brief
177 Return a reference to the first element for the data-point with index i
178 within the underlying data array as determined by the index(i,j) method.
179 */
180 ESCRIPT_DLL_API
181 inline
182 ValueType::reference
183 operator[](ValueType::size_type i);
184
185 ESCRIPT_DLL_API
186 inline
187 ValueType::const_reference
188 operator[](ValueType::size_type i) const;
189
190 /**
191 \brief
192 Return a reference to the first element for the data-point (i,j).
193 */
194 ESCRIPT_DLL_API
195 inline
196 ValueType::reference
197 operator()(int row, int col);
198
199 ESCRIPT_DLL_API
200 inline
201 ValueType::const_reference
202 operator()(int row, int col) const;
203
204 /**
205 \brief
206 Return a reference to the underlying data array.
207 Data returned is an array type object that can be indexed via indexes generated
208 by DataBlocks2D::index.
209 */
210 ESCRIPT_DLL_API
211 inline
212 ValueType&
213 getData();
214
215 ESCRIPT_DLL_API
216 inline
217 const ValueType&
218 getData() const;
219
220 /**
221 \brief
222 Archive the data managed by this DataBlocks2D to the file referenced
223 by ofstream. A count of the number of values expected to be written
224 is provided as a cross-check.
225
226 The return value indicates success (0) or otherwise (1).
227 */
228 ESCRIPT_DLL_API
229 int
230 archiveData(std::ofstream& archiveFile,
231 const ValueType::size_type noValues) const;
232
233 /**
234 \brief
235 Extract the number of values specified by noValues from the file
236 referenced by ifstream to this DataBlocks2D.
237
238 The return value indicates success (0) or otherwise (1).
239 */
240 ESCRIPT_DLL_API
241 int
242 extractData(std::ifstream& archiveFile,
243 const ValueType::size_type noValues);
244
245 protected:
246
247 private:
248
249 //
250 // The underlying array of data values.
251 // The two dimensional array of multi-dimensional data points is flattened
252 // and serialised within this one dimensional array of doubles.
253 ValueType m_data;
254
255 //
256 // The dimensions of the 2D array of data points.
257 ValueType::size_type m_numRows;
258 ValueType::size_type m_numCols;
259
260 //
261 // The number of values per data point.
262 ValueType::size_type m_blockSize;
263
264 };
265
266 inline
267 DataBlocks2D::ValueType::size_type
268 DataBlocks2D::size() const
269 {
270 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
271 return m_data.size();
272 }
273
274 inline
275 DataBlocks2D::ValueType::size_type
276 DataBlocks2D::getNumRows() const
277 {
278 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
279 return m_numRows;
280 }
281
282 inline
283 DataBlocks2D::ValueType::size_type
284 DataBlocks2D::getNumCols() const
285 {
286 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
287 return m_numCols;
288 }
289
290 inline
291 DataBlocks2D::ValueType::size_type
292 DataBlocks2D::getBlockSize() const
293 {
294 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
295 return m_blockSize;
296 }
297
298 inline
299 DataBlocks2D::ValueType::size_type
300 DataBlocks2D::index(int row, int col) const
301 {
302 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
303 EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range.");
304 ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;
305 EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");
306 return (temp);
307 }
308
309 inline
310 DataBlocks2D::ValueType::reference
311 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)
312 {
313 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
314 return m_data[i];
315 }
316
317 inline
318 DataBlocks2D::ValueType::const_reference
319 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
320 {
321 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
322 return m_data[i];
323 }
324
325 inline
326 DataBlocks2D::ValueType::reference
327 DataBlocks2D::operator()(int row, int col)
328 {
329 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
330 return m_data[index(row,col)];
331 }
332
333 inline
334 DataBlocks2D::ValueType::const_reference
335 DataBlocks2D::operator()(int row, int col) const
336 {
337 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
338 return m_data[index(row,col)];
339 }
340
341 inline
342 DataBlocks2D::ValueType&
343 DataBlocks2D::getData()
344 {
345 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
346 return m_data;
347 }
348
349 inline
350 const DataBlocks2D::ValueType&
351 DataBlocks2D::getData() const
352 {
353 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
354 return m_data;
355 }
356
357 } // end of namespace
358
359 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26