diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt index fcc4113fc..5a221198b 100644 --- a/opm/parser/eclipse/CMakeLists.txt +++ b/opm/parser/eclipse/CMakeLists.txt @@ -114,6 +114,7 @@ EclipseState/Tables/VFPInjTable.cpp EclipseState/Tables/TableManager.cpp EclipseState/Tables/TableContainer.cpp EclipseState/Tables/ColumnSchema.cpp +EclipseState/Tables/TableSchema.cpp EclipseState/Tables/TableIndex.cpp # EclipseState/Grid/GridProperty.cpp diff --git a/opm/parser/eclipse/EclipseState/Tables/TableSchema.cpp b/opm/parser/eclipse/EclipseState/Tables/TableSchema.cpp new file mode 100644 index 000000000..c7d5585eb --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Tables/TableSchema.cpp @@ -0,0 +1,50 @@ +/* + 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 . + */ +#include + +#include + +namespace Opm { + + TableSchema::TableSchema() + { + + } + + void TableSchema::addColumn(const ColumnSchema& column) { + m_columns.insert( column.name() , column ); + } + + + const ColumnSchema&& TableSchema::getColumn( const std::string& name ) const { + return std::forward( m_columns.get( name ) ); + } + + const ColumnSchema&& TableSchema::getColumn( size_t columnIndex ) const { + return std::forward( m_columns.get( columnIndex) ); + } + + size_t TableSchema::size() const { + return m_columns.size(); + } + +} + + + diff --git a/opm/parser/eclipse/EclipseState/Tables/TableSchema.hpp b/opm/parser/eclipse/EclipseState/Tables/TableSchema.hpp new file mode 100644 index 000000000..375d27e91 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Tables/TableSchema.hpp @@ -0,0 +1,48 @@ +/* + 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 _TABLE_SCHEMA_HPP_ +#define _TABLE_SCHEMA_HPP_ + +#include +#include + +#include + +#include + +namespace Opm { + + class TableSchema { + public: + TableSchema(); + void addColumn(const ColumnSchema& column); + const ColumnSchema&& getColumn( const std::string& name ) const; + const ColumnSchema&& getColumn( size_t columnIndex ) const; + + /* Number of columns */ + size_t size() const; + private: + OrderedMap m_columns; + }; +} + +#endif + diff --git a/opm/parser/eclipse/EclipseState/Tables/tests/CMakeLists.txt b/opm/parser/eclipse/EclipseState/Tables/tests/CMakeLists.txt index 9f19198d6..2e81778cf 100644 --- a/opm/parser/eclipse/EclipseState/Tables/tests/CMakeLists.txt +++ b/opm/parser/eclipse/EclipseState/Tables/tests/CMakeLists.txt @@ -1,5 +1,6 @@ foreach(tapp TableManagerTests TabdimsTests TableContainerTests - ColumnSchemaTests) + ColumnSchemaTests + TableSchemaTests) opm_add_test(run${tapp} SOURCES ${tapp}.cpp LIBRARIES opmparser ${Boost_LIBRARIES}) diff --git a/opm/parser/eclipse/EclipseState/Tables/tests/TableSchemaTests.cpp b/opm/parser/eclipse/EclipseState/Tables/tests/TableSchemaTests.cpp new file mode 100644 index 000000000..4c8893018 --- /dev/null +++ b/opm/parser/eclipse/EclipseState/Tables/tests/TableSchemaTests.cpp @@ -0,0 +1,49 @@ +/* + Copyright (C) 2015 by 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 . + */ + +#define BOOST_TEST_MODULE TableSchemaTests + +#include +#include +#include + + +#include +#include +#include + +using namespace Opm; + + +BOOST_AUTO_TEST_CASE( CreateTest ) { + TableSchema schema; + ColumnSchema col1("Name1" , Table::INCREASING , Table::DEFAULT_NONE); + ColumnSchema col2("Name2" , Table::INCREASING , Table::DEFAULT_NONE); + BOOST_CHECK_EQUAL( 0 , schema.size( ) ); + + schema.addColumn( col1 ); + BOOST_CHECK_EQUAL( 1 , schema.size( ) ); + + schema.addColumn( col2 ); + BOOST_CHECK_EQUAL( 2 , schema.size( ) ); + + BOOST_CHECK_THROW( schema.getColumn( "NO/NOT/THIS/COLUMN" ) , std::invalid_argument ); + BOOST_CHECK_THROW( schema.getColumn( 5 ) , std::invalid_argument ); +} +