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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26