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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3911 - (show annotations)
Thu Jun 14 01:01:03 2012 UTC (7 years, 5 months ago) by jfenwick
File MIME type: text/plain
File size: 6254 byte(s)
Copyright changes
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2012 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
25 namespace escript {
26
27 class WrappedArray;
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 typedef const ElementType * ConstValueType;
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 Populates the vector with the data from value.
129 This method currently throws an exception if the specified number of copies won't fit.
130 \warning This function does not attempt to perform shape checking.
131 */
132 void
133 copyFromArray(const escript::WrappedArray& value, size_type copies);
134
135 void
136 copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
137
138
139 /**
140 \brief
141 Return the number of elements in this DataVector.
142 */
143 inline
144 size_type
145 size() const;
146
147 /**
148 \brief
149 DataVector assignment operator "=".
150 Assign the given DataVector object to this.
151 */
152 DataVector&
153 operator=(const DataVector& other);
154
155 /**
156 \brief
157 DataVector equality comparison operator "==".
158 Return true if the given DataVector is equal to this.
159 */
160 bool
161 operator==(const DataVector& other) const;
162
163 /**
164 \brief
165 DataVector inequality comparison operator "!=".
166 Return true if the given DataVector is not equal to this.
167 */
168 bool
169 operator!=(const DataVector& other) const;
170
171 /**
172 \brief
173 Return a reference to the element at position i in this DataVector.
174 Will throw an exception if an invalid index "i" is given.
175
176 NB: access to the element one past the end of the vector is permitted
177 in order to provide a facility equivalent to an end() pointer.
178 */
179 inline
180 reference
181 operator[](const size_type i);
182
183 inline
184 const_reference
185 operator[](const size_type i) const;
186
187
188 protected:
189
190 private:
191
192 size_type m_size;
193 size_type m_dim;
194 size_type m_N;
195
196 //
197 // The container for the elements contained in this DataVector.
198 ValueType m_array_data;
199 };
200
201 /**
202 \brief
203 releases unused memory in the memory manager.
204 */
205
206 ESCRIPT_DLL_API void releaseUnusedMemory();
207
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. " << i << " of " << size());
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. " << i << " of " << size());
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