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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (show 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 /*
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 "Taipan.h"
21 #include "DataException.h"
22
23 #include <vector>
24 #include <iostream>
25 #include <fstream>
26 #include <cassert>
27
28 namespace escript {
29
30 /**
31 \brief
32 DataVector implements an arbitrarily long vector of data values.
33 DataVector is the underlying data container for Data objects.
34
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 client classes.
40 */
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 typedef ElementType * ValueType;
53
54 //
55 // 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
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 initilised to "val".
87
88 \param size - Input - Number of elements in the vector.
89 \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
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 */
98 DataVector(const size_type size,
99 const value_type val=0.0,
100 const size_type blockSize=1);
101
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 initialised to "newVal".
116
117 \param newSize - Input - New size for the vector.
118 \param newVal - Input - New initial value for all elements in the vector.
119 \param newBlockSize - Input - New block size for the vector.
120 */
121 void
122 resize(const size_type newSize,
123 const value_type newVal=0.0,
124 const size_type newBlockSize=1);
125
126 /**
127 \brief
128 Return the number of elements in this DataVector.
129 */
130 inline
131 size_type
132 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 operator==(const DataVector& other) const;
149
150 /**
151 \brief
152 DataVector inequality comparison operator "!=".
153 Return true if the given DataVector is not equal to this.
154 */
155 bool
156 operator!=(const DataVector& other) const;
157
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 reference
168 operator[](const size_type i);
169
170 inline
171 const_reference
172 operator[](const size_type i) const;
173
174 /**
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 protected:
198
199 private:
200
201 size_type m_size;
202 size_type m_dim;
203 size_type m_N;
204
205 //
206 // The container for the elements contained in this DataVector.
207 ValueType m_array_data;
208 };
209
210 inline
211 DataVector::size_type
212 DataVector::size() const
213 {
214 return m_size;
215 }
216
217 inline
218 DataVector::reference
219 DataVector::operator[](const DataVector::size_type i)
220 {
221 EsysAssert(i<size(),"DataVector: invalid index specified.");
222 return m_array_data[i];
223 }
224
225 inline
226 DataVector::const_reference
227 DataVector::operator[](const DataVector::size_type i) const
228 {
229 EsysAssert(i<size(),"DataVector: invalid index specified.");
230 return m_array_data[i];
231 }
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