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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 jgs 117 /*
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 121
15 jgs 117 #if !defined escript_DataVector_20050324_H
16     #define escript_DataVector_20050324_H
17    
18 jgs 474 #include "EsysAssert.h"
19    
20     #include "Taipan.h"
21     #include "DataException.h"
22    
23 jgs 117 #include <vector>
24 jgs 474 #include <iostream>
25     #include <fstream>
26     #include <cassert>
27 jgs 117
28     namespace escript {
29    
30     /**
31     \brief
32     DataVector implements an arbitrarily long vector of data values.
33 jgs 121 DataVector is the underlying data container for Data objects.
34 jgs 117
35     Description:
36     DataVector provides an implementation of a vector of data values for use
37     by DataBlocks2D and DataArrayView. Hiding the vector in this container
38     allows different implementations to be swapped in without disrupting the
39 jgs 121 client classes.
40 jgs 117 */
41    
42     class DataVector {
43    
44     public:
45    
46     //
47     // The type of the elements stored in the vector.
48     typedef double ElementType;
49    
50     //
51     // The underlying type used to implement the vector.
52 jgs 121 typedef ElementType * ValueType;
53 jgs 117
54     //
55 jgs 121 // Various types exported to clients of this class.
56     typedef ElementType value_type;
57     typedef long size_type;
58     typedef ElementType & reference;
59     typedef const ElementType & const_reference;
60 jgs 117
61     /**
62     \brief
63     Default constructor for DataVector.
64    
65     Description:
66     Constructs an empty DataVector object.
67     */
68     DataVector();
69    
70     /**
71     \brief
72     Copy constructor for DataVector.
73    
74     Description:
75     Constructs a DataVector object which is a copy of the
76     given DataVector object.
77     */
78     DataVector(const DataVector& other);
79    
80     /**
81     \brief
82     Constructor for DataVector.
83    
84     Description:
85     Constructs a DataVector object of length "size" with all elements
86 jgs 121 initilised to "val".
87 jgs 117
88     \param size - Input - Number of elements in the vector.
89 jgs 121 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
90     \param blockSize - Input - size of blocks within the vector, overall vector
91     size must be a precise multiple of the block size. Default is 1.
92 jgs 151
93     In escript::Data, blocksize corresponds to the number of elements required to hold all
94     the data-points for a sample, ie: the product of the dimensions of a data-point and the
95     number of data-points per sample. Size is the total number of elements required to hold
96     all elements for all data-points in the given object, ie: number of samples * blocksize.
97 jgs 117 */
98 jgs 121 DataVector(const size_type size,
99     const value_type val=0.0,
100     const size_type blockSize=1);
101 jgs 117
102     /**
103     \brief
104     Default destructor for DataVector.
105    
106     Description:
107     Destroys the current DataVector object.
108     */
109     ~DataVector();
110    
111     /**
112     \brief
113     Resize the DataVector to the given length "newSize".
114     All current data is lost. All elements in the new DataVector are
115 jgs 121 initialised to "newVal".
116 jgs 117
117     \param newSize - Input - New size for the vector.
118 jgs 121 \param newVal - Input - New initial value for all elements in the vector.
119     \param newBlockSize - Input - New block size for the vector.
120 jgs 117 */
121     void
122 jgs 121 resize(const size_type newSize,
123     const value_type newVal=0.0,
124     const size_type newBlockSize=1);
125 jgs 117
126     /**
127     \brief
128     Return the number of elements in this DataVector.
129     */
130     inline
131 jgs 121 size_type
132 jgs 117 size() const;
133    
134     /**
135     \brief
136     DataVector assignment operator "=".
137     Assign the given DataVector object to this.
138     */
139     DataVector&
140     operator=(const DataVector& other);
141    
142     /**
143     \brief
144     DataVector equality comparison operator "==".
145     Return true if the given DataVector is equal to this.
146     */
147     bool
148 jgs 121 operator==(const DataVector& other) const;
149 jgs 117
150     /**
151     \brief
152     DataVector inequality comparison operator "!=".
153     Return true if the given DataVector is not equal to this.
154     */
155     bool
156 jgs 121 operator!=(const DataVector& other) const;
157 jgs 117
158     /**
159     \brief
160     Return a reference to the element at position i in this DataVector.
161     Will throw an exception if an invalid index "i" is given.
162    
163     NB: access to the element one past the end of the vector is permitted
164     in order to provide a facility equivalent to an end() pointer.
165     */
166     inline
167 jgs 121 reference
168     operator[](const size_type i);
169 jgs 117
170     inline
171 jgs 121 const_reference
172     operator[](const size_type i) const;
173 jgs 117
174 jgs 123 /**
175     \brief
176     Archive the data managed by this DataVector to the file referenced
177     by ofstream. A count of the number of values expected to be written
178     is provided as a cross-check.
179    
180     The return value indicates success (0) or otherwise (1).
181     */
182     int
183     archiveData(std::ofstream& archiveFile,
184     const size_type noValues) const;
185    
186     /**
187     \brief
188     Extract the number of values specified by noValues from the file
189     referenced by ifstream to this DataVector.
190    
191     The return value indicates success (0) or otherwise (1).
192     */
193     int
194     extractData(std::ifstream& archiveFile,
195     const size_type noValues);
196    
197 jgs 117 protected:
198    
199     private:
200    
201 jgs 121 size_type m_size;
202     size_type m_dim;
203     size_type m_N;
204    
205 jgs 117 //
206     // The container for the elements contained in this DataVector.
207 jgs 121 ValueType m_array_data;
208 jgs 117 };
209    
210     inline
211 jgs 121 DataVector::size_type
212 jgs 117 DataVector::size() const
213     {
214 jgs 121 return m_size;
215 jgs 117 }
216    
217     inline
218 jgs 121 DataVector::reference
219     DataVector::operator[](const DataVector::size_type i)
220 jgs 117 {
221 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
222     return m_array_data[i];
223 jgs 117 }
224    
225     inline
226 jgs 121 DataVector::const_reference
227     DataVector::operator[](const DataVector::size_type i) const
228 jgs 117 {
229 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
230     return m_array_data[i];
231 jgs 117 }
232    
233     } // end of namespace
234    
235     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26