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 <map>
25#include <memory>
26
27#undef min
28#undef max
29
30namespace Opm {
31
32 class SimpleTable;
33
35 /*
36 The TableContainer class implements a simple map:
37 {tableNumber , Table}. The main functionality of the
38 TableContainer class is that the getTable method implements
39 the Eclipse behavior:
40
41 If table N is not implemented - use table N - 1.
42
43 The getTable() method will eventually throw an exception if
44 not even table 0 is there.
45
46 Consider the following code:
47
48 TableContainer container(10);
49
50 std::shared_ptr<TableType> table0 = std::make_shared<TableType>(...);
51 container.addTable( table0 , 0 )
52
53 We create a container with maximum 10 tables, and then we add
54 one single table at slot 0; then we have:
55
56 container.size() == 1
57 container.hasTable( 0 ) == true
58 container.hasTable( 9 ) == false
59 container.hasTable(10 ) == false
60
61 container.getTable( 0 ) == container[9] == table0;
62 container.gteTable(10 ) ==> exception
63 */
64 public:
65 using TableMap = std::map<size_t, std::shared_ptr<SimpleTable>>;
66
68 explicit TableContainer( size_t maxTables );
69
71
72 bool empty() const;
73
74 /*
75 This is the number of actual tables in the container.
76 */
77 size_t size() const;
78
79 size_t max() const;
80 const TableMap& tables() const;
81 void addTable(size_t tableNumber , std::shared_ptr<SimpleTable> table);
82
83
84 /*
85 Observe that the hasTable() method does not invoke the "If
86 table N is not implemented use table N - 1 behavior.
87 */
88 size_t hasTable(size_t tableNumber) const;
89 const SimpleTable& getTable(size_t tableNumber) const;
90 const SimpleTable& operator[](size_t tableNumber) const;
91
92 template <class TableType>
93 const TableType& getTable(size_t tableNumber) const {
94 const SimpleTable &simpleTable = getTable( tableNumber );
95 const TableType * table = static_cast<const TableType *>( &simpleTable );
96 return *table;
97 }
98
99 bool operator==(const TableContainer& data) const;
100
101 template<class Serializer>
102 void serializeOp(Serializer& serializer)
103 {
104 serializer(m_maxTables);
105 serializer.map(m_tables);
106 }
107
108 private:
109 size_t m_maxTables;
110 TableMap m_tables;
111 };
112
113}
114
115
116#endif
Definition: Serializer.hpp:38
Definition: SimpleTable.hpp:35
Definition: TableContainer.hpp:34
TableContainer(size_t maxTables)
const SimpleTable & getTable(size_t tableNumber) const
void serializeOp(Serializer &serializer)
Definition: TableContainer.hpp:102
size_t size() const
size_t max() const
const SimpleTable & operator[](size_t tableNumber) const
void addTable(size_t tableNumber, std::shared_ptr< SimpleTable > table)
size_t hasTable(size_t tableNumber) const
bool operator==(const TableContainer &data) const
const TableType & getTable(size_t tableNumber) const
Definition: TableContainer.hpp:93
std::map< size_t, std::shared_ptr< SimpleTable > > TableMap
Definition: TableContainer.hpp:65
static TableContainer serializeObject()
const TableMap & tables() const
bool empty() const
Definition: A.hpp:4
static std::string data()
Definition: exprtk.hpp:40022