/* 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 . */ #ifndef OPM_TABLE_CONTAINER_HPP #define OPM_TABLE_CONTAINER_HPP #include #include #include 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 table0 = std::make_shared(...); 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 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 const TableType& getTable(size_t tableNumber) const { const SimpleTable &simpleTable = getTable( tableNumber ); const TableType * table = static_cast( &simpleTable ); return *table; } private: size_t m_maxTables; std::map > m_tables; }; } #endif