TableContainer.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2015 Statoil ASA.
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM 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  OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OPM_TABLE_CONTAINER_HPP
21 #define OPM_TABLE_CONTAINER_HPP
22 
23 #include <cstddef>
24 #include <memory>
25 
27 
28 
29 namespace Opm {
30 
32  /*
33  The TableContainer class implements a simple map:
34  {tableNumber , Table}. The main functionality of the
35  TableContainer class is that the getTable method implements
36  the Eclipse behavior:
37 
38  If table N is not implemented - use table N - 1.
39 
40  The getTable() method will eventually throw an exception if
41  not even table 0 is there.
42 
43  Consider the following code:
44 
45  TableContainer container(10);
46 
47  std::shared_ptr<TableType> table0 = std::make_shared<TableType>(...);
48  container.addTable( table0 , 0 )
49 
50  We create a container with maximum 10 tables, and then we add
51  one single table at slot 0; then we have:
52 
53  container.size() == 1
54  container.hasTable( 0 ) == true
55  container.hasTable( 9 ) == false
56  container.hasTable(10 ) == false
57 
58  container.getTable( 0 ) == container[9] == table0;
59  container.gteTable(10 ) ==> exception
60  */
61  public:
62  explicit TableContainer( size_t maxTables );
63  bool empty() const;
64 
65  /*
66  This is the number of actual tables in the container.
67  */
68  size_t size() const;
69  void addTable(size_t tableNumber , std::shared_ptr<const SimpleTable> table);
70 
71 
72  /*
73  Observe that the hasTable() method does not invoke the "If
74  table N is not implemented use table N - 1 behavior.
75  */
76  size_t hasTable(size_t tableNumber) const;
77  const SimpleTable& getTable(size_t tableNumber) const;
78  const SimpleTable& operator[](size_t tableNumber) const;
79 
80  template <class TableType>
81  const TableType& getTable(size_t tableNumber) const {
82  const SimpleTable &simpleTable = getTable( tableNumber );
83  const TableType * table = static_cast<const TableType *>( &simpleTable );
84  return *table;
85  }
86 
87  private:
88  size_t m_maxTables;
89  std::map<size_t , std::shared_ptr<const SimpleTable> > m_tables;
90  };
91 
92 }
93 
94 
95 #endif
void addTable(size_t tableNumber, std::shared_ptr< const SimpleTable > table)
Definition: TableContainer.hpp:31
Definition: Deck.hpp:29
const SimpleTable & operator[](size_t tableNumber) const
size_t hasTable(size_t tableNumber) const
TableContainer(size_t maxTables)
const SimpleTable & getTable(size_t tableNumber) const
const TableType & getTable(size_t tableNumber) const
Definition: TableContainer.hpp:81
size_t size() const
Definition: SimpleTable.hpp:32
bool empty() const