escript  Revision_Unversioneddirectory
DataBlocks2D.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_DataBlocks2D_20040405_H
19 #define escript_DataBlocks2D_20040405_H
20 #include "system_dep.h"
21 
22 #include "DataVector.h"
23 
24 #include <sstream>
25 #include <iostream>
26 
27 namespace escript {
28 
38 class DataBlocks2D {
39 
40  public:
41 
42  //
43  // The type of the underlying data array under management.
44  // The multi-dimensional data points are flattened and stored
45  // serially as a vector of doubles.
47 
57  DataBlocks2D();
58 
67  DataBlocks2D(const DataBlocks2D& other);
68 
83  DataBlocks2D(int numRows, int numCols, int blockSize);
84 
93  ~DataBlocks2D();
94 
101  inline
103  size() const;
104 
110  inline
112  getNumRows() const;
113 
119  inline
121  getNumCols() const;
122 
128  inline
130  getBlockSize() const;
131 
144  void
145  resize(int numRows, int numCols, int blockSize);
146 
153  DataBlocks2D&
154  operator=(const DataBlocks2D& other);
155 
161  void
162  Swap(DataBlocks2D& other);
163 
173  inline
175  index(int row, int col) const;
176 
183  inline
186 
188  inline
191 
197  inline
199  operator()(int row, int col);
200 
202  inline
204  operator()(int row, int col) const;
205 
213  inline
214  ValueType&
215  getData();
216 
218  inline
219  const ValueType&
220  getData() const;
221 
222 
223  protected:
224 
225  private:
226 
227  //
228  // The underlying array of data values.
229  // The two dimensional array of multi-dimensional data points is flattened
230  // and serialised within this one dimensional array of doubles.
231  ValueType m_data;
232 
233  //
234  // The dimensions of the 2D array of data points.
237 
238  //
239  // The number of values per data point.
241 
242 };
243 
244 inline
247 {
248  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
249  return m_data.size();
250 }
251 
252 inline
255 {
256  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
257  return m_numRows;
258 }
259 
260 inline
263 {
264  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
265  return m_numCols;
266 }
267 
268 inline
271 {
272  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
273  return m_blockSize;
274 }
275 
276 inline
278 DataBlocks2D::index(int row, int col) const
279 {
280  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
281  EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range.");
283  EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");
284  return (temp);
285 }
286 
287 inline
290 {
291  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
292  return m_data[i];
293 }
294 
295 inline
298 {
299  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
300  return m_data[i];
301 }
302 
303 inline
305 DataBlocks2D::operator()(int row, int col)
306 {
307  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
308  return m_data[index(row,col)];
309 }
310 
311 inline
313 DataBlocks2D::operator()(int row, int col) const
314 {
315  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
316  return m_data[index(row,col)];
317 }
318 
319 inline
322 {
323  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
324  return m_data;
325 }
326 
327 inline
330 {
331  EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
332  return m_data;
333 }
334 
335 } // end of namespace
336 
337 #endif
DataVector implements an arbitrarily long vector of data values. DataVector is the underlying data co...
Definition: DataVector.h:44
DataBlocks2D()
Default constructor for DataBlocks2D.
Definition: DataBlocks2D.cpp:27
ValueType::size_type getNumRows() const
Return the number of rows in this DataBlocks2D array.
Definition: DataBlocks2D.h:254
Definition: AbstractContinuousDomain.cpp:24
ValueType::reference operator()(int row, int col)
Return a reference to the first element for the data-point (i,j).
Definition: DataBlocks2D.h:305
size_type size() const
Return the number of elements in this DataVector.
Definition: DataVector.h:215
void Swap(DataBlocks2D &other)
Swap all the values managed by the given DataBlocks2D objects.
Definition: DataBlocks2D.cpp:74
ValueType::size_type getBlockSize() const
Return the data point size for this DataBlocks2D array.
Definition: DataBlocks2D.h:270
DataVector ValueType
Definition: DataBlocks2D.h:46
ValueType::size_type m_numRows
Definition: DataBlocks2D.h:235
ValueType & getData()
Return a reference to the underlying data array. Data returned is an array type object that can be in...
Definition: DataBlocks2D.h:321
ValueType::size_type m_blockSize
Definition: DataBlocks2D.h:240
ValueType::reference operator[](ValueType::size_type i)
Return a reference to the first element for the data-point with index i within the underlying data ar...
Definition: DataBlocks2D.h:289
~DataBlocks2D()
Default destructor for DataBlocks2D.
Definition: DataBlocks2D.cpp:50
DataBlocks2D & operator=(const DataBlocks2D &other)
DataBlocks2D assignment operator = Assign the given DataBlocks2D object to this one.
Definition: DataBlocks2D.cpp:84
#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
ValueType m_data
Definition: DataBlocks2D.h:231
void resize(int numRows, int numCols, int blockSize)
Resize the underlying data array. All current data is lost. The new data elements are initialised to ...
Definition: DataBlocks2D.cpp:58
ValueType::size_type m_numCols
Definition: DataBlocks2D.h:236
DataBlocks2D manages a 2D array of multi-dimensional data points.
Definition: DataBlocks2D.h:38
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:54
ElementType & reference
Definition: DataVector.h:61
ValueType::size_type size() const
Return the size of the underlying data array. ie: Number of rows * Number of columns * Number of elem...
Definition: DataBlocks2D.h:246
long size_type
Definition: DataVector.h:60
ValueType::size_type index(int row, int col) const
Return the 1 dimensional index of the first element for data-point (i,j) within the underlying data a...
Definition: DataBlocks2D.h:278
ValueType::size_type getNumCols() const
Return the number of columns in this DataBlocks2D array.
Definition: DataBlocks2D.h:262