ESYS13  Revision_
DataVector.h
Go to the documentation of this file.
00001 
00002 /*******************************************************
00003 *
00004 * Copyright (c) 2003-2012 by University of Queensland
00005 * Earth Systems Science Computational Center (ESSCC)
00006 * http://www.uq.edu.au/esscc
00007 *
00008 * Primary Business: Queensland, Australia
00009 * Licensed under the Open Software License version 3.0
00010 * http://www.opensource.org/licenses/osl-3.0.php
00011 *
00012 *******************************************************/
00013 
00014 
00015 #if !defined escript_DataVector_20050324_H
00016 #define escript_DataVector_20050324_H
00017 #include "system_dep.h"
00018 
00019 #include "esysUtils/EsysAssert.h"
00020 
00021 #include <vector>
00022 #include <iostream>
00023 #include <fstream>
00024 
00025 namespace escript {
00026 
00027 class WrappedArray;
00028 
00041 class ESCRIPT_DLL_API DataVector {
00042 
00043  public:
00044 
00045   //
00046   // The type of the elements stored in the vector.
00047   typedef double ElementType;
00048 
00049   //
00050   // The underlying type used to implement the vector.
00051   typedef ElementType *  ValueType;
00052   typedef const ElementType * ConstValueType;
00053 
00054   //
00055   // Various types exported to clients of this class.
00056   typedef ElementType          value_type;
00057   typedef long                 size_type;
00058   typedef ElementType &        reference;
00059   typedef const ElementType &  const_reference;
00060 
00068   DataVector();
00069 
00078   DataVector(const DataVector& other);
00079 
00098   DataVector(const size_type size,
00099              const value_type val=0.0,
00100              const size_type blockSize=1);
00101 
00109   ~DataVector();
00110 
00121   void
00122   resize(const size_type newSize,
00123          const value_type newVal=0.0,
00124          const size_type newBlockSize=1);
00125 
00132   void
00133   copyFromArray(const escript::WrappedArray& value, size_type copies);
00134 
00135   void 
00136   copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
00137 
00138 
00143   inline
00144   size_type
00145   size() const;
00146 
00152   DataVector&
00153   operator=(const DataVector& other);
00154 
00160   bool
00161   operator==(const DataVector& other) const;
00162 
00168   bool
00169   operator!=(const DataVector& other) const;
00170 
00179   inline
00180   reference
00181   operator[](const size_type i);
00182 
00183   inline
00184   const_reference
00185   operator[](const size_type i) const;
00186 
00187 
00188  protected:
00189 
00190  private:
00191 
00192   size_type m_size;
00193   size_type m_dim;
00194   size_type m_N;
00195 
00196   //
00197   // The container for the elements contained in this DataVector.
00198   ValueType m_array_data;
00199 };
00200 
00206 ESCRIPT_DLL_API void releaseUnusedMemory();
00207                                                                                                                                                                                                      
00208 
00209 
00210 inline
00211 DataVector::size_type
00212 DataVector::size() const
00213 {
00214   return m_size;
00215 }
00216 
00217 inline
00218 DataVector::reference
00219 DataVector::operator[](const DataVector::size_type i)
00220 {
00221   EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
00222   return m_array_data[i];
00223 }
00224 
00225 inline
00226 DataVector::const_reference
00227 DataVector::operator[](const DataVector::size_type i) const
00228 {
00229   EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
00230   return m_array_data[i];
00231 }
00232 
00233 } // end of namespace
00234 
00235 #endif