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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 478 - (show annotations)
Tue Jan 31 02:21:49 2006 UTC (13 years, 6 months ago) by jgs
File MIME type: text/plain
File size: 8894 byte(s)
rationalise #includes

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26