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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (hide annotations)
Mon Jan 30 04:23:44 2006 UTC (13 years, 8 months ago) by jgs
File MIME type: text/plain
File size: 9007 byte(s)
restructure escript source tree
move src/Data/* -> src
remove inc
modify #includes and cpppath settings accordingly

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26