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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26