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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 10 months ago) by ksteube
File MIME type: text/plain
File size: 8087 byte(s)
Copyright updated in all files

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26