queso-0.53.0
2dArrayOfStuff.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/Defines.h>
26 #include <queso/2dArrayOfStuff.h>
27 
28 namespace QUESO {
29 
30 // Default constructor -------------------------------------------------
31 template <class T>
32 TwoDArray<T>::TwoDArray(unsigned int numRows, unsigned int numCols)
33  : m_numRows(numRows),
34  m_numCols(numCols),
35  m_data (m_numRows,NULL)
36 {
37  for (unsigned int i = 0; i < m_numRows; ++i) {
38  m_data[i] = new std::vector<T*>(m_numCols,NULL);
39  }
40 }
41 
42 // Destructor ----------------------------------------------------------
43 template <class T>
45 {
46  for (unsigned int i = 0; i < m_numRows; ++i) {
47  for (unsigned int j = 0; j < m_numCols; ++j) {
48  if ((*(m_data[i]))[j] != NULL) delete (*(m_data[i]))[j];
49  }
50  delete m_data[i];
51  }
52 }
53 
54 // Property methods-----------------------------------------------------
55 template <class T>
56 unsigned int TwoDArray<T>::numRows() const
57 {
58  return m_numRows;
59 }
60 
61 template <class T>
62 unsigned int TwoDArray<T>::numCols() const
63 {
64  return m_numCols;
65 }
66 
67 template <class T>
68 void TwoDArray<T>::setLocation(unsigned int i, unsigned int j, T* info)
69 {
70  queso_require_msg(!((i >= m_numRows) || (j >= m_numCols) || (m_data[i] == NULL)), "invalid situation");
71  (*(m_data[i]))[j] = info;
72  return;
73 }
74 
75 // Accessor methods-----------------------------------------------------
76 template <class T>
77 T& TwoDArray<T>::operator()(unsigned int i, unsigned int j)
78 {
79  // FIXME - Should this really be active in optimized codes? - RHS
80  queso_require_less(i, m_numRows);
81  queso_require_less(j, m_numCols);
82  queso_require(m_data[i]);
83  queso_require((*m_data[i])[j]);
84 
85  return *(*(m_data[i]))[j];
86 }
87 
88 template <class T>
89 const T& TwoDArray<T>::operator()(unsigned int i, unsigned int j) const
90 {
91  // FIXME - Should this really be active in optimized codes? - RHS
92  queso_require_less(i, m_numRows);
93  queso_require_less(j, m_numCols);
94  queso_require(m_data[i]);
95  queso_require((*m_data[i])[j]);
96 
97  return *(*(m_data[i]))[j];
98 }
99 
100 } // End namespace QUESO
~TwoDArray()
Destructor.
TwoDArray(unsigned int numRows, unsigned int numCols)
Default constructor.
unsigned int m_numRows
unsigned int numCols() const
Number of columns in the array.
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
#define queso_require(asserted)
Definition: asserts.h:124
std::vector< std::vector< T * > * > m_data
unsigned int m_numCols
#define queso_require_less(expr1, expr2)
Definition: asserts.h:133
T & operator()(unsigned int i, unsigned int j)
Returns data stored in a specific location (non-const).
void setLocation(unsigned int i, unsigned int j, T *info)
Sets the data in a specific location.
unsigned int numRows() const
Number of rows in the array.

Generated on Thu Jun 11 2015 13:52:32 for queso-0.53.0 by  doxygen 1.8.5