NiHu  2.0
pool_pattern.hpp
Go to the documentation of this file.
1 // This file is a part of NiHu, a C++ BEM template library.
2 //
3 // Copyright (C) 2012-2014 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2014 Peter Rucz <rucz@hit.bme.hu>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
24 #ifndef POOL_PATTERN_HPP_INCLUDED
25 #define POOL_PATTERN_HPP_INCLUDED
26 
27 #include <stdexcept>
28 
29 namespace NiHu
30 {
31 
40 template <class C, unsigned MaxOrder>
41 class pool
42 {
43 public:
45  pool(void)
46  {
47  for (unsigned i = 0; i <= MaxOrder; ++i)
48  m_p_data[i] = new C(i);
49  }
50 
52  ~pool(void)
53  {
54  for (unsigned i = 0; i <= MaxOrder; ++i)
55  delete m_p_data[i];
56  }
57 
63  C const &operator[](unsigned idx) const
64  {
65  if (idx > MaxOrder)
66  throw std::out_of_range("Pool overindexing");
67  return *m_p_data[idx];
68  }
69 
70 private:
71  C *m_p_data[MaxOrder+1];
72 };
73 
74 } // end of namespace NiHu
75 
76 #endif /* POOL_PATTERN_HPP_INCLUDED */
NiHu::pool::pool
pool(void)
constructor
Definition: pool_pattern.hpp:45
C
Definition: bbfmm_covariance.cpp:47
NiHu::pool
Class storing a vector of class instances.
Definition: pool_pattern.hpp:41
NiHu::pool::~pool
~pool(void)
destructor
Definition: pool_pattern.hpp:52
NiHu::pool::operator[]
const C & operator[](unsigned idx) const
Index operator.
Definition: pool_pattern.hpp:63