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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (show annotations)
Mon Jun 26 13:12:56 2006 UTC (13 years, 2 months ago) by woo409
File MIME type: text/plain
File size: 8956 byte(s)
+ Merge of intelc_win32 branch (revision 741:755) with trunk. Tested on iVEC altix (run_tests and py_tests all pass)

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26