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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 477 - (hide annotations)
Mon Jan 30 07:20:20 2006 UTC (17 years ago) by jgs
File MIME type: text/plain
File size: 6295 byte(s)
rationalise #includes

1 jgs 117 /*
2     ******************************************************************************
3     * *
4     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
5     * *
6     * This software is the property of ACcESS. No part of this code *
7     * may be copied in any form or by any means without the expressed written *
8     * consent of ACcESS. Copying, use or modification of this software *
9     * by any unauthorised person is illegal unless that person has a software *
10     * license agreement with ACcESS. *
11     * *
12     ******************************************************************************
13     */
14 jgs 121
15 jgs 117 #if !defined escript_DataVector_20050324_H
16     #define escript_DataVector_20050324_H
17    
18 jgs 474 #include "EsysAssert.h"
19    
20 jgs 117 #include <vector>
21 jgs 474 #include <iostream>
22     #include <fstream>
23 jgs 117
24     namespace escript {
25    
26     /**
27     \brief
28     DataVector implements an arbitrarily long vector of data values.
29 jgs 121 DataVector is the underlying data container for Data objects.
30 jgs 117
31     Description:
32     DataVector provides an implementation of a vector of data values for use
33     by DataBlocks2D and DataArrayView. Hiding the vector in this container
34     allows different implementations to be swapped in without disrupting the
35 jgs 121 client classes.
36 jgs 117 */
37    
38     class DataVector {
39    
40     public:
41    
42     //
43     // The type of the elements stored in the vector.
44     typedef double ElementType;
45    
46     //
47     // The underlying type used to implement the vector.
48 jgs 121 typedef ElementType * ValueType;
49 jgs 117
50     //
51 jgs 121 // Various types exported to clients of this class.
52     typedef ElementType value_type;
53     typedef long size_type;
54     typedef ElementType & reference;
55     typedef const ElementType & const_reference;
56 jgs 117
57     /**
58     \brief
59     Default constructor for DataVector.
60    
61     Description:
62     Constructs an empty DataVector object.
63     */
64     DataVector();
65    
66     /**
67     \brief
68     Copy constructor for DataVector.
69    
70     Description:
71     Constructs a DataVector object which is a copy of the
72     given DataVector object.
73     */
74     DataVector(const DataVector& other);
75    
76     /**
77     \brief
78     Constructor for DataVector.
79    
80     Description:
81     Constructs a DataVector object of length "size" with all elements
82 jgs 121 initilised to "val".
83 jgs 117
84     \param size - Input - Number of elements in the vector.
85 jgs 121 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
86     \param blockSize - Input - size of blocks within the vector, overall vector
87     size must be a precise multiple of the block size. Default is 1.
88 jgs 151
89     In escript::Data, blocksize corresponds to the number of elements required to hold all
90     the data-points for a sample, ie: the product of the dimensions of a data-point and the
91     number of data-points per sample. Size is the total number of elements required to hold
92     all elements for all data-points in the given object, ie: number of samples * blocksize.
93 jgs 117 */
94 jgs 121 DataVector(const size_type size,
95     const value_type val=0.0,
96     const size_type blockSize=1);
97 jgs 117
98     /**
99     \brief
100     Default destructor for DataVector.
101    
102     Description:
103     Destroys the current DataVector object.
104     */
105     ~DataVector();
106    
107     /**
108     \brief
109     Resize the DataVector to the given length "newSize".
110     All current data is lost. All elements in the new DataVector are
111 jgs 121 initialised to "newVal".
112 jgs 117
113     \param newSize - Input - New size for the vector.
114 jgs 121 \param newVal - Input - New initial value for all elements in the vector.
115     \param newBlockSize - Input - New block size for the vector.
116 jgs 117 */
117     void
118 jgs 121 resize(const size_type newSize,
119     const value_type newVal=0.0,
120     const size_type newBlockSize=1);
121 jgs 117
122     /**
123     \brief
124     Return the number of elements in this DataVector.
125     */
126     inline
127 jgs 121 size_type
128 jgs 117 size() const;
129    
130     /**
131     \brief
132     DataVector assignment operator "=".
133     Assign the given DataVector object to this.
134     */
135     DataVector&
136     operator=(const DataVector& other);
137    
138     /**
139     \brief
140     DataVector equality comparison operator "==".
141     Return true if the given DataVector is equal to this.
142     */
143     bool
144 jgs 121 operator==(const DataVector& other) const;
145 jgs 117
146     /**
147     \brief
148     DataVector inequality comparison operator "!=".
149     Return true if the given DataVector is not equal to this.
150     */
151     bool
152 jgs 121 operator!=(const DataVector& other) const;
153 jgs 117
154     /**
155     \brief
156     Return a reference to the element at position i in this DataVector.
157     Will throw an exception if an invalid index "i" is given.
158    
159     NB: access to the element one past the end of the vector is permitted
160     in order to provide a facility equivalent to an end() pointer.
161     */
162     inline
163 jgs 121 reference
164     operator[](const size_type i);
165 jgs 117
166     inline
167 jgs 121 const_reference
168     operator[](const size_type i) const;
169 jgs 117
170 jgs 123 /**
171     \brief
172     Archive the data managed by this DataVector to the file referenced
173     by ofstream. A count of the number of values expected to be written
174     is provided as a cross-check.
175    
176     The return value indicates success (0) or otherwise (1).
177     */
178     int
179     archiveData(std::ofstream& archiveFile,
180     const size_type noValues) const;
181    
182     /**
183     \brief
184     Extract the number of values specified by noValues from the file
185     referenced by ifstream to this DataVector.
186    
187     The return value indicates success (0) or otherwise (1).
188     */
189     int
190     extractData(std::ifstream& archiveFile,
191     const size_type noValues);
192    
193 jgs 117 protected:
194    
195     private:
196    
197 jgs 121 size_type m_size;
198     size_type m_dim;
199     size_type m_N;
200    
201 jgs 117 //
202     // The container for the elements contained in this DataVector.
203 jgs 121 ValueType m_array_data;
204 jgs 117 };
205    
206     inline
207 jgs 121 DataVector::size_type
208 jgs 117 DataVector::size() const
209     {
210 jgs 121 return m_size;
211 jgs 117 }
212    
213     inline
214 jgs 121 DataVector::reference
215     DataVector::operator[](const DataVector::size_type i)
216 jgs 117 {
217 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
218     return m_array_data[i];
219 jgs 117 }
220    
221     inline
222 jgs 121 DataVector::const_reference
223     DataVector::operator[](const DataVector::size_type i) const
224 jgs 117 {
225 jgs 121 EsysAssert(i<size(),"DataVector: invalid index specified.");
226     return m_array_data[i];
227 jgs 117 }
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