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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (show annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 10 months ago) by elspeth
File MIME type: text/plain
File size: 8572 byte(s)
More copyright information.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26