escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 #if !defined escript_DataVector_20050324_H 00019 #define escript_DataVector_20050324_H 00020 #include "system_dep.h" 00021 00022 #include "esysUtils/EsysAssert.h" 00023 00024 #include <vector> 00025 #include <iostream> 00026 #include <fstream> 00027 00028 namespace escript { 00029 00030 class WrappedArray; 00031 00044 class ESCRIPT_DLL_API DataVector { 00045 00046 public: 00047 00048 // 00049 // The type of the elements stored in the vector. 00050 typedef double ElementType; 00051 00052 // 00053 // The underlying type used to implement the vector. 00054 typedef ElementType * ValueType; 00055 typedef const ElementType * ConstValueType; 00056 00057 // 00058 // Various types exported to clients of this class. 00059 typedef ElementType value_type; 00060 typedef long size_type; 00061 typedef ElementType & reference; 00062 typedef const ElementType & const_reference; 00063 00071 DataVector(); 00072 00081 DataVector(const DataVector& other); 00082 00101 DataVector(const size_type size, 00102 const value_type val=0.0, 00103 const size_type blockSize=1); 00104 00112 ~DataVector(); 00113 00124 void 00125 resize(const size_type newSize, 00126 const value_type newVal=0.0, 00127 const size_type newBlockSize=1); 00128 00135 void 00136 copyFromArray(const escript::WrappedArray& value, size_type copies); 00137 00138 void 00139 copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies); 00140 00141 00146 inline 00147 size_type 00148 size() const; 00149 00155 DataVector& 00156 operator=(const DataVector& other); 00157 00163 bool 00164 operator==(const DataVector& other) const; 00165 00171 bool 00172 operator!=(const DataVector& other) const; 00173 00182 inline 00183 reference 00184 operator[](const size_type i); 00185 00186 inline 00187 const_reference 00188 operator[](const size_type i) const; 00189 00190 00191 protected: 00192 00193 private: 00194 00195 size_type m_size; 00196 size_type m_dim; 00197 size_type m_N; 00198 00199 // 00200 // The container for the elements contained in this DataVector. 00201 ValueType m_array_data; 00202 }; 00203 00209 ESCRIPT_DLL_API void releaseUnusedMemory(); 00210 00211 00212 00213 inline 00214 DataVector::size_type 00215 DataVector::size() const 00216 { 00217 return m_size; 00218 } 00219 00220 inline 00221 DataVector::reference 00222 DataVector::operator[](const DataVector::size_type i) 00223 { 00224 EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size()); 00225 return m_array_data[i]; 00226 } 00227 00228 inline 00229 DataVector::const_reference 00230 DataVector::operator[](const DataVector::size_type i) const 00231 { 00232 EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size()); 00233 return m_array_data[i]; 00234 } 00235 00236 } // end of namespace 00237 00238 #endif