LifeV
ArraySimple.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief The file contains two classes implementing a wrap up
30  of Standard Library vector class to allow indexing from one.
31  *
32  * @date 30-08-1999
33  * @author Luca Formaggia <luca.formaggia@polimi.it>
34  *
35  * @contributor Laura Cattaneo
36  * @mantainer Laura Cattaneo
37  */
38 
39 #ifndef _SIMPLEARRAY_HH_
40 #define _SIMPLEARRAY_HH_
41 
42 #include <lifev/core/LifeV.hpp>
43 
44 namespace LifeV
45 {
46 //! ArraySimple
47 /*!
48  @author Luca Formaggia
49 
50  The class is a wrap up of Standard Library vector class.
51  It defines arrays of n x m size.
52  This class is deprecated and it should be removed when the
53  discussion is over. It is with COLUMNWISE ORDERING
54 
55  Example:
56 
57  ArraySimple<int> b(3,5) is an array with 3 rows and 5 columns
58 
59  */
60 
61 template <typename DataType>
62 class ArraySimple : public std::vector<DataType>
63 {
64 public:
65 
66  //! @name Public Types
67  //@{
68 
69  typedef DataType data_Type;
71  typedef typename vector_Type::size_type vectorSize_Type;
72  typedef typename vector_Type::reference vectorReference_Type;
73  typedef typename vector_Type::const_reference vectorConstReference_Type;
74  typedef typename vector_Type::iterator vectorIterator_Type;
75  typedef typename vector_Type::const_iterator vectorConstIterator_Type;
76 
77  //@}
78 
79 
80  //! @name Constructor & Destructor
81  //@{
82 
83  //! Empty Constructor
84  /*!
85  Construct a ArraySimple vector of size (0,0)
86  */
87  explicit ArraySimple();
88 
89  //! Constructor
90  /*!
91  Construct a ArraySimple vector of size (size,1)
92  @param vectorSize size of the ArraySimple vector
93  */
94  explicit ArraySimple ( vectorSize_Type vectorSize );
95 
96  //! Constructor
97  /*!
98  Construct a ArraySimple object of size (numberOfRows,numberOfColumns)
99  @param numberOfRows number of rows
100  @param numberOfColumns number of columns
101  */
102  explicit ArraySimple ( vectorSize_Type numberOfRows, vectorSize_Type numberOfColumns );
103 
104  //! Destructor
106 
107  //@}
108 
109 
110  //! @name Operators
111  //@{
112 
113  //! Access operator
114  /*!
115  ArraySimple is seen as vector (index from one)
116  @param i index of the element of the ArraySimple vector
117  @return a vector reference
118  */
120  {
121  return * ( this->begin() + ( i ) );
122  }
123 
124  //! Const access operator
125  /*!
126  ArraySimple is seen as vector
127  @param i index of the element of the ArraySimple vector
128  @return a vector const reference
129  */
131  {
132  return * ( this->begin() + ( i ) );
133  }
134 
135  //! Access operator
136  /*!
137  @param i row index
138  @param j column index
139  @return a vector reference
140  */
142  {
143  return * ( this->begin() + ( j ) * M_numberOfRows + ( i ) );
144  }
145 
146  //! Const access operator
147  /*!
148  @param i row index
149  @param j column index
150  @return a vector const reference
151  */
153  {
154  return * ( this->begin() + ( j ) * M_numberOfRows + ( i ) );
155  }
156 
157  //@}
158 
159 
160  //! @name Methods
161  //@{
162 
163  //!Return the iterator of the column passed by argument
164  /*!
165  @param column column index
166  @return ArraySimple iterator
167  */
168  inline typename ArraySimple<DataType>::iterator columnIterator ( vectorSize_Type const column );
169 
170  //!Resize the ArraySimple vector
171  /*!
172  @param numberOfRows number of rows
173  @param numberOfColumns number of columns
174  */
176 
177  //! Completely clear out the container, returning memory to the system
178  inline void clearArray();
179 
180  //! Check if the MeshEntityContainer vector contains an element with row index i and column index j
181  /*!
182  @param i row index
183  @param j column index
184  @return boolean
185  */
186  bool checkIndex ( vectorSize_Type const i, vectorSize_Type const j ) const
187  {
188  return i >= 0 && i + ( j ) * M_numberOfRows < this->size();
189  }
190 
191  //! Show the contents of the ArraySimple vector
192  void showMe() const;
193 
194  //@}
195 
196 
197  //! @name Get Methods
198  //@{
199 
200  //!Return the number of rows
201  /*!
202  @return a vector size type variable holding the number of rows
203  */
205  {
206  return M_numberOfRows;
207  }
208 
209  //!Return the number of columns
210  /*!
211  @return a vector size type variable holding the number of columns
212  */
214  {
215  return M_numberOfColumns;
216  }
217 
218  //@}
219 
220 private:
221 
222  //! Number of rows
224 
225  //! Number of columns
227 };
228 
229 
230 //============================================================================
231 // Constructors
232 //============================================================================
233 template <typename DataType>
235  :
236  std::vector<DataType>(),
237  M_numberOfRows ( 0 ),
238  M_numberOfColumns ( 0 )
239 {}
240 
241 template <typename DataType>
242 ArraySimple<DataType>::ArraySimple ( vectorSize_Type vectorSize )
243  :
246  M_numberOfColumns ( 1 )
247 {}
248 
249 template <typename DataType>
250 ArraySimple<DataType>::ArraySimple ( vectorSize_Type numberOfRows, vectorSize_Type numberOfColumns )
251  :
255 {}
256 
257 //============================================================================
258 // Methods
259 //============================================================================
260 template <typename DataType>
261 typename ArraySimple<DataType>::iterator
262 ArraySimple<DataType>::columnIterator ( vectorSize_Type const column )
263 {
264  if ( column > M_numberOfColumns )
265  {
266  return typename ArraySimple<DataType>::iterator();
267  }
268  else
269  {
270  return this->begin() + ( column ) * M_numberOfRows;
271  }
272 }
273 
274 
275 template <typename DataType>
276 void
277 ArraySimple<DataType>::reshape ( vectorSize_Type numberOfRows, vectorSize_Type numberOfColumns )
278 {
279  vector_Type::resize ( numberOfRows * numberOfColumns ); // Standard Library vector method
280  M_numberOfRows = numberOfRows;
281  M_numberOfColumns = numberOfColumns;
282 }
283 
284 template <typename DataType>
285 void
287 {
288  vector_Type tmp;
289  this->clear();
290  this->swap ( tmp );
291  M_numberOfRows = 0;
292  M_numberOfColumns = 0;
293 }
294 
295 template <typename DataType>
296 void
297 ArraySimple<DataType>::showMe() const
298 {
299  std::cout << " Number of rows: " << M_numberOfRows << std::endl;
300  std::cout << " Number of columns: " << M_numberOfColumns << std::endl;
301 }
302 
303 }// Namespace LifeV
304 
305 #endif /* _SIMPLEARRAY_HH_ */
ArraySimple(vectorSize_Type numberOfRows, vectorSize_Type numberOfColumns)
Constructor.
vectorConstReference_Type operator()(vectorSize_Type const i, vectorSize_Type const j) const
Const access operator.
ArraySimple()
Empty Constructor.
void showMe() const
Show the contents of the ArraySimple vector.
std::vector< DataType > vector_Type
Definition: ArraySimple.hpp:70
ArraySimple< DataType >::iterator columnIterator(vectorSize_Type const column)
Return the iterator of the column passed by argument.
vectorReference_Type operator()(vectorSize_Type const i, vectorSize_Type const j)
Access operator.
void updateInverseJacobian(const UInt &iQuadPt)
void reshape(vectorSize_Type const numberOfRows, vectorSize_Type const numberOfColumns)
Resize the ArraySimple vector.
bool checkIndex(vectorSize_Type const i, vectorSize_Type const j) const
Check if the MeshEntityContainer vector contains an element with row index i and column index j...
~ArraySimple()
Destructor.
vectorSize_Type const numberOfColumns() const
Return the number of columns.
ArraySimple(vectorSize_Type vectorSize)
Constructor.
void clearArray()
Completely clear out the container, returning memory to the system.
vectorSize_Type M_numberOfColumns
Number of columns.