queso-0.51.1
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,2009,2010,2011,2012,2013 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  UQ_FATAL_TEST_MACRO((i >= m_numRows) || (j >= m_numCols) || (m_data[i] == NULL),
72  "TwoDArray<T>::setLocation()",
73  "invalid situation");
74  (*(m_data[i]))[j] = info;
75  return;
76 }
77 
78 // Accessor methods-----------------------------------------------------
79 template <class T>
80 T& TwoDArray<T>::operator()(unsigned int i, unsigned int j)
81 {
82  UQ_FATAL_TEST_MACRO((i >= m_numRows) ||
83  (j >= m_numCols) ||
84  (m_data[i] == NULL) ||
85  ((*m_data[i])[j] == NULL),
87  "TwoDArray<T>::operator(1)",
88  "invalid situation");
89  return *(*(m_data[i]))[j];
90 }
91 
92 template <class T>
93 const T& TwoDArray<T>::operator()(unsigned int i, unsigned int j) const
94 {
95  UQ_FATAL_TEST_MACRO((i >= m_numRows) ||
96  (j >= m_numCols) ||
97  (m_data[i] == NULL) ||
98  ((*m_data[i])[j] == NULL),
100  "TwoDArray<T>::operator(2)",
101  "invalid situation");
102  return *(*(m_data[i]))[j];
103 }
104 
105 } // End namespace QUESO
unsigned int numCols() const
Number of columns in the array.
T & operator()(unsigned int i, unsigned int j)
Returns data stored in a specific location (non-const).
unsigned int numRows() const
Number of rows in the array.
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
TwoDArray(unsigned int numRows, unsigned int numCols)
Default constructor.
std::vector< std::vector< T * > * > m_data
~TwoDArray()
Destructor.
unsigned int m_numRows
unsigned int m_numCols
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void setLocation(unsigned int i, unsigned int j, T *info)
Sets the data in a specific location.

Generated on Thu Apr 23 2015 19:26:15 for queso-0.51.1 by  doxygen 1.8.5