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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (hide annotations)
Mon Jun 26 13:12:56 2006 UTC (13 years, 3 months ago) by woo409
File MIME type: text/plain
File size: 8956 byte(s)
+ Merge of intelc_win32 branch (revision 741:755) with trunk. Tested on iVEC altix (run_tests and py_tests all pass)

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26