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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 3 months ago) by ksteube
File MIME type: text/plain
File size: 5974 byte(s)
Copyright updated in all files

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26