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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (hide annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 11 months ago) by trankine
File MIME type: text/plain
File size: 6406 byte(s)
And get the *(&(*&(* name right
1 jgs 121
2 ksteube 1312 /* $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 jgs 117 #if !defined escript_DataVector_20050324_H
17     #define escript_DataVector_20050324_H
18 woo409 757 #include "system_dep.h"
19 jgs 117
20 robwdcock 682 #include "esysUtils/EsysAssert.h"
21 jgs 474
22 jgs 117 #include <vector>
23 jgs 474 #include <iostream>
24     #include <fstream>
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     \brief
126     Return the number of elements in this DataVector.
127     */
128     inline
129 jgs 121 size_type
130 jgs 117 size() const;
131    
132     /**
133     \brief
134     DataVector assignment operator "=".
135     Assign the given DataVector object to this.
136     */
137     DataVector&
138     operator=(const DataVector& other);
139    
140     /**
141     \brief
142     DataVector equality comparison operator "==".
143     Return true if the given DataVector is equal to this.
144     */
145     bool
146 jgs 121 operator==(const DataVector& other) const;
147 jgs 117
148     /**
149     \brief
150     DataVector inequality comparison operator "!=".
151     Return true if the given DataVector is not equal to this.
152     */
153     bool
154 jgs 121 operator!=(const DataVector& other) const;
155 jgs 117
156     /**
157     \brief
158     Return a reference to the element at position i in this DataVector.
159     Will throw an exception if an invalid index "i" is given.
160    
161     NB: access to the element one past the end of the vector is permitted
162     in order to provide a facility equivalent to an end() pointer.
163     */
164     inline
165 jgs 121 reference
166     operator[](const size_type i);
167 jgs 117
168     inline
169 jgs 121 const_reference
170     operator[](const size_type i) const;
171 jgs 117
172 jgs 123 /**
173     \brief
174     Archive the data managed by this DataVector to the file referenced
175     by ofstream. A count of the number of values expected to be written
176     is provided as a cross-check.
177    
178 bcumming 751
179 jgs 123 The return value indicates success (0) or otherwise (1).
180     */
181     int
182     archiveData(std::ofstream& archiveFile,
183     const size_type noValues) const;
184    
185     /**
186     \brief
187     Extract the number of values specified by noValues from the file
188     referenced by ifstream to this DataVector.
189    
190     The return value indicates success (0) or otherwise (1).
191     */
192     int
193     extractData(std::ifstream& archiveFile,
194     const size_type noValues);
195    
196 jgs 117 protected:
197    
198     private:
199    
200 jgs 121 size_type m_size;
201     size_type m_dim;
202     size_type m_N;
203    
204 jgs 117 //
205     // The container for the elements contained in this DataVector.
206 jgs 121 ValueType m_array_data;
207 jgs 117 };
208    
209 gross 797 /**
210     \brief
211     releases unused memory in the memory manager.
212     */
213    
214     ESCRIPT_DLL_API void releaseUnusedMemory();
215    
216    
217    
218 jgs 117 inline
219 jgs 121 DataVector::size_type
220 jgs 117 DataVector::size() const
221     {
222 jgs 121 return m_size;
223 jgs 117 }
224    
225     inline
226 jgs 121 DataVector::reference
227     DataVector::operator[](const DataVector::size_type i)
228 jgs 117 {
229 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
230     return m_array_data[i];
231 jgs 117 }
232    
233     inline
234 jgs 121 DataVector::const_reference
235     DataVector::operator[](const DataVector::size_type i) const
236 jgs 117 {
237 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
238     return m_array_data[i];
239 jgs 117 }
240    
241     } // end of namespace
242    
243     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26