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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1796 - (show annotations)
Wed Sep 17 01:45:46 2008 UTC (10 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 6009 byte(s)
Merged noarrayview branch onto trunk.


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