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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 477 - (hide annotations)
Mon Jan 30 07:20:20 2006 UTC (13 years, 9 months ago) by jgs
File MIME type: text/plain
File size: 8946 byte(s)
rationalise #includes

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26