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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (hide annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 7 months ago) by elspeth
File MIME type: text/plain
File size: 8572 byte(s)
More copyright information.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26