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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26