Files
opm-common/opm/parser/eclipse/EclipseState/Tables/TableContainer.hpp
Jørgen Kvalsvik f404828d63 Cleans up headers to improve build preformance
This is an effort to improve build performance.  Several includes
scattered across the project are either unused or partially used (i.e.
just used to import a type name, not depending on the actual contents of
the header file).

Replaces a lot of these includes with forward declarations.
2016-01-21 09:22:06 +01:00

96 lines
2.9 KiB
C++

/*
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 {
/*
The TableContainer class implements a simple map:
{tableNumber , Table}. The main functionality of the
TableContainer class is that the getTable method implements
the Eclipse behavior:
If table N is not implemented - use table N - 1.
The getTable() method will eventually throw an exception if
not even table 0 is there.
Consider the following code:
TableContainer container(10);
std::shared_ptr<TableType> table0 = std::make_shared<TableType>(...);
container.addTable( table0 , 0 )
We create a container with maximum 10 tables, and then we add
one single table at slot 0; then we have:
container.size() == 1
container.hasTable( 0 ) == true
container.hasTable( 9 ) == false
container.hasTable(10 ) == false
container.getTable( 0 ) == container[9] == table0;
container.gteTable(10 ) ==> exception
*/
public:
explicit TableContainer( size_t maxTables );
bool empty() const;
/*
This is the number of actual tables in the container.
*/
size_t size() const;
void addTable(size_t tableNumber , std::shared_ptr<const SimpleTable> table);
/*
Observe that the hasTable() method does not invoke the "If
table N is not implemented use table N - 1 behavior.
*/
size_t hasTable(size_t tableNumber) const;
const SimpleTable& getTable(size_t tableNumber) const;
const SimpleTable& operator[](size_t tableNumber) const;
template <class TableType>
const TableType& getTable(size_t tableNumber) const {
const SimpleTable &simpleTable = getTable( tableNumber );
const TableType * table = static_cast<const TableType *>( &simpleTable );
return *table;
}
private:
size_t m_maxTables;
std::map<size_t , std::shared_ptr<const SimpleTable> > m_tables;
};
}
#endif