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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations)
Fri May 6 04:26:16 2005 UTC (14 years, 7 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataVector.h
File MIME type: text/plain
File size: 5246 byte(s)
Merge of development branch back to main trunk on 2005-05-06

1 /*
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
15 #if !defined escript_DataVector_20050324_H
16 #define escript_DataVector_20050324_H
17
18 #include <vector>
19
20 #include "esysUtils/EsysAssert.h"
21
22 namespace escript {
23
24 /**
25 \brief
26 DataVector implements an arbitrarily long vector of data values.
27 DataVector is the underlying data container for Data objects.
28
29 Description:
30 DataVector provides an implementation of a vector of data values for use
31 by DataBlocks2D and DataArrayView. Hiding the vector in this container
32 allows different implementations to be swapped in without disrupting the
33 client classes.
34 */
35
36 class DataVector {
37
38 public:
39
40 //
41 // The type of the elements stored in the vector.
42 typedef double ElementType;
43
44 //
45 // The underlying type used to implement the vector.
46 typedef ElementType * ValueType;
47
48 //
49 // Various types exported to clients of this class.
50 typedef ElementType value_type;
51 typedef long size_type;
52 typedef ElementType & reference;
53 typedef const ElementType & const_reference;
54
55 /**
56 \brief
57 Default constructor for DataVector.
58
59 Description:
60 Constructs an empty DataVector object.
61 */
62 DataVector();
63
64 /**
65 \brief
66 Copy constructor for DataVector.
67
68 Description:
69 Constructs a DataVector object which is a copy of the
70 given DataVector object.
71 */
72 DataVector(const DataVector& other);
73
74 /**
75 \brief
76 Constructor for DataVector.
77
78 Description:
79 Constructs a DataVector object of length "size" with all elements
80 initilised to "val".
81
82 \param size - Input - Number of elements in the vector.
83 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
84 \param blockSize - Input - size of blocks within the vector, overall vector
85 size must be a precise multiple of the block size. Default is 1.
86 */
87 DataVector(const size_type size,
88 const value_type val=0.0,
89 const size_type blockSize=1);
90
91 /**
92 \brief
93 Default destructor for DataVector.
94
95 Description:
96 Destroys the current DataVector object.
97 */
98 ~DataVector();
99
100 /**
101 \brief
102 Resize the DataVector to the given length "newSize".
103 All current data is lost. All elements in the new DataVector are
104 initialised to "newVal".
105
106 \param newSize - Input - New size for the vector.
107 \param newVal - Input - New initial value for all elements in the vector.
108 \param newBlockSize - Input - New block size for the vector.
109 */
110 void
111 resize(const size_type newSize,
112 const value_type newVal=0.0,
113 const size_type newBlockSize=1);
114
115 /**
116 \brief
117 Return the number of elements in this DataVector.
118 */
119 inline
120 size_type
121 size() const;
122
123 /**
124 \brief
125 DataVector assignment operator "=".
126 Assign the given DataVector object to this.
127 */
128 DataVector&
129 operator=(const DataVector& other);
130
131 /**
132 \brief
133 DataVector equality comparison operator "==".
134 Return true if the given DataVector is equal to this.
135 */
136 bool
137 operator==(const DataVector& other) const;
138
139 /**
140 \brief
141 DataVector inequality comparison operator "!=".
142 Return true if the given DataVector is not equal to this.
143 */
144 bool
145 operator!=(const DataVector& other) const;
146
147 /**
148 \brief
149 Return a reference to the element at position i in this DataVector.
150 Will throw an exception if an invalid index "i" is given.
151
152 NB: access to the element one past the end of the vector is permitted
153 in order to provide a facility equivalent to an end() pointer.
154 */
155 inline
156 reference
157 operator[](const size_type i);
158
159 inline
160 const_reference
161 operator[](const size_type i) const;
162
163 protected:
164
165 private:
166
167 size_type m_size;
168 size_type m_dim;
169 size_type m_N;
170
171 //
172 // The container for the elements contained in this DataVector.
173 ValueType m_array_data;
174 };
175
176 inline
177 DataVector::size_type
178 DataVector::size() const
179 {
180 return m_size;
181 }
182
183 inline
184 DataVector::reference
185 DataVector::operator[](const DataVector::size_type i)
186 {
187 EsysAssert(i<size(),"DataVector: invalid index specified.");
188 return m_array_data[i];
189 }
190
191 inline
192 DataVector::const_reference
193 DataVector::operator[](const DataVector::size_type i) const
194 {
195 EsysAssert(i<size(),"DataVector: invalid index specified.");
196 return m_array_data[i];
197 }
198
199 } // end of namespace
200
201 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26