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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1796 - (show annotations)
Wed Sep 17 01:45:46 2008 UTC (10 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 8122 byte(s)
Merged noarrayview branch onto trunk.


1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #if !defined escript_DataBlocks2D_20040405_H
17 #define escript_DataBlocks2D_20040405_H
18 #include "system_dep.h"
19
20 #include "DataVector.h"
21
22 #include <sstream>
23 #include <iostream>
24
25 namespace escript {
26
27 /**
28 \brief
29 DataBlocks2D manages a 2D array of multi-dimensional data points.
30
31 Description:
32 This class is used to manage the data held by instances of
33 the DataExpanded class.
34 */
35
36 class DataBlocks2D {
37
38 public:
39
40 //
41 // The type of the underlying data array under management.
42 // The multi-dimensional data points are flattened and stored
43 // serially as a vector of doubles.
44 typedef DataVector ValueType;
45
46 /**
47 \brief
48 Default constructor for DataBlocks2D.
49
50 Description:
51 Default constructor for DataBlocks2D.
52 Creates an empty DataBlocks2D object.
53 */
54 ESCRIPT_DLL_API
55 DataBlocks2D();
56
57 /**
58 \brief
59 Copy constructor for DataBlocks2D.
60
61 Description:
62 Copy constructor for DataBlocks2D.
63 */
64 ESCRIPT_DLL_API
65 DataBlocks2D(const DataBlocks2D& other);
66
67 /**
68 \brief
69 Constructor for DataBlocks2D.
70
71 Description:
72 Constructor for DataBlocks2D.
73
74 \param numRows - Input - Number of rows(samples).
75 \param numCols - Input - Number of columns(data-points per sample).
76 \param blockSize - Input - Number of elements per block(per data-point).
77
78 All parameters must be >0, else an exception will be thrown.
79 */
80 ESCRIPT_DLL_API
81 DataBlocks2D(int numRows, int numCols, int blockSize);
82
83 /**
84 \brief
85 Default destructor for DataBlocks2D.
86
87 Description:
88 Default destructor for DataBlocks2D.
89 */
90 ESCRIPT_DLL_API
91 ~DataBlocks2D();
92
93 /**
94 \brief
95 Return the size of the underlying data array.
96 ie: Number of rows * Number of columns * Number of elements per data point.
97 */
98 ESCRIPT_DLL_API
99 inline
100 ValueType::size_type
101 size() const;
102
103 /**
104 \brief
105 Return the number of rows in this DataBlocks2D array.
106 */
107 ESCRIPT_DLL_API
108 inline
109 ValueType::size_type
110 getNumRows() const;
111
112 /**
113 \brief
114 Return the number of columns in this DataBlocks2D array.
115 */
116 ESCRIPT_DLL_API
117 inline
118 ValueType::size_type
119 getNumCols() const;
120
121 /**
122 \brief
123 Return the data point size for this DataBlocks2D array.
124 */
125 ESCRIPT_DLL_API
126 inline
127 ValueType::size_type
128 getBlockSize() const;
129
130 /**
131 \brief
132 Resize the underlying data array. All current data is lost.
133 The new data elements are initialised to 0.
134
135 \param numRows - Input - Number of rows.
136 \param numCols - Input - Number of columns.
137 \param blockSize - Input - Number of elements per block.
138
139 All parameters must be >0, else an exception will be thrown.
140 */
141 ESCRIPT_DLL_API
142 void
143 resize(int numRows, int numCols, int blockSize);
144
145 /**
146 \brief
147 DataBlocks2D assignment operator =
148 Assign the given DataBlocks2D object to this one.
149 */
150 ESCRIPT_DLL_API
151 DataBlocks2D&
152 operator=(const DataBlocks2D& other);
153
154 /**
155 \brief
156 Swap all the values managed by the given DataBlocks2D objects.
157 */
158 ESCRIPT_DLL_API
159 void
160 Swap(DataBlocks2D& other);
161
162 /**
163 \brief
164 Return the 1 dimensional index of the first element for data-point (i,j)
165 within the underlying data array.
166 Provides an index for accessing this data value via the [] operator.
167 Subsequent elements of this data point can be accessed by manually
168 incrementing the returned index value.
169 */
170 ESCRIPT_DLL_API
171 inline
172 ValueType::size_type
173 index(int row, int col) const;
174
175 /**
176 \brief
177 Return a reference to the first element for the data-point with index i
178 within the underlying data array as determined by the index(i,j) method.
179 */
180 ESCRIPT_DLL_API
181 inline
182 ValueType::reference
183 operator[](ValueType::size_type i);
184
185 ESCRIPT_DLL_API
186 inline
187 ValueType::const_reference
188 operator[](ValueType::size_type i) const;
189
190 /**
191 \brief
192 Return a reference to the first element for the data-point (i,j).
193 */
194 ESCRIPT_DLL_API
195 inline
196 ValueType::reference
197 operator()(int row, int col);
198
199 ESCRIPT_DLL_API
200 inline
201 ValueType::const_reference
202 operator()(int row, int col) const;
203
204 /**
205 \brief
206 Return a reference to the underlying data array.
207 Data returned is an array type object that can be indexed via indexes generated
208 by DataBlocks2D::index.
209 */
210 ESCRIPT_DLL_API
211 inline
212 ValueType&
213 getData();
214
215 ESCRIPT_DLL_API
216 inline
217 const ValueType&
218 getData() const;
219
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