Loading...
Searching...
No Matches
TableContainer.hpp
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_TABLE_CONTAINER_HPP
#define OPM_TABLE_CONTAINER_HPP
#include <cstddef>
#include <map>
#include <memory>
namespace Opm {
class SimpleTable;
class TableContainer
{
public:
using TableMap = std::map<size_t, std::shared_ptr<SimpleTable>>;
TableContainer();
explicit TableContainer(size_t maxTables);
static TableContainer serializationTestObject();
bool empty() const;
// This is the number of actual tables in the container.
size_t size() const;
size_t max() const;
const TableMap& tables() const;
void addTable(size_t tableNumber, std::shared_ptr<SimpleTable> table);
// Observe that the hasTable() method does not invoke the "If table
// N is not implemented use table N - 1 behavior.
bool hasTable(size_t tableNumber) const;
const SimpleTable& getTable(size_t tableNumber) const;
const SimpleTable& operator[](size_t tableNumber) const
{
return this->getTable(tableNumber);
}
template <class TableType>
const TableType& getTable(size_t tableNumber) const
{
// This is, strictly speaking, a downcast so we should prefer
// dynamic_cast<>() instead. However, serializeOp() by
// construction throws away the derived TableType during object
// distribution, keeping only the SimpleTable, so dynamic_cast<>
// will throw a bad_cast exception on ranks other than the I/O
// rank (0). We therefore resort to static_cast<>() here
// instead and hope that the caller specifies the correct
// derived type...
return static_cast<const TableType&>(this->getTable(tableNumber));
}
bool operator==(const TableContainer& data) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(m_maxTables);
serializer(m_tables);
}
private:
size_t m_maxTables;
TableMap m_tables;
};
}
#endif // OPM_TABLE_CONTAINER_HPP
Opm::Serializer
Class for (de-)serializing.
Definition Serializer.hpp:94
Opm::SimpleTable
Definition SimpleTable.hpp:35
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30