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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 jgs 121
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 117 #if !defined escript_DataVector_20050324_H
16     #define escript_DataVector_20050324_H
17 woo409 757 #include "system_dep.h"
18 jgs 117
19 robwdcock 682 #include "esysUtils/EsysAssert.h"
20 jgs 474
21 jgs 117 #include <vector>
22 jgs 474 #include <iostream>
23     #include <fstream>
24 jfenwick 1796 #include <boost/python/numeric.hpp>
25 jgs 117
26     namespace escript {
27    
28     /**
29     \brief
30     DataVector implements an arbitrarily long vector of data values.
31 jgs 121 DataVector is the underlying data container for Data objects.
32 jgs 117
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 jgs 121 client classes.
38 jgs 117 */
39    
40 woo409 757 class ESCRIPT_DLL_API DataVector {
41 jgs 117
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 jgs 121 typedef ElementType * ValueType;
51 jgs 117
52     //
53 jgs 121 // 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 jgs 117
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 jgs 121 initilised to "val".
85 jgs 117
86     \param size - Input - Number of elements in the vector.
87 jgs 121 \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 jgs 151
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 jgs 117 */
96 jgs 121 DataVector(const size_type size,
97     const value_type val=0.0,
98     const size_type blockSize=1);
99 jgs 117
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 jgs 121 initialised to "newVal".
114 jgs 117
115     \param newSize - Input - New size for the vector.
116 jgs 121 \param newVal - Input - New initial value for all elements in the vector.
117     \param newBlockSize - Input - New block size for the vector.
118 jgs 117 */
119     void
120 jgs 121 resize(const size_type newSize,
121     const value_type newVal=0.0,
122     const size_type newBlockSize=1);
123 jgs 117
124     /**
125 jfenwick 1796 \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 jgs 117 \brief
136     Return the number of elements in this DataVector.
137     */
138     inline
139 jgs 121 size_type
140 jgs 117 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 jgs 121 operator==(const DataVector& other) const;
157 jgs 117
158     /**
159     \brief
160     DataVector inequality comparison operator "!=".
161     Return true if the given DataVector is not equal to this.
162     */
163     bool
164 jgs 121 operator!=(const DataVector& other) const;
165 jgs 117
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 jgs 121 reference
176     operator[](const size_type i);
177 jgs 117
178     inline
179 jgs 121 const_reference
180     operator[](const size_type i) const;
181 jgs 117
182 jgs 123
183 jgs 117 protected:
184    
185     private:
186    
187 jgs 121 size_type m_size;
188     size_type m_dim;
189     size_type m_N;
190    
191 jgs 117 //
192     // The container for the elements contained in this DataVector.
193 jgs 121 ValueType m_array_data;
194 jgs 117 };
195    
196 gross 797 /**
197     \brief
198     releases unused memory in the memory manager.
199     */
200    
201     ESCRIPT_DLL_API void releaseUnusedMemory();
202    
203    
204    
205 jgs 117 inline
206 jgs 121 DataVector::size_type
207 jgs 117 DataVector::size() const
208     {
209 jgs 121 return m_size;
210 jgs 117 }
211    
212     inline
213 jgs 121 DataVector::reference
214     DataVector::operator[](const DataVector::size_type i)
215 jgs 117 {
216 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
217     return m_array_data[i];
218 jgs 117 }
219    
220     inline
221 jgs 121 DataVector::const_reference
222     DataVector::operator[](const DataVector::size_type i) const
223 jgs 117 {
224 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
225     return m_array_data[i];
226 jgs 117 }
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