Added class TableSchema with table metadata.

This commit is contained in:
Joakim Hove
2015-12-21 15:00:40 +01:00
parent e94d01e88c
commit 5e469c0676
5 changed files with 150 additions and 1 deletions

View File

@@ -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

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <utility>
#include <opm/parser/eclipse/EclipseState/Tables/TableSchema.hpp>
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<const ColumnSchema>( m_columns.get( name ) );
}
const ColumnSchema&& TableSchema::getColumn( size_t columnIndex ) const {
return std::forward<const ColumnSchema>( m_columns.get( columnIndex) );
}
size_t TableSchema::size() const {
return m_columns.size();
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef _TABLE_SCHEMA_HPP_
#define _TABLE_SCHEMA_HPP_
#include <string>
#include <vector>
#include <opm/parser/eclipse/EclipseState/Util/OrderedMap.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/ColumnSchema.hpp>
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<ColumnSchema> m_columns;
};
}
#endif

View File

@@ -1,5 +1,6 @@
foreach(tapp TableManagerTests TabdimsTests TableContainerTests
ColumnSchemaTests)
ColumnSchemaTests
TableSchemaTests)
opm_add_test(run${tapp} SOURCES ${tapp}.cpp
LIBRARIES opmparser ${Boost_LIBRARIES})

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE TableSchemaTests
#include <opm/common/utility/platform_dependent/disable_warnings.h>
#include <boost/test/unit_test.hpp>
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
#include <opm/parser/eclipse/EclipseState/Tables/TableSchema.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/ColumnSchema.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/TableEnums.hpp>
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 );
}