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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 jgs 117
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 117 #if !defined escript_DataBlocks2D_20040405_H
16 jgs 82 #define escript_DataBlocks2D_20040405_H
17 woo409 757 #include "system_dep.h"
18 jgs 82
19 jgs 474 #include "DataVector.h"
20 jgs 82
21 jgs 474 #include <sstream>
22     #include <iostream>
23    
24 jgs 82 namespace escript {
25    
26     /**
27     \brief
28 jgs 117 DataBlocks2D manages a 2D array of multi-dimensional data points.
29 jgs 82
30     Description:
31 jgs 117 This class is used to manage the data held by instances of
32     the DataExpanded class.
33 jgs 82 */
34    
35     class DataBlocks2D {
36    
37     public:
38    
39 jgs 117 //
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 jgs 82
45     /**
46     \brief
47 jgs 117 Default constructor for DataBlocks2D.
48 jgs 82
49     Description:
50 jgs 117 Default constructor for DataBlocks2D.
51 jgs 151 Creates an empty DataBlocks2D object.
52 jgs 82 */
53 woo409 757 ESCRIPT_DLL_API
54 jgs 82 DataBlocks2D();
55    
56     /**
57     \brief
58 jgs 117 Copy constructor for DataBlocks2D.
59 jgs 82
60     Description:
61 jgs 117 Copy constructor for DataBlocks2D.
62 jgs 82 */
63 woo409 757 ESCRIPT_DLL_API
64 jgs 82 DataBlocks2D(const DataBlocks2D& other);
65    
66     /**
67     \brief
68 jgs 117 Constructor for DataBlocks2D.
69 jgs 82
70     Description:
71 jgs 117 Constructor for DataBlocks2D.
72    
73 jgs 151 \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 jgs 82 */
79 woo409 757 ESCRIPT_DLL_API
80 jgs 82 DataBlocks2D(int numRows, int numCols, int blockSize);
81    
82     /**
83     \brief
84 jgs 117 Default destructor for DataBlocks2D.
85 jgs 82
86     Description:
87 jgs 117 Default destructor for DataBlocks2D.
88 jgs 82 */
89 woo409 757 ESCRIPT_DLL_API
90 jgs 82 ~DataBlocks2D();
91    
92     /**
93     \brief
94 jgs 117 Return the size of the underlying data array.
95     ie: Number of rows * Number of columns * Number of elements per data point.
96 jgs 82 */
97 woo409 757 ESCRIPT_DLL_API
98 jgs 117 inline
99     ValueType::size_type
100     size() const;
101 jgs 82
102     /**
103 jgs 117 \brief
104     Return the number of rows in this DataBlocks2D array.
105 jgs 82 */
106 woo409 757 ESCRIPT_DLL_API
107 jgs 117 inline
108     ValueType::size_type
109     getNumRows() const;
110 jgs 82
111     /**
112     \brief
113 jgs 117 Return the number of columns in this DataBlocks2D array.
114 jgs 82 */
115 woo409 757 ESCRIPT_DLL_API
116 jgs 117 inline
117     ValueType::size_type
118     getNumCols() const;
119 jgs 82
120     /**
121     \brief
122 jgs 117 Return the data point size for this DataBlocks2D array.
123 jgs 82 */
124 woo409 757 ESCRIPT_DLL_API
125 jgs 117 inline
126     ValueType::size_type
127     getBlockSize() const;
128 jgs 82
129     /**
130     \brief
131 jgs 117 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 jgs 151
138     All parameters must be >0, else an exception will be thrown.
139 jgs 82 */
140 woo409 757 ESCRIPT_DLL_API
141 jgs 117 void
142     resize(int numRows, int numCols, int blockSize);
143 jgs 82
144     /**
145     \brief
146 jgs 117 DataBlocks2D assignment operator =
147     Assign the given DataBlocks2D object to this one.
148 jgs 82 */
149 woo409 757 ESCRIPT_DLL_API
150 jgs 117 DataBlocks2D&
151     operator=(const DataBlocks2D& other);
152 jgs 82
153     /**
154     \brief
155 jgs 117 Swap all the values managed by the given DataBlocks2D objects.
156 jgs 82 */
157 woo409 757 ESCRIPT_DLL_API
158 jgs 117 void
159     Swap(DataBlocks2D& other);
160 jgs 82
161     /**
162 jgs 117 \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 woo409 757 ESCRIPT_DLL_API
170 jgs 117 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 woo409 757 ESCRIPT_DLL_API
180 jgs 117 inline
181     ValueType::reference
182     operator[](ValueType::size_type i);
183    
184 woo409 757 ESCRIPT_DLL_API
185 jgs 117 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 woo409 757 ESCRIPT_DLL_API
194 jgs 117 inline
195     ValueType::reference
196     operator()(int row, int col);
197    
198 woo409 757 ESCRIPT_DLL_API
199 jgs 117 inline
200     ValueType::const_reference
201     operator()(int row, int col) const;
202    
203     /**
204 jgs 82 \brief
205 jgs 119 Return a reference to the underlying data array.
206 jgs 117 Data returned is an array type object that can be indexed via indexes generated
207     by DataBlocks2D::index.
208 jgs 82 */
209 woo409 757 ESCRIPT_DLL_API
210 jgs 117 inline
211     ValueType&
212     getData();
213 jgs 82
214 woo409 757 ESCRIPT_DLL_API
215 jgs 117 inline
216 jgs 151 const ValueType&
217 jgs 117 getData() const;
218    
219 jgs 123
220 jgs 82 protected:
221    
222     private:
223    
224     //
225 jgs 117 // 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 jgs 82 ValueType m_data;
229    
230     //
231 jgs 117 // The dimensions of the 2D array of data points.
232     ValueType::size_type m_numRows;
233     ValueType::size_type m_numCols;
234 jgs 82
235 jgs 151 //
236     // The number of values per data point.
237     ValueType::size_type m_blockSize;
238    
239 jgs 82 };
240    
241 jgs 117 inline
242     DataBlocks2D::ValueType::size_type
243     DataBlocks2D::size() const
244 jgs 82 {
245 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
246     return m_data.size();
247 jgs 117 }
248    
249     inline
250     DataBlocks2D::ValueType::size_type
251     DataBlocks2D::getNumRows() const
252     {
253 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
254     return m_numRows;
255 jgs 82 }
256    
257 jgs 117 inline
258     DataBlocks2D::ValueType::size_type
259     DataBlocks2D::getNumCols() const
260 jgs 82 {
261 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
262     return m_numCols;
263 jgs 82 }
264    
265 jgs 117 inline
266     DataBlocks2D::ValueType::size_type
267     DataBlocks2D::getBlockSize() const
268     {
269 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
270     return m_blockSize;
271 jgs 117 }
272    
273     inline
274     DataBlocks2D::ValueType::size_type
275     DataBlocks2D::index(int row, int col) const
276     {
277 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
278 jgs 117 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 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
289 jgs 117 return m_data[i];
290     }
291    
292     inline
293     DataBlocks2D::ValueType::const_reference
294     DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
295     {
296 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
297 jgs 117 return m_data[i];
298     }
299    
300     inline
301     DataBlocks2D::ValueType::reference
302     DataBlocks2D::operator()(int row, int col)
303     {
304 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
305 jgs 117 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 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
313 jgs 117 return m_data[index(row,col)];
314     }
315    
316     inline
317     DataBlocks2D::ValueType&
318     DataBlocks2D::getData()
319     {
320 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
321 jgs 117 return m_data;
322     }
323    
324     inline
325     const DataBlocks2D::ValueType&
326     DataBlocks2D::getData() const
327     {
328 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
329 jgs 117 return m_data;
330     }
331    
332 jgs 82 } // end of namespace
333 jgs 117
334 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26