My Project
Loading...
Searching...
No Matches
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
27namespace Opm {
28
29 class SimpleTable;
30
61 {
62 public:
63 using TableMap = std::map<size_t, std::shared_ptr<SimpleTable>>;
64
66 explicit TableContainer(size_t maxTables);
67
68 static TableContainer serializationTestObject();
69
70 bool empty() const;
71
72 // This is the number of actual tables in the container.
73 size_t size() const;
74 size_t max() const;
75
76 const TableMap& tables() const;
77
78 void addTable(size_t tableNumber, std::shared_ptr<SimpleTable> table);
79
80 // Observe that the hasTable() method does not invoke the "If table
81 // N is not implemented use table N - 1 behavior.
82 bool hasTable(size_t tableNumber) const;
83 const SimpleTable& getTable(size_t tableNumber) const;
84
85 const SimpleTable& operator[](size_t tableNumber) const
86 {
87 return this->getTable(tableNumber);
88 }
89
90 template <class TableType>
91 const TableType& getTable(size_t tableNumber) const
92 {
93 // This is, strictly speaking, a downcast so we should prefer
94 // dynamic_cast<>() instead. However, serializeOp() by
95 // construction throws away the derived TableType during object
96 // distribution, keeping only the SimpleTable, so dynamic_cast<>
97 // will throw a bad_cast exception on ranks other than the I/O
98 // rank (0). We therefore resort to static_cast<>() here
99 // instead and hope that the caller specifies the correct
100 // derived type...
101 return static_cast<const TableType&>(this->getTable(tableNumber));
102 }
103
104 bool operator==(const TableContainer& data) const;
105
106 template<class Serializer>
107 void serializeOp(Serializer& serializer)
108 {
109 serializer(m_maxTables);
110 serializer(m_tables);
111 }
112
113 private:
114 size_t m_maxTables;
115 TableMap m_tables;
116 };
117
118}
119
120#endif // OPM_TABLE_CONTAINER_HPP
Class for (de-)serializing.
Definition Serializer.hpp:94
Definition SimpleTable.hpp:35
The TableContainer class implements a simple map:
Definition TableContainer.hpp:61
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30