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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26