ESScript  Revision_4488
DataBlocks2D.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 
17 #if !defined escript_DataBlocks2D_20040405_H
18 #define escript_DataBlocks2D_20040405_H
19 #include "system_dep.h"
20 
21 #include "DataVector.h"
22 
23 #include <sstream>
24 #include <iostream>
25 
26 namespace escript {
27 
37 class DataBlocks2D {
38 
39  public:
40 
41  //
42  // The type of the underlying data array under management.
43  // The multi-dimensional data points are flattened and stored
44  // serially as a vector of doubles.
46 
56  DataBlocks2D();
57 
66  DataBlocks2D(const DataBlocks2D& other);
67 
82  DataBlocks2D(int numRows, int numCols, int blockSize);
83 
92  ~DataBlocks2D();
93 
100  inline
102  size() const;
103 
109  inline
111  getNumRows() const;
112 
118  inline
120  getNumCols() const;
121 
127  inline
129  getBlockSize() const;
130 
143  void
144  resize(int numRows, int numCols, int blockSize);
145 
152  DataBlocks2D&
153  operator=(const DataBlocks2D& other);
154 
160  void
161  Swap(DataBlocks2D& other);
162 
172  inline
174  index(int row, int col) const;
175 
182  inline
185 
187  inline
190 
196  inline
198  operator()(int row, int col);
199 
201  inline
203  operator()(int row, int col) const;
204 
212  inline
213  ValueType&
214  getData();
215 
217  inline
218  const ValueType&
219  getData() const;
220 
221 
222  protected:
223 
224  private:
225 
226  //
227  // The underlying array of data values.
228  // The two dimensional array of multi-dimensional data points is flattened
229  // and serialised within this one dimensional array of doubles.
231 
232  //
233  // The dimensions of the 2D array of data points.
236 
237  //
238  // The number of values per data point.
240 
241 };
242 
243 inline
246 {
247  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
248  return m_data.size();
249 }
250 
251 inline
254 {
255  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
256  return m_numRows;
257 }
258 
259 inline
262 {
263  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
264  return m_numCols;
265 }
266 
267 inline
270 {
271  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
272  return m_blockSize;
273 }
274 
275 inline
277 DataBlocks2D::index(int row, int col) const
278 {
279  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
280  EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range.");
282  EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");
283  return (temp);
284 }
285 
286 inline
289 {
290  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
291  return m_data[i];
292 }
293 
294 inline
297 {
298  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
299  return m_data[i];
300 }
301 
302 inline
304 DataBlocks2D::operator()(int row, int col)
305 {
306  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
307  return m_data[index(row,col)];
308 }
309 
310 inline
312 DataBlocks2D::operator()(int row, int col) const
313 {
314  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
315  return m_data[index(row,col)];
316 }
317 
318 inline
321 {
322  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
323  return m_data;
324 }
325 
326 inline
329 {
330  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
331  return m_data;
332 }
333 
334 } // end of namespace
335 
336 #endif