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_DataBlocks2D_20040405_H 00019 #define escript_DataBlocks2D_20040405_H 00020 #include "system_dep.h" 00021 00022 #include "DataVector.h" 00023 00024 #include <sstream> 00025 #include <iostream> 00026 00027 namespace escript { 00028 00038 class DataBlocks2D { 00039 00040 public: 00041 00042 // 00043 // The type of the underlying data array under management. 00044 // The multi-dimensional data points are flattened and stored 00045 // serially as a vector of doubles. 00046 typedef DataVector ValueType; 00047 00056 ESCRIPT_DLL_API 00057 DataBlocks2D(); 00058 00066 ESCRIPT_DLL_API 00067 DataBlocks2D(const DataBlocks2D& other); 00068 00082 ESCRIPT_DLL_API 00083 DataBlocks2D(int numRows, int numCols, int blockSize); 00084 00092 ESCRIPT_DLL_API 00093 ~DataBlocks2D(); 00094 00100 ESCRIPT_DLL_API 00101 inline 00102 ValueType::size_type 00103 size() const; 00104 00109 ESCRIPT_DLL_API 00110 inline 00111 ValueType::size_type 00112 getNumRows() const; 00113 00118 ESCRIPT_DLL_API 00119 inline 00120 ValueType::size_type 00121 getNumCols() const; 00122 00127 ESCRIPT_DLL_API 00128 inline 00129 ValueType::size_type 00130 getBlockSize() const; 00131 00143 ESCRIPT_DLL_API 00144 void 00145 resize(int numRows, int numCols, int blockSize); 00146 00152 ESCRIPT_DLL_API 00153 DataBlocks2D& 00154 operator=(const DataBlocks2D& other); 00155 00160 ESCRIPT_DLL_API 00161 void 00162 Swap(DataBlocks2D& other); 00163 00172 ESCRIPT_DLL_API 00173 inline 00174 ValueType::size_type 00175 index(int row, int col) const; 00176 00182 ESCRIPT_DLL_API 00183 inline 00184 ValueType::reference 00185 operator[](ValueType::size_type i); 00186 00187 ESCRIPT_DLL_API 00188 inline 00189 ValueType::const_reference 00190 operator[](ValueType::size_type i) const; 00191 00196 ESCRIPT_DLL_API 00197 inline 00198 ValueType::reference 00199 operator()(int row, int col); 00200 00201 ESCRIPT_DLL_API 00202 inline 00203 ValueType::const_reference 00204 operator()(int row, int col) const; 00205 00212 ESCRIPT_DLL_API 00213 inline 00214 ValueType& 00215 getData(); 00216 00217 ESCRIPT_DLL_API 00218 inline 00219 const ValueType& 00220 getData() const; 00221 00222 00223 protected: 00224 00225 private: 00226 00227 // 00228 // The underlying array of data values. 00229 // The two dimensional array of multi-dimensional data points is flattened 00230 // and serialised within this one dimensional array of doubles. 00231 ValueType m_data; 00232 00233 // 00234 // The dimensions of the 2D array of data points. 00235 ValueType::size_type m_numRows; 00236 ValueType::size_type m_numCols; 00237 00238 // 00239 // The number of values per data point. 00240 ValueType::size_type m_blockSize; 00241 00242 }; 00243 00244 inline 00245 DataBlocks2D::ValueType::size_type 00246 DataBlocks2D::size() const 00247 { 00248 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00249 return m_data.size(); 00250 } 00251 00252 inline 00253 DataBlocks2D::ValueType::size_type 00254 DataBlocks2D::getNumRows() const 00255 { 00256 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00257 return m_numRows; 00258 } 00259 00260 inline 00261 DataBlocks2D::ValueType::size_type 00262 DataBlocks2D::getNumCols() const 00263 { 00264 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00265 return m_numCols; 00266 } 00267 00268 inline 00269 DataBlocks2D::ValueType::size_type 00270 DataBlocks2D::getBlockSize() const 00271 { 00272 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00273 return m_blockSize; 00274 } 00275 00276 inline 00277 DataBlocks2D::ValueType::size_type 00278 DataBlocks2D::index(int row, int col) const 00279 { 00280 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00281 EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range."); 00282 ValueType::size_type temp=(row*m_numCols+col)*m_blockSize; 00283 EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range."); 00284 return (temp); 00285 } 00286 00287 inline 00288 DataBlocks2D::ValueType::reference 00289 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) 00290 { 00291 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00292 return m_data[i]; 00293 } 00294 00295 inline 00296 DataBlocks2D::ValueType::const_reference 00297 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const 00298 { 00299 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00300 return m_data[i]; 00301 } 00302 00303 inline 00304 DataBlocks2D::ValueType::reference 00305 DataBlocks2D::operator()(int row, int col) 00306 { 00307 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00308 return m_data[index(row,col)]; 00309 } 00310 00311 inline 00312 DataBlocks2D::ValueType::const_reference 00313 DataBlocks2D::operator()(int row, int col) const 00314 { 00315 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00316 return m_data[index(row,col)]; 00317 } 00318 00319 inline 00320 DataBlocks2D::ValueType& 00321 DataBlocks2D::getData() 00322 { 00323 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00324 return m_data; 00325 } 00326 00327 inline 00328 const DataBlocks2D::ValueType& 00329 DataBlocks2D::getData() const 00330 { 00331 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object."); 00332 return m_data; 00333 } 00334 00335 } // end of namespace 00336 00337 #endif