escript  Revision_
DataVector.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 #if !defined escript_DataVector_20050324_H
19 #define escript_DataVector_20050324_H
20 #include "system_dep.h"
21 
22 #include "esysUtils/EsysAssert.h"
23 
24 #include <vector>
25 #include <iostream>
26 #include <fstream>
27 
28 namespace escript {
29 
30 class WrappedArray;
31 
45 
46  public:
47 
48  //
49  // The type of the elements stored in the vector.
50  typedef double ElementType;
51 
52  //
53  // The underlying type used to implement the vector.
54  typedef ElementType * ValueType;
55  typedef const ElementType * ConstValueType;
56 
57  //
58  // Various types exported to clients of this class.
59  typedef ElementType value_type;
60  typedef long size_type;
61  typedef ElementType & reference;
62  typedef const ElementType & const_reference;
63 
71  DataVector();
72 
81  DataVector(const DataVector& other);
82 
101  DataVector(const size_type size,
102  const value_type val=0.0,
103  const size_type blockSize=1);
104 
112  ~DataVector();
113 
124  void
125  resize(const size_type newSize,
126  const value_type newVal=0.0,
127  const size_type newBlockSize=1);
128 
135  void
136  copyFromArray(const escript::WrappedArray& value, size_type copies);
137 
138  void
139  copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
140 
141 
146  inline
147  size_type
148  size() const;
149 
155  DataVector&
156  operator=(const DataVector& other);
157 
163  bool
164  operator==(const DataVector& other) const;
165 
171  bool
172  operator!=(const DataVector& other) const;
173 
182  inline
183  reference
184  operator[](const size_type i);
185 
186  inline
187  const_reference
188  operator[](const size_type i) const;
189 
190 
191  protected:
192 
193  private:
194 
195  size_type m_size;
196  size_type m_dim;
197  size_type m_N;
198 
199  //
200  // The container for the elements contained in this DataVector.
201  ValueType m_array_data;
202 };
203 
210 
211 
212 
213 inline
216 {
217  return m_size;
218 }
219 
220 inline
223 {
224  EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
225  return m_array_data[i];
226 }
227 
228 inline
231 {
232  EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
233  return m_array_data[i];
234 }
235 
236 } // end of namespace
237 
238 #endif
const ElementType * ConstValueType
Definition: DataVector.h:55
DataVector implements an arbitrarily long vector of data values. DataVector is the underlying data co...
Definition: DataVector.h:44
size_type m_size
Definition: DataVector.h:195
Definition: AbstractContinuousDomain.cpp:24
size_type m_dim
Definition: DataVector.h:196
size_type size() const
Return the number of elements in this DataVector.
Definition: DataVector.h:215
void releaseUnusedMemory()
releases unused memory in the memory manager.
Definition: DataVector.cpp:39
double ElementType
Definition: DataVector.h:50
size_type m_N
Definition: DataVector.h:197
ElementType * ValueType
Definition: DataVector.h:54
#define EsysAssert(AssertTest, AssertMessage)
EsysAssert is a MACRO that will throw an exception if the boolean condition specified is false...
Definition: EsysAssert.h:96
const ElementType & const_reference
Definition: DataVector.h:62
reference operator[](const size_type i)
Return a reference to the element at position i in this DataVector. Will throw an exception if an inv...
Definition: DataVector.h:222
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:54
ElementType & reference
Definition: DataVector.h:61
ElementType value_type
Definition: DataVector.h:59
long size_type
Definition: DataVector.h:60
Definition: WrappedArray.h:29
ValueType m_array_data
Definition: DataVector.h:201