My Project
TableContainer.hpp
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 <map>
25 #include <memory>
26 
27 namespace Opm {
28 
29  class SimpleTable;
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  using TableMap = std::map<size_t, std::shared_ptr<SimpleTable>>;
63 
65  explicit TableContainer( size_t maxTables );
66 
67  static TableContainer serializeObject();
68 
69  bool empty() const;
70 
71  /*
72  This is the number of actual tables in the container.
73  */
74  size_t size() const;
75 
76  size_t max() const;
77  const TableMap& tables() const;
78  void addTable(size_t tableNumber , std::shared_ptr<SimpleTable> table);
79 
80 
81  /*
82  Observe that the hasTable() method does not invoke the "If
83  table N is not implemented use table N - 1 behavior.
84  */
85  size_t hasTable(size_t tableNumber) const;
86  const SimpleTable& getTable(size_t tableNumber) const;
87  const SimpleTable& operator[](size_t tableNumber) const;
88 
89  template <class TableType>
90  const TableType& getTable(size_t tableNumber) const {
91  const SimpleTable &simpleTable = getTable( tableNumber );
92  const TableType * table = static_cast<const TableType *>( &simpleTable );
93  return *table;
94  }
95 
96  bool operator==(const TableContainer& data) const;
97 
98  template<class Serializer>
99  void serializeOp(Serializer& serializer)
100  {
101  serializer(m_maxTables);
102  serializer.map(m_tables);
103  }
104 
105  private:
106  size_t m_maxTables;
107  TableMap m_tables;
108  };
109 
110 }
111 
112 
113 #endif
Definition: Serializer.hpp:38
Definition: SimpleTable.hpp:35
Definition: TableContainer.hpp:31
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29