Merge pull request #950 from jokva/stack-allocd-items
Stack allocd items
This commit is contained in:
@@ -44,9 +44,6 @@ Parser/ParserKeyword.cpp
|
||||
Parser/Parser.cpp
|
||||
Parser/ParserRecord.cpp
|
||||
Parser/ParserItem.cpp
|
||||
Parser/ParserIntItem.cpp
|
||||
Parser/ParserDoubleItem.cpp
|
||||
Parser/ParserStringItem.cpp
|
||||
)
|
||||
|
||||
set( generator_source
|
||||
@@ -60,9 +57,6 @@ Parser/ParserEnums.cpp
|
||||
Parser/ParserKeyword.cpp
|
||||
Parser/ParserRecord.cpp
|
||||
Parser/ParserItem.cpp
|
||||
Parser/ParserIntItem.cpp
|
||||
Parser/ParserDoubleItem.cpp
|
||||
Parser/ParserStringItem.cpp
|
||||
${generator_source}
|
||||
)
|
||||
|
||||
@@ -156,9 +150,6 @@ Parser/ParserKeyword.hpp
|
||||
Parser/Parser.hpp
|
||||
Parser/ParserRecord.hpp
|
||||
Parser/ParserItem.hpp
|
||||
Parser/ParserIntItem.hpp
|
||||
Parser/ParserDoubleItem.hpp
|
||||
Parser/ParserStringItem.hpp
|
||||
Parser/InputErrorAction.hpp
|
||||
Parser/ParseContext.hpp
|
||||
Parser/MessageContainer.hpp
|
||||
@@ -201,9 +192,8 @@ EclipseState/Schedule/GroupTree.hpp
|
||||
EclipseState/Schedule/Tuning.hpp
|
||||
EclipseState/Schedule/Events.hpp
|
||||
#
|
||||
EclipseState/Util/RecordVector.hpp
|
||||
EclipseState/Util/OrderedMap.hpp
|
||||
EclipseState/Util/Value.hpp
|
||||
EclipseState/Util/OrderedMap.hpp
|
||||
EclipseState/Util/Value.hpp
|
||||
#
|
||||
EclipseState/Grid/Box.hpp
|
||||
EclipseState/Grid/BoxManager.hpp
|
||||
|
||||
@@ -26,367 +26,211 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
template< typename T >
|
||||
class DeckTypeItem : public DeckItemBase {
|
||||
public:
|
||||
const std::string& name() const override;
|
||||
bool defaultApplied( size_t ) const override;
|
||||
bool hasValue( size_t ) const override;
|
||||
size_t size() const override;
|
||||
template< typename T >
|
||||
std::vector< T >& DeckItem::value_ref() {
|
||||
return const_cast< std::vector< T >& >(
|
||||
const_cast< const DeckItem& >( *this ).value_ref< T >()
|
||||
);
|
||||
}
|
||||
|
||||
void push_back( T );
|
||||
void push_back( T, size_t numValues );
|
||||
void push_backDefault( T );
|
||||
void push_backDummyDefault() override;
|
||||
template<>
|
||||
const std::vector< int >& DeckItem::value_ref< int >() const {
|
||||
if( this->type != get_type< int >() )
|
||||
throw std::invalid_argument( "Item of wrong type." );
|
||||
|
||||
const T& get( size_t ) const;
|
||||
const std::vector< T >& getData() const;
|
||||
return this->ival;
|
||||
}
|
||||
|
||||
protected:
|
||||
DeckTypeItem( const std::string&, size_t );
|
||||
template<>
|
||||
const std::vector< double >& DeckItem::value_ref< double >() const {
|
||||
if( this->type != get_type< double >() )
|
||||
throw std::invalid_argument( "Item of wrong type." );
|
||||
|
||||
private:
|
||||
std::string item_name;
|
||||
std::vector< bool > dataPointDefaulted;
|
||||
std::vector< T > data;
|
||||
};
|
||||
return this->dval;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
class DeckItemT : public DeckTypeItem< T > {
|
||||
private:
|
||||
using DeckTypeItem< T >::DeckTypeItem;
|
||||
std::unique_ptr< DeckItemBase > clone() const override;
|
||||
template<>
|
||||
const std::vector< std::string >& DeckItem::value_ref< std::string >() const {
|
||||
if( this->type != get_type< std::string >() )
|
||||
throw std::invalid_argument( "Item of wrong type." );
|
||||
|
||||
friend class DeckItem;
|
||||
};
|
||||
return this->sval;
|
||||
}
|
||||
|
||||
template<>
|
||||
class DeckItemT< double > : public DeckTypeItem< double > {
|
||||
public:
|
||||
using DeckTypeItem< double >::DeckTypeItem;
|
||||
DeckItem::DeckItem( const std::string& nm ) : item_name( nm ) {}
|
||||
|
||||
const double& getSI( size_t ) const;
|
||||
const std::vector< double >& getSIData() const;
|
||||
DeckItem::DeckItem( const std::string& nm, int, size_t hint ) :
|
||||
type( get_type< int >() ),
|
||||
item_name( nm )
|
||||
{
|
||||
this->ival.reserve( hint );
|
||||
this->defaulted.reserve( hint );
|
||||
}
|
||||
|
||||
void push_backDimension( const Dimension& activeDimension,
|
||||
const Dimension& defaultDimension );
|
||||
DeckItem::DeckItem( const std::string& nm, double, size_t hint ) :
|
||||
type( get_type< double >() ),
|
||||
item_name( nm )
|
||||
{
|
||||
this->dval.reserve( hint );
|
||||
this->defaulted.reserve( hint );
|
||||
}
|
||||
|
||||
private:
|
||||
const std::vector< double >& assertSIData() const;
|
||||
std::unique_ptr< DeckItemBase > clone() const override;
|
||||
DeckItem::DeckItem( const std::string& nm, std::string, size_t hint ) :
|
||||
type( get_type< std::string >() ),
|
||||
item_name( nm )
|
||||
{
|
||||
this->sval.reserve( hint );
|
||||
this->defaulted.reserve( hint );
|
||||
}
|
||||
|
||||
mutable std::vector< double > SIdata;
|
||||
std::vector< Dimension > dimensions;
|
||||
const std::string& DeckItem::name() const {
|
||||
return this->item_name;
|
||||
}
|
||||
|
||||
friend class DeckItem;
|
||||
};
|
||||
bool DeckItem::defaultApplied( size_t index ) const {
|
||||
return this->defaulted.at( index );
|
||||
}
|
||||
|
||||
template< typename T > static inline DeckItem::type type_to_tag();
|
||||
template<>
|
||||
DeckItem::type type_to_tag< int >() {
|
||||
return DeckItem::integer;
|
||||
bool DeckItem::hasValue( size_t index ) const {
|
||||
switch( this->type ) {
|
||||
case type_tag::integer: return this->ival.size() > index;
|
||||
case type_tag::fdouble: return this->dval.size() > index;
|
||||
case type_tag::string: return this->sval.size() > index;
|
||||
default: throw std::logic_error( "Type not set." );
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
DeckItem::type type_to_tag< double >() {
|
||||
return DeckItem::fdouble;
|
||||
size_t DeckItem::size() const {
|
||||
switch( this->type ) {
|
||||
case type_tag::integer: return this->ival.size();
|
||||
case type_tag::fdouble: return this->dval.size();
|
||||
case type_tag::string: return this->sval.size();
|
||||
default: throw std::logic_error( "Type not set." );
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
DeckItem::type type_to_tag< std::string >() {
|
||||
return DeckItem::string;
|
||||
}
|
||||
template< typename T >
|
||||
const T& DeckItem::get( size_t index ) const {
|
||||
return this->value_ref< T >().at( index );
|
||||
}
|
||||
|
||||
static inline std::string tag_to_string( DeckItem::type x ) {
|
||||
switch( x ) {
|
||||
case DeckItem::type::integer: return "int";
|
||||
case DeckItem::type::string: return "std::string";
|
||||
case DeckItem::type::fdouble: return "double";
|
||||
case DeckItem::type::unknown: return "unknown";
|
||||
template< typename T >
|
||||
const std::vector< T >& DeckItem::getData() const {
|
||||
return this->value_ref< T >();
|
||||
}
|
||||
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
template< typename T >
|
||||
void DeckItem::push( T x, size_t n ) {
|
||||
auto& val = this->value_ref< T >();
|
||||
|
||||
val.insert( val.end(), n, x );
|
||||
this->defaulted.insert( this->defaulted.end(), n, false );
|
||||
}
|
||||
|
||||
void DeckItem::push_back( int x, size_t n ) {
|
||||
this->push( x, n );
|
||||
}
|
||||
|
||||
void DeckItem::push_back( double x, size_t n ) {
|
||||
this->push( x, n );
|
||||
}
|
||||
|
||||
void DeckItem::push_back( std::string x, size_t n ) {
|
||||
this->push( std::move( x ), n );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void DeckItem::push_default( T x ) {
|
||||
auto& val = this->value_ref< T >();
|
||||
if( this->defaulted.size() != val.size() )
|
||||
throw std::logic_error("To add a value to an item, "
|
||||
"no 'pseudo defaults' can be added before");
|
||||
|
||||
val.push_back( std::move( x ) );
|
||||
this->defaulted.push_back( true );
|
||||
}
|
||||
|
||||
void DeckItem::push_backDefault( int x ) {
|
||||
this->push_default( x );
|
||||
}
|
||||
|
||||
void DeckItem::push_backDefault( double x ) {
|
||||
this->push_default( x );
|
||||
}
|
||||
|
||||
void DeckItem::push_backDefault( std::string x ) {
|
||||
this->push_default( std::move( x ) );
|
||||
}
|
||||
|
||||
|
||||
template< typename T >
|
||||
DeckTypeItem< T >::DeckTypeItem( const std::string& nm, size_t sz ) :
|
||||
DeckItemBase( type_to_tag< T >() ),
|
||||
item_name( nm )
|
||||
{
|
||||
this->dataPointDefaulted.reserve( sz );
|
||||
this->data.reserve( sz );
|
||||
}
|
||||
void DeckItem::push_backDummyDefault() {
|
||||
if( !this->defaulted.empty() )
|
||||
throw std::logic_error("Pseudo defaults can only be specified for empty items");
|
||||
|
||||
template< typename T >
|
||||
const std::string& DeckTypeItem< T >::name() const {
|
||||
return this->item_name;
|
||||
}
|
||||
this->defaulted.push_back( true );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
bool DeckTypeItem< T >::defaultApplied( size_t index ) const {
|
||||
return this->dataPointDefaulted.at( index );
|
||||
}
|
||||
std::string DeckItem::getTrimmedString( size_t index ) const {
|
||||
return boost::algorithm::trim_copy(
|
||||
this->value_ref< std::string >().at( index )
|
||||
);
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
bool DeckTypeItem< T >::hasValue( size_t index ) const {
|
||||
return index < this->size();
|
||||
}
|
||||
double DeckItem::getSIDouble( size_t index ) const {
|
||||
return this->getSIDoubleData().at( index );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
size_t DeckTypeItem< T >::size() const {
|
||||
return this->data.size();
|
||||
}
|
||||
const std::vector< double >& DeckItem::getSIDoubleData() const {
|
||||
const auto& raw = this->value_ref< double >();
|
||||
// we already converted this item to SI?
|
||||
if( !this->SIdata.empty() ) return this->SIdata;
|
||||
|
||||
template< typename T >
|
||||
void DeckTypeItem< T >::push_back( T x ) {
|
||||
if( this->dataPointDefaulted.size() != this->data.size() )
|
||||
throw std::logic_error("To add a value to an item, no \"pseudo defaults\" can be added before");
|
||||
|
||||
this->data.push_back( x );
|
||||
this->dataPointDefaulted.push_back( false );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void DeckTypeItem< T >::push_backDefault( T data_arg ) {
|
||||
if( this->dataPointDefaulted.size() != this->data.size() )
|
||||
throw std::logic_error("To add a value to an item, no \"pseudo defaults\" can be added before");
|
||||
|
||||
this->data.push_back( data_arg );
|
||||
this->dataPointDefaulted.push_back(true);
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void DeckTypeItem< T >::push_backDummyDefault() {
|
||||
if( this->dataPointDefaulted.size() != 0 )
|
||||
throw std::logic_error("Pseudo defaults can only be specified for empty items");
|
||||
|
||||
this->dataPointDefaulted.push_back( true );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void DeckTypeItem< T >::push_back( T x, size_t numValues ) {
|
||||
if( this->dataPointDefaulted.size() != this->data.size() )
|
||||
throw std::logic_error("To add a value to an item, no \"pseudo defaults\" can be added before");
|
||||
|
||||
this->data.insert( this->data.end(), numValues, x );
|
||||
this->dataPointDefaulted.insert( this->dataPointDefaulted.end(), numValues, false );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
const T& DeckTypeItem< T >::get( size_t index ) const {
|
||||
return this->data.at( index );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
const std::vector< T >& DeckTypeItem< T >::getData() const {
|
||||
return this->data;
|
||||
}
|
||||
|
||||
const double& DeckItemT< double >::getSI( size_t index ) const {
|
||||
return this->assertSIData().at( index );
|
||||
}
|
||||
|
||||
const std::vector< double >& DeckItemT< double >::getSIData() const {
|
||||
return this->assertSIData();
|
||||
}
|
||||
|
||||
void DeckItemT< double >::push_backDimension( const Dimension& activeDimension,
|
||||
const Dimension& defaultDimension ) {
|
||||
|
||||
if( this->size() == 0 || this->defaultApplied( this->size() - 1 ) )
|
||||
this->dimensions.push_back( defaultDimension );
|
||||
else
|
||||
this->dimensions.push_back( activeDimension );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
std::unique_ptr< DeckItemBase > DeckItemT< T >::clone() const {
|
||||
return std::unique_ptr< DeckItemBase > { new DeckItemT< T >( *this ) };
|
||||
}
|
||||
|
||||
std::unique_ptr< DeckItemBase > DeckItemT< double >::clone() const {
|
||||
return std::unique_ptr< DeckItemBase > { new DeckItemT< double >( *this ) };
|
||||
}
|
||||
|
||||
const std::vector< double >& DeckItemT< double >::assertSIData() const {
|
||||
// we already converted this item to SI?
|
||||
if( !this->SIdata.empty() ) return this->SIdata;
|
||||
|
||||
if( this->dimensions.empty() )
|
||||
throw std::invalid_argument("No dimension has been set for item:" + this->name() + " can not ask for SI data");
|
||||
|
||||
/*
|
||||
* This is an unobservable state change - SIData is lazily converted to
|
||||
* SI units, so externally the object still behaves as const
|
||||
*/
|
||||
const auto dim_size = dimensions.size();
|
||||
const auto sz = this->size();
|
||||
this->SIdata.resize( sz );
|
||||
|
||||
for( size_t index = 0; index < sz; index++ ) {
|
||||
const auto dimIndex = index % dim_size;
|
||||
this->SIdata[ index ] = this->dimensions[ dimIndex ]
|
||||
.convertRawToSi( this->get( index ) );
|
||||
}
|
||||
|
||||
return this->SIdata;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
static inline DeckItemT< T >* conv( std::unique_ptr< DeckItemBase >& ptr ) {
|
||||
if( ptr->type_tag == type_to_tag< T >() )
|
||||
return static_cast< DeckItemT< T >* >( ptr.get() );
|
||||
|
||||
throw std::logic_error(
|
||||
"Treating item " + ptr->name()
|
||||
+ " as " + tag_to_string( type_to_tag< T >() )
|
||||
+ ", but is "
|
||||
+ tag_to_string( ptr->type_tag ) );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
static inline
|
||||
const DeckItemT< T >* conv( const std::unique_ptr< DeckItemBase >& ptr ) {
|
||||
if( ptr->type_tag == type_to_tag< T >() )
|
||||
return static_cast< const DeckItemT< T >* >( ptr.get() );
|
||||
|
||||
throw std::logic_error(
|
||||
"Treating item " + ptr->name()
|
||||
+ " as " + tag_to_string( type_to_tag< T >() )
|
||||
+ ", but is "
|
||||
+ tag_to_string( ptr->type_tag ) );
|
||||
}
|
||||
|
||||
DeckItem::DeckItem( const DeckItem& rhs ) :
|
||||
ptr( rhs.ptr->clone() )
|
||||
{}
|
||||
|
||||
DeckItem::DeckItem( std::unique_ptr< DeckItemBase >&& x ) :
|
||||
ptr( std::move( x ) )
|
||||
{}
|
||||
|
||||
template< typename T >
|
||||
DeckItem DeckItem::make( const std::string& name, size_t size ) {
|
||||
return DeckItem( std::unique_ptr< DeckItemBase > { new DeckItemT< T >( name, size ) } );
|
||||
}
|
||||
|
||||
const std::string& DeckItem::name() const {
|
||||
return this->ptr->name();
|
||||
}
|
||||
|
||||
bool DeckItem::defaultApplied( size_t index ) const {
|
||||
return this->ptr->defaultApplied( index );
|
||||
}
|
||||
|
||||
bool DeckItem::hasValue( size_t index ) const {
|
||||
return this->ptr->hasValue( index );
|
||||
}
|
||||
|
||||
size_t DeckItem::size() const {
|
||||
return this->ptr->size();
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
const T& DeckItem::get( size_t index ) const {
|
||||
return conv< T >( this->ptr )->get( index );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
const std::vector< T >& DeckItem::getData() const {
|
||||
return conv< T >( this->ptr )->getData();
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void DeckItem::push_back( T x ) {
|
||||
return conv< T >( this->ptr )->push_back( x );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void DeckItem::push_back( T x, size_t n ) {
|
||||
return conv< T >( this->ptr )->push_back( x, n );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void DeckItem::push_backDefault( T x ) {
|
||||
return conv< T >( this->ptr )->push_backDefault( x );
|
||||
}
|
||||
|
||||
template<>
|
||||
void DeckItem::push_back( const char* x ) {
|
||||
return conv< std::string >( this->ptr )->push_back( x );
|
||||
}
|
||||
|
||||
template<>
|
||||
void DeckItem::push_back( const char* x, size_t n ) {
|
||||
return conv< std::string >( this->ptr )->push_back( x, n );
|
||||
}
|
||||
|
||||
template<>
|
||||
void DeckItem::push_backDefault( const char* x ) {
|
||||
return conv< std::string >( this->ptr )->push_backDefault( x );
|
||||
}
|
||||
|
||||
void DeckItem::push_backDummyDefault() {
|
||||
return this->ptr->push_backDummyDefault();
|
||||
}
|
||||
|
||||
std::string DeckItem::getTrimmedString( size_t index ) const {
|
||||
return boost::algorithm::trim_copy(
|
||||
conv< std::string >( this->ptr )->get( index )
|
||||
);
|
||||
}
|
||||
|
||||
double DeckItem::getSIDouble( size_t index ) const {
|
||||
return conv< double >( this->ptr )->getSI( index );
|
||||
}
|
||||
|
||||
const std::vector< double >& DeckItem::getSIDoubleData() const {
|
||||
return conv< double >( this->ptr )->getSIData();
|
||||
}
|
||||
|
||||
void DeckItem::push_backDimension( Dimension active,
|
||||
Dimension def ) {
|
||||
return conv< double >( this->ptr ) ->push_backDimension( active, def );
|
||||
}
|
||||
|
||||
DeckItem::type DeckItem::getType() const {
|
||||
return this->ptr->type_tag;
|
||||
}
|
||||
if( this->dimensions.empty() )
|
||||
throw std::invalid_argument("No dimension has been set for item'"
|
||||
+ this->name()
|
||||
+ "'; can not ask for SI data");
|
||||
|
||||
/*
|
||||
* Explicit template instantiations. These must be manually maintained and
|
||||
* updated with changes in DeckItem so that code is emitted.
|
||||
* This is an unobservable state change - SIData is lazily converted to
|
||||
* SI units, so externally the object still behaves as const
|
||||
*/
|
||||
const auto dim_size = dimensions.size();
|
||||
const auto sz = raw.size();
|
||||
this->SIdata.resize( sz );
|
||||
|
||||
template class DeckTypeItem< int >;
|
||||
template class DeckTypeItem< double >;
|
||||
template class DeckTypeItem< std::string >;
|
||||
for( size_t index = 0; index < sz; index++ ) {
|
||||
const auto dimIndex = index % dim_size;
|
||||
this->SIdata[ index ] = this->dimensions[ dimIndex ]
|
||||
.convertRawToSi( raw[ index ] );
|
||||
}
|
||||
|
||||
template class DeckItemT< int >;
|
||||
template class DeckItemT< double >;
|
||||
template class DeckItemT< std::string >;
|
||||
return this->SIdata;
|
||||
}
|
||||
|
||||
template DeckItem DeckItem::make< int >( const std::string&, size_t );
|
||||
template DeckItem DeckItem::make< double >( const std::string&, size_t );
|
||||
template DeckItem DeckItem::make< std::string >( const std::string&, size_t );
|
||||
void DeckItem::push_backDimension( const Dimension& active,
|
||||
const Dimension& def ) {
|
||||
const auto& ds = this->value_ref< double >();
|
||||
const bool dim_inactive = ds.empty()
|
||||
|| this->defaultApplied( ds.size() - 1 );
|
||||
|
||||
template const int& DeckItem::get< int >( size_t ) const;
|
||||
template const double& DeckItem::get< double >( size_t ) const;
|
||||
template const std::string& DeckItem::get< std::string >( size_t ) const;
|
||||
this->dimensions.push_back( dim_inactive ? def : active );
|
||||
}
|
||||
|
||||
template const std::vector< int >& DeckItem::getData< int >() const;
|
||||
template const std::vector< double >& DeckItem::getData< double >() const;
|
||||
template const std::vector< std::string >& DeckItem::getData< std::string >() const;
|
||||
type_tag DeckItem::getType() const {
|
||||
return this->type;
|
||||
}
|
||||
|
||||
template void DeckItem::push_back< int >( int );
|
||||
template void DeckItem::push_back< double >( double );
|
||||
template void DeckItem::push_back< std::string >( std::string );
|
||||
template void DeckItem::push_back< int >( int, size_t );
|
||||
template void DeckItem::push_back< double >( double, size_t );
|
||||
template void DeckItem::push_back< std::string >( std::string, size_t );
|
||||
template void DeckItem::push_backDefault< int >( int );
|
||||
template void DeckItem::push_backDefault< double >( double );
|
||||
template void DeckItem::push_backDefault< std::string >( std::string );
|
||||
/*
|
||||
* Explicit template instantiations. These must be manually maintained and
|
||||
* updated with changes in DeckItem so that code is emitted.
|
||||
*/
|
||||
|
||||
template const int& DeckItem::get< int >( size_t ) const;
|
||||
template const double& DeckItem::get< double >( size_t ) const;
|
||||
template const std::string& DeckItem::get< std::string >( size_t ) const;
|
||||
|
||||
template const std::vector< int >& DeckItem::getData< int >() const;
|
||||
template const std::vector< double >& DeckItem::getData< double >() const;
|
||||
template const std::vector< std::string >& DeckItem::getData< std::string >() const;
|
||||
|
||||
}
|
||||
|
||||
@@ -25,29 +25,18 @@
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Units/Dimension.hpp>
|
||||
#include <opm/parser/eclipse/Utility/Typetools.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class DeckItem;
|
||||
class DeckItemBase;
|
||||
|
||||
class DeckItem {
|
||||
public:
|
||||
DeckItem() = delete;
|
||||
DeckItem( const DeckItem& );
|
||||
DeckItem() = default;
|
||||
DeckItem( const std::string& );
|
||||
|
||||
/* for python interop as well as queries, must be manually synchronised
|
||||
* with cdeck_item.cc and opm/deck/item_type_enum.py
|
||||
*/
|
||||
enum type {
|
||||
unknown = 0, /* this signals an error */
|
||||
integer = 1,
|
||||
string = 2,
|
||||
fdouble = 3
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
static DeckItem make( const std::string&, size_t = 1 );
|
||||
DeckItem( const std::string&, int, size_t size_hint = 8 );
|
||||
DeckItem( const std::string&, double, size_t size_hint = 8 );
|
||||
DeckItem( const std::string&, std::string, size_t size_hint = 8 );
|
||||
|
||||
const std::string& name() const;
|
||||
|
||||
@@ -73,40 +62,37 @@ namespace Opm {
|
||||
template< typename T > const std::vector< T >& getData() const;
|
||||
const std::vector< double >& getSIDoubleData() const;
|
||||
|
||||
template< typename T > void push_back( T );
|
||||
template< typename T > void push_back( T, size_t );
|
||||
template< typename T > void push_backDefault( T );
|
||||
void push_back( int, size_t = 1 );
|
||||
void push_back( double, size_t = 1 );
|
||||
void push_back( std::string, size_t = 1 );
|
||||
void push_backDefault( int );
|
||||
void push_backDefault( double );
|
||||
void push_backDefault( std::string );
|
||||
// trying to access the data of a "dummy default item" will raise an exception
|
||||
void push_backDummyDefault();
|
||||
|
||||
void push_backDimension( Dimension /* activeDimension */,
|
||||
Dimension /* defaultDimension */);
|
||||
void push_backDimension( const Dimension& /* activeDimension */,
|
||||
const Dimension& /* defaultDimension */);
|
||||
|
||||
type getType() const;
|
||||
type_tag getType() const;
|
||||
|
||||
private:
|
||||
DeckItem( std::unique_ptr< DeckItemBase >&& );
|
||||
std::unique_ptr< DeckItemBase > ptr;
|
||||
std::vector< double > dval;
|
||||
std::vector< int > ival;
|
||||
std::vector< std::string > sval;
|
||||
|
||||
type_tag type = type_tag::unknown;
|
||||
|
||||
std::string item_name;
|
||||
std::vector< bool > defaulted;
|
||||
std::vector< Dimension > dimensions;
|
||||
mutable std::vector< double > SIdata;
|
||||
|
||||
template< typename T > std::vector< T >& value_ref();
|
||||
template< typename T > const std::vector< T >& value_ref() const;
|
||||
template< typename T > void push( T, size_t );
|
||||
template< typename T > void push_default( T );
|
||||
};
|
||||
|
||||
class DeckItemBase {
|
||||
public:
|
||||
virtual const std::string& name() const = 0;
|
||||
virtual bool defaultApplied( size_t ) const = 0;
|
||||
virtual bool hasValue( size_t ) const = 0;
|
||||
virtual size_t size() const = 0;
|
||||
virtual void push_backDummyDefault() = 0;
|
||||
virtual ~DeckItemBase() = default;
|
||||
const DeckItem::type type_tag;
|
||||
|
||||
protected:
|
||||
DeckItemBase( DeckItem::type tag ) : type_tag( tag ) {}
|
||||
|
||||
private:
|
||||
virtual std::unique_ptr< DeckItemBase > clone() const = 0;
|
||||
friend class DeckItem;
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* DECKITEM_HPP */
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Opm {
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
void DeckRecord::addItem( DeckItem&& deckItem ) {
|
||||
void DeckRecord::addItem( DeckItem deckItem ) {
|
||||
if( this->hasItem( deckItem.name() ) )
|
||||
throw std::invalid_argument(
|
||||
"Item with name: "
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Opm {
|
||||
DeckRecord( std::vector< DeckItem >&& );
|
||||
|
||||
size_t size() const;
|
||||
void addItem( DeckItem&& deckItem );
|
||||
void addItem( DeckItem deckItem );
|
||||
|
||||
DeckItem& getItem( size_t index );
|
||||
DeckItem& getItem( const std::string& name );
|
||||
@@ -47,7 +47,7 @@ namespace Opm {
|
||||
const DeckItem& getDataItem() const;
|
||||
|
||||
bool hasItem(const std::string& name) const;
|
||||
|
||||
|
||||
template <class Item>
|
||||
DeckItem& getItem() {
|
||||
return getItem( Item::itemName );
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeDouble) {
|
||||
BOOST_REQUIRE_NO_THROW( DeckItem::make< double >("HEI") );
|
||||
BOOST_REQUIRE_NO_THROW( DeckItem( "HEI", double() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetDoubleAtIndex_NoData_ExceptionThrown) {
|
||||
auto deckDoubleItem = DeckItem::make< double >("TEST");
|
||||
DeckItem deckDoubleItem( "TEST", double() );
|
||||
|
||||
BOOST_CHECK_THROW(deckDoubleItem.get< double >(0), std::out_of_range);
|
||||
deckDoubleItem.push_back(1.89);
|
||||
@@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(GetDoubleAtIndex_NoData_ExceptionThrown) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(sizeDouble_correct) {
|
||||
auto deckDoubleItem = DeckItem::make< double >("TEST");
|
||||
DeckItem deckDoubleItem( "TEST", double() );
|
||||
|
||||
BOOST_CHECK_EQUAL( 0U , deckDoubleItem.size());
|
||||
deckDoubleItem.push_back( 100.0 );
|
||||
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(sizeDouble_correct) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SetInDeck) {
|
||||
auto deckDoubleItem = DeckItem::make< double >("TEST");
|
||||
DeckItem deckDoubleItem( "TEST", double() );
|
||||
BOOST_CHECK( deckDoubleItem.size() == 0 );
|
||||
|
||||
deckDoubleItem.push_backDefault( 1.0 );
|
||||
@@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(SetInDeck) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DummyDefaults) {
|
||||
auto deckDoubleItem = DeckItem::make< double >("TEST");
|
||||
DeckItem deckDoubleItem( "TEST", double() );
|
||||
BOOST_CHECK_EQUAL(deckDoubleItem.size(), 0);
|
||||
|
||||
deckDoubleItem.push_backDummyDefault();
|
||||
@@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(DummyDefaults) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PushBackMultiple) {
|
||||
auto item = DeckItem::make< double >("HEI");
|
||||
DeckItem item( "HEI", double() );
|
||||
item.push_back(10.22 , 100 );
|
||||
BOOST_CHECK_EQUAL( 100U , item.size() );
|
||||
for (size_t i=0; i < 100; i++)
|
||||
@@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(PushBackMultiple) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PushBackDimension) {
|
||||
auto item = DeckItem::make< double >("HEI");
|
||||
DeckItem item( "HEI", double() );
|
||||
Dimension activeDimension{ "Length" , 100 };
|
||||
Dimension defaultDimension{ "Length" , 10 };
|
||||
|
||||
@@ -104,13 +104,13 @@ BOOST_AUTO_TEST_CASE(PushBackDimension) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PushBackDimensionInvalidType) {
|
||||
auto item = DeckItem::make< int >("HEI");
|
||||
DeckItem item( "HEI", int() );
|
||||
Dimension dim{ "Length" , 100 };
|
||||
BOOST_CHECK_THROW( item.push_backDimension( dim , dim ) , std::logic_error );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetSIWithoutDimensionThrows) {
|
||||
auto item = DeckItem::make< double >("HEI");
|
||||
DeckItem item( "HEI", double() );
|
||||
item.push_back(10.22 , 100 );
|
||||
|
||||
BOOST_CHECK_THROW( item.getSIDouble(0) , std::invalid_argument );
|
||||
@@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(GetSIWithoutDimensionThrows) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetSISingleDimensionCorrect) {
|
||||
auto item = DeckItem::make< double >("HEI");
|
||||
DeckItem item( "HEI", double() );
|
||||
Dimension dim{ "Length" , 100 };
|
||||
|
||||
item.push_back(1.0 , 100 );
|
||||
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(GetSISingleDimensionCorrect) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetSISingleDefault) {
|
||||
auto item = DeckItem::make< double >("HEI");
|
||||
DeckItem item( "HEI", double() );
|
||||
Dimension dim{ "Length" , 1 };
|
||||
Dimension defaultDim{ "Length" , 100 };
|
||||
|
||||
@@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(GetSISingleDefault) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetSIMultipleDim) {
|
||||
auto item = DeckItem::make< double >("HEI");
|
||||
DeckItem item( "HEI", double() );
|
||||
Dimension dim1{ "Length" , 2 };
|
||||
Dimension dim2{ "Length" , 4 };
|
||||
Dimension dim3{ "Length" , 8 };
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
BOOST_REQUIRE_NO_THROW( DeckItem::make< int >("TEST") );
|
||||
BOOST_REQUIRE_NO_THROW( DeckItem m( "TEST", int() ) );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(HasValue) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
BOOST_CHECK_EQUAL( false , deckIntItem.hasValue(0) );
|
||||
deckIntItem.push_back(1);
|
||||
BOOST_CHECK_EQUAL( true , deckIntItem.hasValue(0) );
|
||||
@@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE(HasValue) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DummyDefaults) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
BOOST_CHECK_EQUAL(deckIntItem.size(), 0);
|
||||
|
||||
deckIntItem.push_backDummyDefault();
|
||||
@@ -52,19 +52,19 @@ BOOST_AUTO_TEST_CASE(DummyDefaults) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetIntAtIndex_NoData_ExceptionThrown) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
deckIntItem.push_back(100);
|
||||
BOOST_CHECK(deckIntItem.get< int >(0) == 100);
|
||||
BOOST_CHECK_THROW(deckIntItem.get< int >(1), std::out_of_range);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeDefaultApplied) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
BOOST_CHECK( deckIntItem.size() == 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(size_correct) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
|
||||
BOOST_CHECK_EQUAL( 0U , deckIntItem.size());
|
||||
deckIntItem.push_back( 100 );
|
||||
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(size_correct) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultNotApplied) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
BOOST_CHECK( deckIntItem.size() == 0 );
|
||||
|
||||
deckIntItem.push_back( 100 );
|
||||
@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(DefaultNotApplied) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(UseDefault) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
|
||||
deckIntItem.push_backDefault( 100 );
|
||||
|
||||
@@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(UseDefault) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultApplied) {
|
||||
auto deckIntItem = DeckItem::make< int >("TEST");
|
||||
DeckItem deckIntItem( "TEST", int() );
|
||||
BOOST_CHECK( deckIntItem.size() == 0 );
|
||||
|
||||
deckIntItem.push_backDefault( 100 );
|
||||
@@ -117,12 +117,9 @@ BOOST_AUTO_TEST_CASE(DefaultApplied) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PushBackMultiple) {
|
||||
auto item = DeckItem::make< int >("HEI");
|
||||
DeckItem item( "HEI", int() );
|
||||
item.push_back(10 , 100U );
|
||||
BOOST_CHECK_EQUAL( 100U , item.size() );
|
||||
for (size_t i=0; i < 100; i++)
|
||||
BOOST_CHECK_EQUAL(10 , item.get< int >(i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,15 +26,11 @@
|
||||
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
static DeckItem mkIntItem( std::string name ) {
|
||||
return DeckItem::make< int >( name );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
BOOST_CHECK_NO_THROW(DeckRecord deckRecord);
|
||||
}
|
||||
@@ -46,61 +42,54 @@ BOOST_AUTO_TEST_CASE(size_defaultConstructor_sizezero) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addItem_singleItem_sizeone) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( mkIntItem( "TEST" ) );
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_EQUAL(1U, deckRecord.size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addItem_multipleItems_sizecorrect) {
|
||||
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( mkIntItem( "TEST" ) );
|
||||
deckRecord.addItem( mkIntItem( "TEST2" ) );
|
||||
deckRecord.addItem( mkIntItem( "TEST3" ) );
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
deckRecord.addItem( DeckItem { "TEST2", int() } );
|
||||
deckRecord.addItem( DeckItem { "TEST3", int() } );
|
||||
|
||||
BOOST_CHECK_EQUAL(3U, deckRecord.size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addItem_sameItemTwoTimes_throws) {
|
||||
DeckRecord deckRecord;
|
||||
auto intItem1 = mkIntItem( "TEST" );
|
||||
deckRecord.addItem( std::move( intItem1 ) );
|
||||
BOOST_CHECK_THROW(deckRecord.addItem( std::move( intItem1 ) ), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addItem_differentItemsSameName_throws) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( mkIntItem( "TEST" ) );
|
||||
BOOST_CHECK_THROW( deckRecord.addItem( mkIntItem( "TEST" ) ), std::invalid_argument );
|
||||
std::vector< DeckItem > items = { mkIntItem( "TEST" ), mkIntItem( "TEST" ) };
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_THROW( deckRecord.addItem( DeckItem { "TEST", int() } ), std::invalid_argument );
|
||||
std::vector< DeckItem > items = { DeckItem { "TEST", int() }, DeckItem { "TEST" , int() } };
|
||||
BOOST_CHECK_THROW( DeckRecord( std::move( items ) ), std::invalid_argument );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(get_byIndex_returnsItem) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( mkIntItem( "TEST" ) );
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_NO_THROW(deckRecord.getItem(0U));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(get_indexoutofbounds_throws) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( mkIntItem( "TEST" ) );
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_THROW(deckRecord.getItem(1), std::out_of_range);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(get_byName_returnsItem) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( mkIntItem( "TEST" ) );
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
deckRecord.getItem("TEST");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(get_byNameNonExisting_throws) {
|
||||
DeckRecord deckRecord;
|
||||
deckRecord.addItem( mkIntItem( "TEST" ) );
|
||||
deckRecord.addItem( DeckItem { "TEST", int() } );
|
||||
BOOST_CHECK_THROW(deckRecord.getItem("INVALID"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) {
|
||||
auto itemString = std::make_shared< ParserStringItem >(std::string("STRINGITEM1"));
|
||||
ParserItem itemString("STRINGITEM1", "" );
|
||||
ParserRecord record1;
|
||||
RawRecord rawRecord( " ' VALUE ' " );
|
||||
ParseContext parseContext;
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeString) {
|
||||
auto stringItem = DeckItem::make< std::string >("TEST");
|
||||
DeckItem stringItem("TEST", std::string() );
|
||||
BOOST_CHECK_EQUAL("TEST", stringItem.name());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DummyDefaults) {
|
||||
auto deckStringItem = DeckItem::make< std::string >("TEST");
|
||||
DeckItem deckStringItem("TEST", std::string() );
|
||||
BOOST_CHECK_EQUAL(deckStringItem.size(), 0);
|
||||
|
||||
deckStringItem.push_backDummyDefault();
|
||||
@@ -43,14 +43,14 @@ BOOST_AUTO_TEST_CASE(DummyDefaults) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GetStringAtIndex_NoData_ExceptionThrown) {
|
||||
auto deckStringItem = DeckItem::make< std::string >("TEST");
|
||||
DeckItem deckStringItem( "TEST", std::string() );
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(0), std::out_of_range);
|
||||
deckStringItem.push_back("SA");
|
||||
BOOST_CHECK_THROW(deckStringItem.get< std::string >(1), std::out_of_range);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(size_variouspushes_sizecorrect) {
|
||||
auto deckStringItem = DeckItem::make< std::string >("TEST");
|
||||
DeckItem deckStringItem( "TEST", std::string() );
|
||||
|
||||
BOOST_CHECK_EQUAL(0U, deckStringItem.size());
|
||||
deckStringItem.push_back("WELL-3");
|
||||
@@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(size_variouspushes_sizecorrect) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultNotApplied) {
|
||||
auto deckStringItem = DeckItem::make< std::string >("TEST");
|
||||
DeckItem deckStringItem( "TEST", std::string() );
|
||||
BOOST_CHECK( deckStringItem.size() == 0 );
|
||||
|
||||
deckStringItem.push_back( "FOO") ;
|
||||
@@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(DefaultNotApplied) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultApplied) {
|
||||
auto deckStringItem = DeckItem::make< std::string >("TEST");
|
||||
DeckItem deckStringItem( "TEST", std::string() );
|
||||
BOOST_CHECK( deckStringItem.size() == 0 );
|
||||
|
||||
deckStringItem.push_backDefault( "FOO" );
|
||||
@@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(DefaultApplied) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PushBackMultiple) {
|
||||
auto stringItem = DeckItem::make< std::string >("HEI");
|
||||
DeckItem stringItem( "TEST", std::string() );
|
||||
stringItem.push_back("Heisann ", 100U );
|
||||
BOOST_CHECK_EQUAL( 100U , stringItem.size() );
|
||||
for (size_t i=0; i < 100; i++)
|
||||
|
||||
@@ -249,9 +249,9 @@ static Deck deckWithGRUPTREE() {
|
||||
DeckKeyword gruptreeKeyword("GRUPTREE");
|
||||
|
||||
DeckRecord recordChildOfField;
|
||||
auto itemChild1 = DeckItem::make< std::string >( "CHILD_GROUP" );
|
||||
DeckItem itemChild1( "CHILD_GROUP", std::string() );
|
||||
itemChild1.push_back(std::string("BARNET"));
|
||||
auto itemParent1 = DeckItem::make< std::string >( "PARENT_GROUP" );
|
||||
DeckItem itemParent1( "PARENT_GROUP", std::string() );
|
||||
itemParent1.push_back(std::string("FAREN"));
|
||||
|
||||
recordChildOfField.addItem( std::move( itemChild1 ) );
|
||||
|
||||
@@ -103,11 +103,11 @@ BOOST_AUTO_TEST_CASE(AddStepSizeCorrect) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( dateFromEclipseThrowsInvalidRecord ) {
|
||||
Opm::DeckRecord startRecord;
|
||||
auto dayItem = Opm::DeckItem::make< int >("DAY");
|
||||
auto monthItem = Opm::DeckItem::make< std::string >("MONTH");
|
||||
auto yearItem = Opm::DeckItem::make< int >("YEAR");
|
||||
auto timeItem = Opm::DeckItem::make< std::string >("TIME");
|
||||
auto extraItem = Opm::DeckItem::make< int >("EXTRA");
|
||||
Opm::DeckItem dayItem("DAY", int() );
|
||||
Opm::DeckItem monthItem("MONTH", std::string() );
|
||||
Opm::DeckItem yearItem("YEAR", int() );
|
||||
Opm::DeckItem timeItem("TIME", std::string() );
|
||||
Opm::DeckItem extraItem("EXTRA", int() );
|
||||
|
||||
dayItem.push_back( 10 );
|
||||
yearItem.push_back(1987 );
|
||||
@@ -116,19 +116,19 @@ BOOST_AUTO_TEST_CASE( dateFromEclipseThrowsInvalidRecord ) {
|
||||
|
||||
BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::invalid_argument );
|
||||
|
||||
startRecord.addItem( std::move( dayItem ) );
|
||||
startRecord.addItem( dayItem );
|
||||
BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::invalid_argument );
|
||||
|
||||
startRecord.addItem( std::move( monthItem ) );
|
||||
startRecord.addItem( monthItem );
|
||||
BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::invalid_argument );
|
||||
|
||||
startRecord.addItem( std::move( yearItem ) );
|
||||
startRecord.addItem( yearItem );
|
||||
BOOST_CHECK_THROW(Opm::TimeMap::timeFromEclipse( startRecord ) , std::invalid_argument );
|
||||
|
||||
startRecord.addItem( std::move( timeItem ) );
|
||||
startRecord.addItem( timeItem );
|
||||
BOOST_CHECK_NO_THROW(Opm::TimeMap::timeFromEclipse( startRecord ));
|
||||
|
||||
startRecord.addItem( std::move( extraItem ) );
|
||||
startRecord.addItem( extraItem );
|
||||
BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::invalid_argument );
|
||||
}
|
||||
|
||||
@@ -136,17 +136,17 @@ BOOST_AUTO_TEST_CASE( dateFromEclipseThrowsInvalidRecord ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( dateFromEclipseInvalidMonthThrows ) {
|
||||
Opm::DeckRecord startRecord;
|
||||
auto dayItem = Opm::DeckItem::make< int >("DAY");
|
||||
auto monthItem = Opm::DeckItem::make< std::string >("MONTH");
|
||||
auto yearItem = Opm::DeckItem::make< int >("YEAR");
|
||||
Opm::DeckItem dayItem( "DAY", int() );
|
||||
Opm::DeckItem monthItem( "MONTH", std::string() );
|
||||
Opm::DeckItem yearItem( "YEAR", int() );
|
||||
|
||||
dayItem.push_back( 10 );
|
||||
yearItem.push_back(1987 );
|
||||
monthItem.push_back("XXX");
|
||||
|
||||
startRecord.addItem( std::move( dayItem ) );
|
||||
startRecord.addItem( std::move( monthItem ) );
|
||||
startRecord.addItem( std::move( yearItem ) );
|
||||
startRecord.addItem( dayItem );
|
||||
startRecord.addItem( monthItem );
|
||||
startRecord.addItem( yearItem );
|
||||
|
||||
BOOST_CHECK_THROW( Opm::TimeMap::timeFromEclipse( startRecord ) , std::invalid_argument );
|
||||
}
|
||||
@@ -177,10 +177,10 @@ BOOST_AUTO_TEST_CASE( timeFromEclipseCheckMonthNames ) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE( timeFromEclipseInputRecord ) {
|
||||
Opm::DeckRecord startRecord;
|
||||
auto dayItem = Opm::DeckItem::make< int >("DAY");
|
||||
auto monthItem = Opm::DeckItem::make< std::string >("MONTH");
|
||||
auto yearItem = Opm::DeckItem::make< int >("YEAR");
|
||||
auto timeItem = Opm::DeckItem::make< std::string >("TIME");
|
||||
Opm::DeckItem dayItem( "DAY", int() );
|
||||
Opm::DeckItem monthItem( "MONTH", std::string() );
|
||||
Opm::DeckItem yearItem("YEAR", int() );
|
||||
Opm::DeckItem timeItem("TIME", std::string() );
|
||||
|
||||
dayItem.push_back( 10 );
|
||||
yearItem.push_back( 1987 );
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 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_RECORD_VECTOR_HPP
|
||||
#define OPM_RECORD_VECTOR_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
/*
|
||||
A vector like container which will return the last valid element
|
||||
when the lookup index is out of range.
|
||||
*/
|
||||
|
||||
namespace Opm {
|
||||
|
||||
template <typename T>
|
||||
class RecordVector {
|
||||
private:
|
||||
std::vector<T> m_data;
|
||||
public:
|
||||
size_t size() const {
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
T get(size_t index) const {
|
||||
if (m_data.size() > 0) {
|
||||
if (index >= m_data.size())
|
||||
return m_data.back();
|
||||
else
|
||||
return m_data[index];
|
||||
} else
|
||||
throw std::invalid_argument("Trying to get from empty RecordVector");
|
||||
}
|
||||
|
||||
|
||||
void push_back(T value) {
|
||||
m_data.push_back(value);
|
||||
}
|
||||
|
||||
typename std::vector<T>::const_iterator begin() const {
|
||||
return m_data.begin();
|
||||
}
|
||||
|
||||
|
||||
typename std::vector<T>::const_iterator end() const {
|
||||
return m_data.end();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
foreach(tapp OrderedMapTests ValueTests RecordVectorTests)
|
||||
foreach(tapp OrderedMapTests ValueTests)
|
||||
opm_add_test(run${tapp} SOURCES ${tapp}.cpp
|
||||
LIBRARIES opmparser ${Boost_LIBRARIES})
|
||||
endforeach()
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 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 <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE ScheduleTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Util/RecordVector.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_empty) {
|
||||
Opm::RecordVector<int> vector;
|
||||
BOOST_CHECK_EQUAL( 0U , vector.size());
|
||||
BOOST_CHECK_THROW( vector.get(0) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( check_add ) {
|
||||
Opm::RecordVector<int> vector;
|
||||
vector.push_back(10);
|
||||
BOOST_CHECK_EQUAL( 1U , vector.size());
|
||||
BOOST_CHECK_EQUAL( 10 , vector.get(0));
|
||||
BOOST_CHECK_EQUAL( 10 , vector.get(10));
|
||||
|
||||
vector.push_back(20);
|
||||
BOOST_CHECK_EQUAL( 2U , vector.size());
|
||||
BOOST_CHECK_EQUAL( 10 , vector.get(0));
|
||||
BOOST_CHECK_EQUAL( 20 , vector.get(1));
|
||||
BOOST_CHECK_EQUAL( 20 , vector.get(10));
|
||||
}
|
||||
@@ -43,9 +43,6 @@ const std::string testHeader =
|
||||
"#include <opm/parser/eclipse/Parser/ParserKeywords.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserRecord.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Units/UnitSystem.hpp>\n"
|
||||
"using namespace Opm;\n"
|
||||
@@ -54,9 +51,6 @@ const std::string testHeader =
|
||||
const std::string sourceHeader =
|
||||
"#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserRecord.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/Parser.hpp>\n"
|
||||
"#include <opm/parser/eclipse/Parser/ParserKeywords.hpp>\n\n\n"
|
||||
@@ -232,13 +226,13 @@ namespace Opm {
|
||||
stream << " Json::JsonObject jsonConfig( jsonPath );" << std::endl;
|
||||
stream << " ParserKeyword jsonKeyword(jsonConfig);" << std::endl;
|
||||
stream << " ParserKeywords::" << keywordName << " inlineKeyword;" << std::endl;
|
||||
stream << " BOOST_CHECK( jsonKeyword.equal( inlineKeyword ));" << std::endl;
|
||||
stream << " BOOST_CHECK_EQUAL( jsonKeyword, inlineKeyword );" << std::endl;
|
||||
stream << " if (jsonKeyword.hasDimension()) {" <<std::endl;
|
||||
stream << " const auto& parserRecord = jsonKeyword.getRecord(0);" << std::endl;
|
||||
stream << " for (size_t i=0; i < parserRecord->size(); i++){ " << std::endl;
|
||||
stream << " const auto& item = parserRecord->get( i );" << std::endl;
|
||||
stream << " for (size_t j=0; j < item->numDimensions(); j++) {" << std::endl;
|
||||
stream << " std::string dimString = item->getDimension(j);" << std::endl;
|
||||
stream << " for (size_t i=0; i < parserRecord.size(); i++){ " << std::endl;
|
||||
stream << " const auto& item = parserRecord.get( i );" << std::endl;
|
||||
stream << " for (size_t j=0; j < item.numDimensions(); j++) {" << std::endl;
|
||||
stream << " const std::string& dimString = item.getDimension(j);" << std::endl;
|
||||
stream << " BOOST_CHECK_NO_THROW( unitSystem.getNewDimension( dimString ));" << std::endl;
|
||||
stream << " }" << std::endl;
|
||||
stream << " }" << std::endl;
|
||||
|
||||
@@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(LoadKeywordDirectory) {
|
||||
{
|
||||
auto kw = loader.getKeyword("ADDREG");
|
||||
auto record = kw->getRecord(0);
|
||||
BOOST_CHECK_EQUAL( false, record->hasItem("REGION_NUMBER"));
|
||||
BOOST_CHECK( !record.hasItem("REGION_NUMBER") );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,6 @@ BOOST_AUTO_TEST_CASE(BigLoad) {
|
||||
{
|
||||
auto kw = loader.getKeyword("ADDREG");
|
||||
auto record = kw->getRecord(0);
|
||||
BOOST_CHECK( record->hasItem("REGION_NUMBER"));
|
||||
BOOST_CHECK( record.hasItem("REGION_NUMBER"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
|
||||
@@ -28,10 +28,8 @@
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
@@ -54,8 +52,8 @@ std::unique_ptr< ParserKeyword > createDynamicSized(const std::string& kw) {
|
||||
Parser createWWCTParser() {
|
||||
auto parserKeyword = createDynamicSized("WWCT");
|
||||
|
||||
auto record = std::make_shared< ParserRecord >();
|
||||
record->addItem( std::make_shared< ParserStringItem >("WELL", ALL) );
|
||||
ParserRecord record;
|
||||
record.addItem( ParserItem("WELL", ParserItem::item_size::ALL, "") );
|
||||
parserKeyword->addRecord( record );
|
||||
|
||||
auto summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
||||
@@ -140,10 +138,10 @@ BOOST_AUTO_TEST_CASE(parser_internal_name_vs_deck_name) {
|
||||
static Parser createBPRParser() {
|
||||
auto parserKeyword = createDynamicSized("BPR");
|
||||
{
|
||||
std::shared_ptr<ParserRecord> bprRecord = std::make_shared<ParserRecord>();
|
||||
bprRecord->addItem( std::make_shared< ParserIntItem >("I", SINGLE));
|
||||
bprRecord->addItem( std::make_shared< ParserIntItem >("J", SINGLE));
|
||||
bprRecord->addItem( std::make_shared< ParserIntItem >("K", SINGLE));
|
||||
ParserRecord bprRecord;
|
||||
bprRecord.addItem( ParserItem("I", ParserItem::item_size::SINGLE, 0) );
|
||||
bprRecord.addItem( ParserItem("J", ParserItem::item_size::SINGLE, 0) );
|
||||
bprRecord.addItem( ParserItem("K", ParserItem::item_size::SINGLE, 0) );
|
||||
parserKeyword->addRecord( bprRecord );
|
||||
}
|
||||
auto summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
||||
@@ -230,9 +228,8 @@ BOOST_AUTO_TEST_CASE(parse_truncatedrecords_deckFilledWithDefaults) {
|
||||
|
||||
auto* parserKeyword = parser.getParserKeywordFromDeckName("RADFIN4");
|
||||
const auto& parserRecord = parserKeyword->getRecord(0);
|
||||
const auto& nwmaxItem = parserRecord->get("NWMAX");
|
||||
auto intItem = std::static_pointer_cast<const ParserIntItem>(nwmaxItem);
|
||||
const auto& intItem = parserRecord.get("NWMAX");
|
||||
|
||||
BOOST_CHECK_EQUAL(18, radfin4_0_full.getRecord(0).getItem(10).get< int >(0));
|
||||
BOOST_CHECK_EQUAL(intItem->getDefault(), radfin4_1_partial.getRecord(0).getItem(10).get< int >(0));
|
||||
BOOST_CHECK_EQUAL(intItem.getDefault< int >(), radfin4_1_partial.getRecord(0).getItem(10).get< int >(0));
|
||||
}
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Units/Units.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/MULTREGTScanner.hpp>
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Units/Units.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@@ -35,12 +35,14 @@
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawConsts.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawEnums.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||
#include <opm/parser/eclipse/Utility/Stringview.hpp>
|
||||
|
||||
namespace Opm {
|
||||
@@ -439,10 +441,10 @@ std::shared_ptr< RawKeyword > createRawKeyword( const string_view& kw, ParserSta
|
||||
parserState.parseContext.handleError(ParseContext::PARSE_MISSING_DIMS_KEYWORD , msgContainer, msg );
|
||||
|
||||
const auto* keyword = parser.getKeyword( sizeKeyword.first );
|
||||
const auto record = keyword->getRecord(0);
|
||||
const auto int_item = std::dynamic_pointer_cast<const ParserIntItem>( record->get( sizeKeyword.second ) );
|
||||
const auto& record = keyword->getRecord(0);
|
||||
const auto& int_item = record.get( sizeKeyword.second );
|
||||
|
||||
const auto targetSize = int_item->getDefault( );
|
||||
const auto targetSize = int_item.getDefault< int >( );
|
||||
return std::make_shared< RawKeyword >( keywordString,
|
||||
parserState.current_path().string(),
|
||||
parserState.line(),
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 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 <boost/lexical_cast.hpp>
|
||||
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
|
||||
ParserDoubleItem::ParserDoubleItem(const std::string& itemName,
|
||||
ParserItemSizeEnum p_sizeType) :
|
||||
ParserItem(itemName, p_sizeType)
|
||||
{
|
||||
// use NaN as 'default default'. (Keep in mind that in the deck it can be queried
|
||||
// using deckItem->defaultApplied(idx) if an item was defaulted or not...
|
||||
m_default = std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
|
||||
ParserDoubleItem::ParserDoubleItem(const std::string& itemName)
|
||||
: ParserItem(itemName)
|
||||
{
|
||||
m_default = std::numeric_limits<double>::quiet_NaN();
|
||||
m_defaultSet = false;
|
||||
}
|
||||
|
||||
|
||||
ParserDoubleItem::ParserDoubleItem(const std::string& itemName, double defaultValue)
|
||||
: ParserItem(itemName)
|
||||
{
|
||||
setDefault( defaultValue );
|
||||
}
|
||||
|
||||
|
||||
ParserDoubleItem::ParserDoubleItem(const std::string& itemName, ParserItemSizeEnum p_sizeType, double defaultValue)
|
||||
: ParserItem(itemName, p_sizeType)
|
||||
{
|
||||
setDefault( defaultValue );
|
||||
}
|
||||
|
||||
|
||||
double ParserDoubleItem::getDefault() const {
|
||||
if (hasDefault())
|
||||
return m_default;
|
||||
|
||||
if (sizeType() == Opm::ALL)
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
|
||||
throw std::invalid_argument("No default value available for item "+name());
|
||||
}
|
||||
|
||||
|
||||
void ParserDoubleItem::setDefault(double defaultValue) {
|
||||
m_default = defaultValue;
|
||||
m_defaultSet = true;
|
||||
}
|
||||
|
||||
bool ParserDoubleItem::hasDefault() const {
|
||||
return m_defaultSet;
|
||||
}
|
||||
|
||||
ParserDoubleItem::ParserDoubleItem(const Json::JsonObject& jsonConfig) :
|
||||
ParserItem(jsonConfig)
|
||||
{
|
||||
m_default = std::numeric_limits<double>::quiet_NaN();
|
||||
if (jsonConfig.has_item("default"))
|
||||
setDefault( jsonConfig.get_double("default") );
|
||||
}
|
||||
|
||||
bool ParserDoubleItem::equal(const ParserItem& other) const {
|
||||
return parserRawItemEqual<ParserDoubleItem>(other) && equalDimensions(other);
|
||||
}
|
||||
|
||||
|
||||
bool ParserDoubleItem::equalDimensions(const ParserItem& other) const {
|
||||
bool equal_=false;
|
||||
if (other.numDimensions() == numDimensions()) {
|
||||
equal_ = true;
|
||||
for (size_t idim=0; idim < numDimensions(); idim++) {
|
||||
if (other.getDimension(idim) != getDimension(idim))
|
||||
equal_ = false;
|
||||
}
|
||||
}
|
||||
return equal_;
|
||||
}
|
||||
|
||||
void ParserDoubleItem::push_backDimension(const std::string& dimension) {
|
||||
if ((sizeType() == SINGLE) && (m_dimensions.size() > 0))
|
||||
throw std::invalid_argument("Internal error: cannot add more than one dimension to an item of size 1");
|
||||
|
||||
m_dimensions.push_back( dimension );
|
||||
}
|
||||
|
||||
bool ParserDoubleItem::hasDimension() const {
|
||||
return (m_dimensions.size() > 0);
|
||||
}
|
||||
|
||||
size_t ParserDoubleItem::numDimensions() const {
|
||||
return m_dimensions.size();
|
||||
}
|
||||
|
||||
const std::string& ParserDoubleItem::getDimension(size_t index) const {
|
||||
if (index < m_dimensions.size())
|
||||
return m_dimensions[index];
|
||||
else
|
||||
throw std::invalid_argument("Invalid index ");
|
||||
}
|
||||
|
||||
|
||||
DeckItem ParserDoubleItem::scan( RawRecord& rawRecord ) const {
|
||||
return ParserItemScan<ParserDoubleItem,double>(this , rawRecord);
|
||||
}
|
||||
|
||||
std::string ParserDoubleItem::createCode() const {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "new ParserDoubleItem(" << "\"" << name() << "\"" << ",Opm::" << ParserItemSizeEnum2String( sizeType() );
|
||||
if (m_defaultSet)
|
||||
ss << "," << boost::lexical_cast<std::string>(getDefault());
|
||||
ss << ")";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParserDoubleItem::inlineClass(std::ostream& os, const std::string& indent) const {
|
||||
ParserItemInlineClassDeclaration<ParserDoubleItem,double>(this , os , indent , "double");
|
||||
}
|
||||
|
||||
std::string ParserDoubleItem::inlineClassInit(const std::string& parentClass) const {
|
||||
return ParserItemInlineClassInit<ParserDoubleItem,int>(this , parentClass , "double");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 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 PARSERDOUBLEITEM_HPP
|
||||
#define PARSERDOUBLEITEM_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
namespace Json {
|
||||
class JsonObject;
|
||||
}
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class RawRecord;
|
||||
|
||||
class ParserDoubleItem : public ParserItem {
|
||||
public:
|
||||
ParserDoubleItem(const std::string& itemName);
|
||||
ParserDoubleItem(const std::string& itemName, ParserItemSizeEnum sizeType);
|
||||
ParserDoubleItem(const std::string& itemName, double defaultValue);
|
||||
ParserDoubleItem(const std::string& itemName, ParserItemSizeEnum sizeType, double defaultValue);
|
||||
explicit ParserDoubleItem( const Json::JsonObject& jsonConfig);
|
||||
|
||||
size_t numDimensions() const override;
|
||||
bool hasDimension() const override;
|
||||
void push_backDimension(const std::string& dimension) override;
|
||||
const std::string& getDimension(size_t index) const override;
|
||||
bool equalDimensions(const ParserItem& other) const;
|
||||
|
||||
DeckItem scan( RawRecord& rawRecord ) const override;
|
||||
bool equal(const ParserItem& other) const override;
|
||||
|
||||
std::string createCode() const override;
|
||||
void inlineClass(std::ostream& os, const std::string& indent) const override;
|
||||
std::string inlineClassInit(const std::string& parentClass) const override;
|
||||
void setDefault(double defaultValue);
|
||||
double getDefault() const;
|
||||
bool hasDefault() const;
|
||||
|
||||
size_t dimensionSize() const;
|
||||
|
||||
private:
|
||||
double m_default;
|
||||
std::vector<std::string> m_dimensions;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* PARSERINTITEM_HPP */
|
||||
|
||||
@@ -23,32 +23,6 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
|
||||
const std::string ParserItemSizeEnum2String(ParserItemSizeEnum enumValue) {
|
||||
switch (enumValue) {
|
||||
case ALL:
|
||||
return "ALL";
|
||||
break;
|
||||
case SINGLE:
|
||||
return "SINGLE";
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("Implementation error - should NOT be here");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ParserItemSizeEnum ParserItemSizeEnumFromString(const std::string& stringValue) {
|
||||
if (stringValue == "ALL")
|
||||
return ALL;
|
||||
else if (stringValue == "SINGLE")
|
||||
return SINGLE;
|
||||
else
|
||||
throw std::invalid_argument("String: " + stringValue + " can not be converted to enum value");
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
const std::string ParserKeywordSizeEnum2String(ParserKeywordSizeEnum enumValue) {
|
||||
|
||||
@@ -30,16 +30,6 @@ namespace Opm {
|
||||
OTHER_KEYWORD_IN_DECK = 2,
|
||||
UNKNOWN=3
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum ParserItemSizeEnum {
|
||||
ALL = 0,
|
||||
SINGLE = 1
|
||||
};
|
||||
|
||||
|
||||
|
||||
enum ParserValueTypeEnum {
|
||||
INT = 0,
|
||||
FLOAT = 1,
|
||||
@@ -56,11 +46,9 @@ namespace Opm {
|
||||
};
|
||||
|
||||
const std::string ParserKeywordActionEnum2String(ParserKeywordActionEnum enumValue);
|
||||
const std::string ParserItemSizeEnum2String(ParserItemSizeEnum enumValue);
|
||||
const std::string ParserKeywordSizeEnum2String(ParserKeywordSizeEnum enumValue);
|
||||
const std::string ParserValueTypeEnum2String(ParserValueTypeEnum enumValue);
|
||||
|
||||
ParserItemSizeEnum ParserItemSizeEnumFromString(const std::string& stringValue);
|
||||
ParserKeywordSizeEnum ParserKeywordSizeEnumFromString(const std::string& stringValue);
|
||||
ParserValueTypeEnum ParserValueTypeEnumFromString(const std::string& stringValue);
|
||||
ParserKeywordActionEnum ParserKeywordActionEnumFromString(const std::string& stringValue);
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2013 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 <stdexcept>
|
||||
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
ParserIntItem::ParserIntItem(const std::string& itemName) : ParserItem(itemName)
|
||||
{
|
||||
// integers do not have a representation for NaN. Let's use a negative value as
|
||||
// this is usually meaningless. (Keep in mind that in the deck it can be queried
|
||||
// using deckItem->defaultApplied(idx) if an item was defaulted or not...
|
||||
m_default = -1;
|
||||
m_defaultSet = false;
|
||||
}
|
||||
|
||||
ParserIntItem::ParserIntItem(const std::string& itemName, ParserItemSizeEnum p_sizeType)
|
||||
: ParserItem(itemName, p_sizeType)
|
||||
{
|
||||
m_default = -1;
|
||||
m_defaultSet = false;
|
||||
}
|
||||
|
||||
ParserIntItem::ParserIntItem(const std::string& itemName, int defaultValue) : ParserItem(itemName)
|
||||
{
|
||||
setDefault(defaultValue);
|
||||
}
|
||||
|
||||
|
||||
ParserIntItem::ParserIntItem(const std::string& itemName, ParserItemSizeEnum sizeType_, int defaultValue) : ParserItem(itemName, sizeType_)
|
||||
{
|
||||
setDefault(defaultValue);
|
||||
}
|
||||
|
||||
ParserIntItem::ParserIntItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig)
|
||||
{
|
||||
m_default = -1;
|
||||
if (jsonConfig.has_item("default"))
|
||||
setDefault( jsonConfig.get_int("default") );
|
||||
}
|
||||
|
||||
|
||||
void ParserIntItem::setDefault(int defaultValue) {
|
||||
if (sizeType() == ALL)
|
||||
throw std::invalid_argument("The size type ALL can not be combined with an explicit default value");
|
||||
m_defaultSet = true;
|
||||
m_default = defaultValue;
|
||||
}
|
||||
|
||||
int ParserIntItem::getDefault() const {
|
||||
if (hasDefault())
|
||||
return m_default;
|
||||
|
||||
if (sizeType() == Opm::ALL)
|
||||
return -1;
|
||||
|
||||
throw std::invalid_argument("No default value available for item "+name());
|
||||
}
|
||||
|
||||
bool ParserIntItem::hasDefault() const {
|
||||
return m_defaultSet;
|
||||
}
|
||||
|
||||
DeckItem ParserIntItem::scan( RawRecord& rawRecord) const {
|
||||
return ParserItemScan<ParserIntItem,int>(this , rawRecord);
|
||||
}
|
||||
|
||||
|
||||
bool ParserIntItem::equal(const ParserItem& other) const
|
||||
{
|
||||
return parserRawItemEqual<ParserIntItem>(other);
|
||||
}
|
||||
|
||||
|
||||
std::string ParserIntItem::createCode() const {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "new ParserIntItem(" << "\"" << name() << "\"" << ",Opm::" << ParserItemSizeEnum2String( sizeType() );
|
||||
if (m_defaultSet)
|
||||
ss << "," << getDefault();
|
||||
ss << ")";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParserIntItem::inlineClass(std::ostream& os, const std::string& indent) const {
|
||||
ParserItemInlineClassDeclaration<ParserIntItem,int>(this , os , indent , "int");
|
||||
}
|
||||
|
||||
|
||||
std::string ParserIntItem::inlineClassInit(const std::string& parentClass) const {
|
||||
return ParserItemInlineClassInit<ParserIntItem,int>(this , parentClass , "int");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 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 PARSERINTITEM_HPP
|
||||
#define PARSERINTITEM_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
namespace Json {
|
||||
class JsonObject;
|
||||
}
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class RawRecord;
|
||||
|
||||
class ParserIntItem : public ParserItem {
|
||||
public:
|
||||
ParserIntItem(const std::string& itemName);
|
||||
ParserIntItem(const std::string& itemName, ParserItemSizeEnum sizeType);
|
||||
ParserIntItem(const std::string& itemName, int defaultValue);
|
||||
ParserIntItem(const std::string& itemName, ParserItemSizeEnum sizeType, int defaultValue);
|
||||
explicit ParserIntItem(const Json::JsonObject& jsonConfig);
|
||||
|
||||
DeckItem scan( RawRecord& rawRecord) const override;
|
||||
bool equal(const ParserItem& other) const override;
|
||||
|
||||
std::string createCode() const override;
|
||||
void inlineClass(std::ostream& os, const std::string& indent) const override;
|
||||
std::string inlineClassInit(const std::string& parentClass) const override;
|
||||
|
||||
int getDefault() const;
|
||||
bool hasDefault() const;
|
||||
void setDefault(int defaultValue);
|
||||
private:
|
||||
int m_default;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* PARSERINTITEM_HPP */
|
||||
|
||||
@@ -17,64 +17,244 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||
|
||||
|
||||
namespace Opm {
|
||||
|
||||
ParserItem::ParserItem(const std::string& itemName, ParserItemSizeEnum p_sizeType) {
|
||||
m_name.assign(itemName);
|
||||
m_sizeType = p_sizeType;
|
||||
m_defaultSet = false;
|
||||
m_description = "";
|
||||
namespace {
|
||||
|
||||
template< typename T > const T& default_value();
|
||||
template<> const int& default_value< int >() {
|
||||
static const int value = -1;
|
||||
return value;
|
||||
}
|
||||
|
||||
template<> const double& default_value< double >() {
|
||||
static constexpr auto value = std::numeric_limits< double >::quiet_NaN();
|
||||
return value;
|
||||
}
|
||||
|
||||
template<> const std::string& default_value< std::string >() {
|
||||
static const std::string value = "";
|
||||
return value;
|
||||
}
|
||||
|
||||
type_tag get_type_json( const std::string& str ) {
|
||||
if( str == "INT" ) return type_tag::integer;
|
||||
if( str == "DOUBLE" ) return type_tag::fdouble;
|
||||
if( str == "STRING" ) return type_tag::string;
|
||||
throw std::invalid_argument( str + " cannot be converted to enum 'tag'" );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
ParserItem::item_size ParserItem::size_from_string( const std::string& str ) {
|
||||
if( str == "ALL" ) return item_size::ALL;
|
||||
if( str == "SINGLE") return item_size::SINGLE;
|
||||
throw std::invalid_argument( str + " can not be converted "
|
||||
"to enum 'item_size'" );
|
||||
}
|
||||
|
||||
std::string ParserItem::string_from_size( ParserItem::item_size sz ) {
|
||||
switch( sz ) {
|
||||
case item_size::ALL: return "ALL";
|
||||
case item_size::SINGLE: return "SINGLE";
|
||||
}
|
||||
|
||||
throw std::logic_error( "Fatal error; should not be reachable" );
|
||||
}
|
||||
|
||||
ParserItem::ParserItem(const std::string& itemName) {
|
||||
m_name.assign(itemName);
|
||||
m_sizeType = SINGLE;
|
||||
m_defaultSet = false;
|
||||
m_description = "";
|
||||
}
|
||||
template<> const int& ParserItem::value_ref< int >() const {
|
||||
if( this->type != get_type< int >() )
|
||||
throw std::invalid_argument( "Wrong type." );
|
||||
return this->ival;
|
||||
}
|
||||
|
||||
bool ParserItem::hasDimension() const {
|
||||
return false;
|
||||
}
|
||||
template<> const double& ParserItem::value_ref< double >() const {
|
||||
if( this->type != get_type< double >() )
|
||||
throw std::invalid_argument( "Wrong type." );
|
||||
return this->dval;
|
||||
}
|
||||
|
||||
size_t ParserItem::numDimensions() const {
|
||||
return 0;
|
||||
}
|
||||
template<> const std::string& ParserItem::value_ref< std::string >() const {
|
||||
if( this->type != get_type< std::string >() )
|
||||
throw std::invalid_argument( "Wrong type." );
|
||||
return this->sval;
|
||||
}
|
||||
|
||||
const std::string& ParserItem::getDimension(size_t /* index */) const {
|
||||
throw std::invalid_argument("Should not call this ... \n");
|
||||
}
|
||||
template< typename T >
|
||||
T& ParserItem::value_ref() {
|
||||
return const_cast< T& >(
|
||||
const_cast< const ParserItem& >( *this ).value_ref< T >()
|
||||
);
|
||||
}
|
||||
|
||||
void ParserItem::push_backDimension(const std::string& /* dimension */) {
|
||||
throw std::invalid_argument("Should not call this ... \n");
|
||||
}
|
||||
ParserItem::ParserItem( const std::string& itemName ) :
|
||||
ParserItem( itemName, ParserItem::item_size::SINGLE )
|
||||
{}
|
||||
|
||||
ParserItem::ParserItem(const Json::JsonObject& jsonConfig) {
|
||||
if (jsonConfig.has_item("name"))
|
||||
m_name = jsonConfig.get_string("name");
|
||||
else
|
||||
throw std::invalid_argument("Json config object missing \"name\": ... item");
|
||||
ParserItem::ParserItem( const std::string& itemName,
|
||||
ParserItem::item_size p_sizeType ) :
|
||||
m_name( itemName ),
|
||||
m_sizeType( p_sizeType ),
|
||||
m_defaultSet( false )
|
||||
{}
|
||||
|
||||
if (jsonConfig.has_item("size_type")) {
|
||||
const std::string sizeTypeString = jsonConfig.get_string("size_type");
|
||||
m_sizeType = ParserItemSizeEnumFromString( sizeTypeString );
|
||||
} else
|
||||
m_sizeType = SINGLE;
|
||||
ParserItem::ParserItem( const std::string& itemName, item_size sz, int val ) :
|
||||
ival( val ),
|
||||
m_name( itemName ),
|
||||
m_sizeType( sz ),
|
||||
type( get_type< int >() ),
|
||||
m_defaultSet( true )
|
||||
{}
|
||||
|
||||
if (jsonConfig.has_item("description")) {
|
||||
m_description = jsonConfig.get_string("description");
|
||||
ParserItem::ParserItem( const std::string& itemName,
|
||||
item_size sz,
|
||||
double val ) :
|
||||
dval( val ),
|
||||
m_name( itemName ),
|
||||
m_sizeType( sz ),
|
||||
type( get_type< double >() ),
|
||||
m_defaultSet( true )
|
||||
{}
|
||||
|
||||
ParserItem::ParserItem( const std::string& itemName,
|
||||
item_size sz,
|
||||
std::string val ) :
|
||||
sval( std::move( val ) ),
|
||||
m_name( itemName ),
|
||||
m_sizeType( sz ),
|
||||
type( get_type< std::string >() ),
|
||||
m_defaultSet( true )
|
||||
{}
|
||||
|
||||
ParserItem::ParserItem( const Json::JsonObject& json ) :
|
||||
m_name( json.get_string( "name" ) ),
|
||||
m_sizeType( json.has_item( "size_type" )
|
||||
? ParserItem::size_from_string( json.get_string( "size_type" ) )
|
||||
: ParserItem::item_size::SINGLE ),
|
||||
m_description( json.has_item( "description" )
|
||||
? json.get_string( "description" )
|
||||
: "" ),
|
||||
type( get_type_json( json.get_string( "value_type" ) ) ),
|
||||
m_defaultSet( false )
|
||||
{
|
||||
if( json.has_item( "dimension" ) ) {
|
||||
const auto& dim = json.get_item( "dimension" );
|
||||
|
||||
if( dim.is_string() ) {
|
||||
this->push_backDimension( dim.as_string() );
|
||||
}
|
||||
else if( dim.is_array() ) {
|
||||
for( size_t i = 0; i < dim.size(); ++i )
|
||||
this->push_backDimension( dim.get_array_item( i ).as_string() );
|
||||
}
|
||||
else {
|
||||
throw std::invalid_argument(
|
||||
"The 'dimension' attribute must be a string or list of strings"
|
||||
);
|
||||
}
|
||||
|
||||
m_defaultSet = false;
|
||||
}
|
||||
|
||||
if( !json.has_item( "default" ) ) return;
|
||||
|
||||
switch( this->type ) {
|
||||
case type_tag::integer:
|
||||
this->setDefault( json.get_int( "default" ) );
|
||||
break;
|
||||
|
||||
case type_tag::fdouble:
|
||||
this->setDefault( json.get_double( "default" ) );
|
||||
break;
|
||||
|
||||
case type_tag::string:
|
||||
this->setDefault( json.get_string( "default" ) );
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::logic_error( "Item of unknown type." );
|
||||
}
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void ParserItem::setDefault( T val ) {
|
||||
if( this->type != type_tag::fdouble && this->m_sizeType == item_size::ALL )
|
||||
throw std::invalid_argument( "The size type ALL can not be combined "
|
||||
"with an explicit default value." );
|
||||
|
||||
this->value_ref< T >() = std::move( val );
|
||||
this->m_defaultSet = true;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
void ParserItem::setType( T ) {
|
||||
this->type = get_type< T >();
|
||||
}
|
||||
|
||||
bool ParserItem::hasDefault() const {
|
||||
return this->m_defaultSet;
|
||||
}
|
||||
|
||||
|
||||
template< typename T >
|
||||
const T& ParserItem::getDefault() const {
|
||||
if( get_type< T >() != this->type )
|
||||
throw std::invalid_argument( "Wrong type." );
|
||||
|
||||
if( !this->hasDefault() && this->m_sizeType == item_size::ALL )
|
||||
return default_value< T >();
|
||||
|
||||
if( !this->hasDefault() )
|
||||
throw std::invalid_argument( "No default value available for item "
|
||||
+ this->name() );
|
||||
|
||||
return this->value_ref< T >();
|
||||
}
|
||||
|
||||
bool ParserItem::hasDimension() const {
|
||||
if( this->type != type_tag::fdouble )
|
||||
return false;
|
||||
|
||||
return !this->dimensions.empty();
|
||||
}
|
||||
|
||||
size_t ParserItem::numDimensions() const {
|
||||
if( this->type != type_tag::fdouble ) return 0;
|
||||
return this->dimensions.size();
|
||||
}
|
||||
|
||||
const std::string& ParserItem::getDimension( size_t index ) const {
|
||||
if( this->type != type_tag::fdouble )
|
||||
throw std::invalid_argument("Item is not double.");
|
||||
|
||||
return this->dimensions.at( index );
|
||||
}
|
||||
|
||||
void ParserItem::push_backDimension( const std::string& dim ) {
|
||||
if( this->type != type_tag::fdouble )
|
||||
throw std::invalid_argument( "Invalid type, does not have dimension." );
|
||||
|
||||
if( this->sizeType() == item_size::SINGLE && this->dimensions.size() > 0 ) {
|
||||
throw std::invalid_argument(
|
||||
"Internal error: "
|
||||
"cannot add more than one dimension to an item of size 1" );
|
||||
}
|
||||
|
||||
this->dimensions.push_back( dim );
|
||||
}
|
||||
|
||||
const std::string& ParserItem::name() const {
|
||||
return m_name;
|
||||
}
|
||||
@@ -85,15 +265,12 @@ namespace Opm {
|
||||
|
||||
|
||||
|
||||
ParserItemSizeEnum ParserItem::sizeType() const {
|
||||
ParserItem::item_size ParserItem::sizeType() const {
|
||||
return m_sizeType;
|
||||
}
|
||||
|
||||
bool ParserItem::scalar() const {
|
||||
if (m_sizeType == SINGLE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return this->m_sizeType == item_size::SINGLE;
|
||||
}
|
||||
|
||||
std::string ParserItem::getDescription() const {
|
||||
@@ -103,4 +280,285 @@ namespace Opm {
|
||||
void ParserItem::setDescription(std::string description) {
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
bool ParserItem::operator==( const ParserItem& rhs ) const {
|
||||
if( !( this->type == rhs.type
|
||||
&& this->m_name == rhs.m_name
|
||||
&& this->m_description == rhs.m_description
|
||||
&& this->m_sizeType == rhs.m_sizeType
|
||||
&& this->m_defaultSet == rhs.m_defaultSet ) )
|
||||
return false;
|
||||
|
||||
if( this->m_defaultSet ) {
|
||||
switch( this->type ) {
|
||||
case type_tag::integer:
|
||||
if( this->ival != rhs.ival ) return false;
|
||||
break;
|
||||
|
||||
case type_tag::fdouble:
|
||||
if( this->dval != rhs.dval ) return false;
|
||||
break;
|
||||
|
||||
case type_tag::string:
|
||||
if( this->sval != rhs.sval ) return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::logic_error( "Item of unknown type." );
|
||||
}
|
||||
}
|
||||
|
||||
if( this->type != type_tag::fdouble ) return true;
|
||||
|
||||
return this->dimensions.size() == rhs.dimensions.size()
|
||||
&& std::equal( this->dimensions.begin(),
|
||||
this->dimensions.end(),
|
||||
rhs.dimensions.begin() );
|
||||
}
|
||||
|
||||
bool ParserItem::operator!=( const ParserItem& rhs ) const {
|
||||
return !( *this == rhs );
|
||||
}
|
||||
|
||||
std::string ParserItem::createCode() const {
|
||||
std::stringstream stream;
|
||||
stream << "ParserItem item(\"" << this->name()
|
||||
<< "\", ParserItem::item_size::" << this->sizeType();
|
||||
|
||||
if( m_defaultSet ) {
|
||||
stream << ", ";
|
||||
switch( this->type ) {
|
||||
case type_tag::integer:
|
||||
stream << this->getDefault< int >();
|
||||
break;
|
||||
|
||||
case type_tag::fdouble:
|
||||
stream << "double( "
|
||||
<< boost::lexical_cast< std::string >
|
||||
( this->getDefault< double >() )
|
||||
<< " )";
|
||||
break;
|
||||
|
||||
case type_tag::string:
|
||||
stream << "\"" << this->getDefault< std::string >() << "\"";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::logic_error( "Item of unknown type." );
|
||||
}
|
||||
}
|
||||
|
||||
stream << " ); item.setType( " << tag_name( this->type ) << "() );";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
template< typename T >
|
||||
DeckItem scan_item( const ParserItem& p, RawRecord& record ) {
|
||||
DeckItem item( p.name(), T(), record.size() );
|
||||
|
||||
if( p.sizeType() == ParserItem::item_size::ALL ) {
|
||||
while( record.size() > 0 ) {
|
||||
auto token = record.pop_front();
|
||||
|
||||
std::string countString;
|
||||
std::string valueString;
|
||||
|
||||
if( !isStarToken( token, countString, valueString ) ) {
|
||||
item.push_back( readValueToken< T >( token ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
StarToken st(token, countString, valueString);
|
||||
|
||||
if( st.hasValue() ) {
|
||||
item.push_back( readValueToken< T >( st.valueString() ), st.count() );
|
||||
continue;
|
||||
}
|
||||
|
||||
auto value = p.getDefault< T >();
|
||||
for (size_t i=0; i < st.count(); i++)
|
||||
item.push_backDefault( value );
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
if( record.size() == 0 ) {
|
||||
// if the record was ended prematurely,
|
||||
if( p.hasDefault() ) {
|
||||
// use the default value for the item, if there is one...
|
||||
item.push_backDefault( p.getDefault< T >() );
|
||||
} else {
|
||||
// ... otherwise indicate that the deck item should throw once the
|
||||
// item's data is accessed.
|
||||
item.push_backDummyDefault();
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
// The '*' should be interpreted as a repetition indicator, but it must
|
||||
// be preceeded by an integer...
|
||||
auto token = record.pop_front();
|
||||
std::string countString;
|
||||
std::string valueString;
|
||||
if( !isStarToken(token, countString, valueString) ) {
|
||||
item.push_back( readValueToken<T>( token ) );
|
||||
return item;
|
||||
}
|
||||
|
||||
StarToken st(token, countString, valueString);
|
||||
|
||||
if( st.hasValue() )
|
||||
item.push_back(readValueToken< T >( st.valueString() ) );
|
||||
else if( p.hasDefault() )
|
||||
item.push_backDefault( p.getDefault< T >() );
|
||||
else
|
||||
item.push_backDummyDefault();
|
||||
|
||||
const auto value_start = token.size() - valueString.size();
|
||||
// replace the first occurence of "N*FOO" by a sequence of N-1 times
|
||||
// "FOO". this is slightly hacky, but it makes it work if the
|
||||
// number of defaults pass item boundaries...
|
||||
// We can safely make a string_view of one_star because it
|
||||
// has static storage
|
||||
static const char* one_star = "1*";
|
||||
string_view rep = !st.hasValue()
|
||||
? string_view{ one_star }
|
||||
: string_view{ token.begin() + value_start, token.end() };
|
||||
record.prepend( st.count() - 1, rep );
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Scans the records data according to the ParserItems definition.
|
||||
/// returns a DeckItem object.
|
||||
/// NOTE: data are popped from the records deque!
|
||||
DeckItem ParserItem::scan( RawRecord& record ) const {
|
||||
switch( this->type ) {
|
||||
case type_tag::integer:
|
||||
return scan_item< int >( *this, record );
|
||||
case type_tag::fdouble:
|
||||
return scan_item< double >( *this, record );
|
||||
case type_tag::string:
|
||||
return scan_item< std::string >( *this, record );
|
||||
default:
|
||||
throw std::logic_error( "Fatal error; should not be reachable" );
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& ParserItem::inlineClass( std::ostream& stream, const std::string& indent ) const {
|
||||
std::string local_indent = indent + " ";
|
||||
|
||||
stream << indent << "class " << this->className() << " {" << std::endl
|
||||
<< indent << "public:" << std::endl
|
||||
<< local_indent << "static const std::string itemName;" << std::endl;
|
||||
|
||||
if( this->hasDefault() ) {
|
||||
stream << local_indent << "static const "
|
||||
<< tag_name( this->type )
|
||||
<< " defaultValue;" << std::endl;
|
||||
}
|
||||
|
||||
return stream << indent << "};" << std::endl;
|
||||
}
|
||||
|
||||
std::string ParserItem::inlineClassInit(const std::string& parentClass,
|
||||
const std::string* defaultValue ) const {
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "const std::string " << parentClass
|
||||
<< "::" << this->className()
|
||||
<< "::itemName = \"" << this->name()
|
||||
<< "\";" << std::endl;
|
||||
|
||||
if( !this->hasDefault() ) return ss.str();
|
||||
|
||||
auto typestring = tag_name( this->type );
|
||||
|
||||
auto defval = [this]() -> std::string {
|
||||
switch( this->type ) {
|
||||
case type_tag::integer:
|
||||
return std::to_string( this->getDefault< int >() );
|
||||
case type_tag::fdouble:
|
||||
return std::to_string( this->getDefault< double >() );
|
||||
case type_tag::string:
|
||||
return "\"" + this->getDefault< std::string >() + "\"";
|
||||
|
||||
default:
|
||||
throw std::logic_error( "Fatal error; should not be reachable" );
|
||||
}
|
||||
};
|
||||
|
||||
ss << "const " << typestring << " "
|
||||
<< parentClass << "::" << this->className()
|
||||
<< "::defaultValue = " << (defaultValue ? *defaultValue : defval() )
|
||||
<< ";" << std::endl;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<( std::ostream& stream, const ParserItem::item_size& sz ) {
|
||||
return stream << ParserItem::string_from_size( sz );
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& stream, const ParserItem& item ) {
|
||||
stream
|
||||
<< "ParserItem " << item.name() << " { "
|
||||
<< "size: " << item.sizeType() << " "
|
||||
<< "description: '" << item.getDescription() << "' "
|
||||
;
|
||||
|
||||
if( item.hasDefault() ) {
|
||||
stream << "default: ";
|
||||
switch( item.type ) {
|
||||
case type_tag::integer:
|
||||
stream << item.getDefault< int >();
|
||||
break;
|
||||
|
||||
case type_tag::fdouble:
|
||||
stream << item.getDefault< double >();
|
||||
break;
|
||||
|
||||
case type_tag::string:
|
||||
stream << "'" << item.getDefault< std::string >() << "'";
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::logic_error( "Item of unknown type." );
|
||||
}
|
||||
|
||||
stream << " ";
|
||||
}
|
||||
|
||||
if( !item.hasDimension() )
|
||||
stream << "dimensions: none";
|
||||
else {
|
||||
stream << "dimensions: [ ";
|
||||
for( size_t i = 0; i < item.numDimensions(); ++i )
|
||||
stream << "'" << item.getDimension( i ) << "' ";
|
||||
stream << "]";
|
||||
}
|
||||
|
||||
return stream << " }";
|
||||
}
|
||||
|
||||
template void ParserItem::setDefault( int );
|
||||
template void ParserItem::setDefault( double );
|
||||
template void ParserItem::setDefault( std::string );
|
||||
|
||||
template void ParserItem::setType( int );
|
||||
template void ParserItem::setType( double );
|
||||
template void ParserItem::setType( std::string );
|
||||
|
||||
template const int& ParserItem::getDefault() const;
|
||||
template const double& ParserItem::getDefault() const;
|
||||
template const std::string& ParserItem::getDefault() const;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,17 +19,12 @@
|
||||
#ifndef PARSER_ITEM_H
|
||||
#define PARSER_ITEM_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||
#include <opm/parser/eclipse/Utility/Typetools.hpp>
|
||||
|
||||
namespace Json {
|
||||
class JsonObject;
|
||||
@@ -37,188 +32,71 @@ namespace Json {
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class RawRecord;
|
||||
|
||||
class ParserItem {
|
||||
public:
|
||||
ParserItem(const std::string& itemName);
|
||||
ParserItem(const std::string& itemName, ParserItemSizeEnum sizeType);
|
||||
enum class item_size { ALL, SINGLE };
|
||||
static item_size size_from_string( const std::string& );
|
||||
static std::string string_from_size( item_size );
|
||||
|
||||
explicit ParserItem( const std::string& name );
|
||||
ParserItem( const std::string& name, item_size );
|
||||
template< typename T >
|
||||
ParserItem( const std::string& item_name, T val ) :
|
||||
ParserItem( item_name, item_size::SINGLE, std::move( val ) ) {}
|
||||
ParserItem( const std::string& name, item_size, int defaultValue );
|
||||
ParserItem( const std::string& name, item_size, double defaultValue );
|
||||
ParserItem( const std::string& name, item_size, std::string defaultValue );
|
||||
|
||||
explicit ParserItem(const Json::JsonObject& jsonConfig);
|
||||
|
||||
virtual void push_backDimension(const std::string& dimension);
|
||||
virtual const std::string& getDimension(size_t index) const;
|
||||
virtual DeckItem scan( RawRecord& rawRecord) const = 0;
|
||||
virtual bool hasDimension() const;
|
||||
virtual size_t numDimensions() const;
|
||||
const std::string className() const;
|
||||
void push_backDimension( const std::string& );
|
||||
const std::string& getDimension(size_t index) const;
|
||||
bool hasDimension() const;
|
||||
size_t numDimensions() const;
|
||||
const std::string& name() const;
|
||||
ParserItemSizeEnum sizeType() const;
|
||||
item_size sizeType() const;
|
||||
std::string getDescription() const;
|
||||
bool scalar() const;
|
||||
void setDescription(std::string helpText);
|
||||
|
||||
virtual std::string createCode() const = 0;
|
||||
virtual void inlineClass(std::ostream& /* os */ , const std::string& indent) const = 0;
|
||||
virtual std::string inlineClassInit(const std::string& parentClass) const = 0;
|
||||
template< typename T > void setDefault( T );
|
||||
/* set type without a default value. will reset dimension etc. */
|
||||
template< typename T > void setType( T );
|
||||
bool hasDefault() const;
|
||||
template< typename T > const T& getDefault() const;
|
||||
|
||||
virtual ~ParserItem() {
|
||||
}
|
||||
bool operator==( const ParserItem& ) const;
|
||||
bool operator!=( const ParserItem& ) const;
|
||||
|
||||
virtual bool equal(const ParserItem& other) const = 0;
|
||||
|
||||
protected:
|
||||
template <class T>
|
||||
bool parserRawItemEqual(const ParserItem &other) const {
|
||||
const T * lhs = dynamic_cast<const T*>(this);
|
||||
const T * rhs = dynamic_cast<const T*>(&other);
|
||||
if (!lhs || !rhs)
|
||||
return false;
|
||||
|
||||
if (lhs->name() != rhs->name())
|
||||
return false;
|
||||
|
||||
if (lhs->getDescription() != rhs->getDescription())
|
||||
return false;
|
||||
|
||||
if (lhs->sizeType() != rhs->sizeType())
|
||||
return false;
|
||||
|
||||
if (lhs->m_defaultSet != rhs->m_defaultSet)
|
||||
return false;
|
||||
|
||||
// we only care that the default value is equal if it was
|
||||
// specified...
|
||||
if (lhs->m_defaultSet && lhs->getDefault() != rhs->getDefault())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool m_defaultSet;
|
||||
DeckItem scan( RawRecord& rawRecord ) const;
|
||||
const std::string className() const;
|
||||
std::string createCode() const;
|
||||
std::ostream& inlineClass(std::ostream&, const std::string& indent) const;
|
||||
std::string inlineClassInit(const std::string& parentClass,
|
||||
const std::string* defaultValue = nullptr ) const;
|
||||
|
||||
private:
|
||||
double dval;
|
||||
int ival;
|
||||
std::string sval;
|
||||
std::vector< std::string > dimensions;
|
||||
|
||||
std::string m_name;
|
||||
ParserItemSizeEnum m_sizeType;
|
||||
item_size m_sizeType;
|
||||
std::string m_description;
|
||||
|
||||
type_tag type = type_tag::unknown;
|
||||
bool m_defaultSet;
|
||||
|
||||
template< typename T > T& value_ref();
|
||||
template< typename T > const T& value_ref() const;
|
||||
friend std::ostream& operator<<( std::ostream&, const ParserItem& );
|
||||
};
|
||||
|
||||
|
||||
template<typename ParserItemType, typename ValueType>
|
||||
void ParserItemInlineClassDeclaration(const ParserItemType * self , std::ostream& os, const std::string& indent , const std::string& typeString) {
|
||||
os << indent << "class " << self->className( ) << " {" << std::endl;
|
||||
os << indent << "public:" << std::endl;
|
||||
{
|
||||
std::string local_indent = indent + " ";
|
||||
os << local_indent << "static const std::string itemName;" << std::endl;
|
||||
if (self->hasDefault())
|
||||
os << local_indent << "static const " << typeString << " defaultValue;" << std::endl;
|
||||
}
|
||||
os << indent << "};" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
template<typename ParserItemType, typename ValueType>
|
||||
std::string ParserItemInlineClassInit(const ParserItemType * self ,
|
||||
const std::string& parentClass ,
|
||||
const std::string& typeString ,
|
||||
const std::string * defaultValue = NULL) {
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "const std::string " << parentClass << "::" << self->className() << "::itemName = \"" << self->name() << "\";" << std::endl;
|
||||
|
||||
if (self->hasDefault()) {
|
||||
if (defaultValue)
|
||||
ss << "const " << typeString << " " << parentClass << "::" << self->className() << "::defaultValue = " << *defaultValue << ";" << std::endl;
|
||||
else
|
||||
ss << "const " << typeString << " " << parentClass << "::" << self->className() << "::defaultValue = " << self->getDefault() << ";" << std::endl;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// Scans the rawRecords data according to the ParserItems definition.
|
||||
/// returns a DeckItem object.
|
||||
/// NOTE: data are popped from the rawRecords deque!
|
||||
template<typename ParserItemType, typename ValueType>
|
||||
DeckItem ParserItemScan(const ParserItemType * self, RawRecord& rawRecord ) {
|
||||
auto deckItem = DeckItem::make< ValueType >( self->name(), rawRecord.size() );
|
||||
|
||||
if (self->sizeType() == ALL) {
|
||||
while (rawRecord.size() > 0) {
|
||||
auto token = rawRecord.pop_front();
|
||||
|
||||
std::string countString;
|
||||
std::string valueString;
|
||||
if (isStarToken(token, countString, valueString)) {
|
||||
StarToken st(token, countString, valueString);
|
||||
ValueType value;
|
||||
|
||||
if (st.hasValue()) {
|
||||
value = readValueToken<ValueType>(st.valueString());
|
||||
deckItem.push_back( value , st.count());
|
||||
} else {
|
||||
value = self->getDefault();
|
||||
for (size_t i=0; i < st.count(); i++)
|
||||
deckItem.push_backDefault( value );
|
||||
}
|
||||
} else {
|
||||
deckItem.push_back( readValueToken<ValueType>( token ) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (rawRecord.size() == 0) {
|
||||
// if the record was ended prematurely,
|
||||
if (self->hasDefault()) {
|
||||
// use the default value for the item, if there is one...
|
||||
deckItem.push_backDefault( self->getDefault() );
|
||||
} else {
|
||||
// ... otherwise indicate that the deck item should throw once the
|
||||
// item's data is accessed.
|
||||
deckItem.push_backDummyDefault();
|
||||
}
|
||||
} else {
|
||||
// The '*' should be interpreted as a repetition indicator, but it must
|
||||
// be preceeded by an integer...
|
||||
auto token = rawRecord.pop_front();
|
||||
std::string countString;
|
||||
std::string valueString;
|
||||
if (isStarToken(token, countString, valueString)) {
|
||||
StarToken st(token, countString, valueString);
|
||||
|
||||
if (!st.hasValue()) {
|
||||
if (self->hasDefault())
|
||||
deckItem.push_backDefault( self->getDefault() );
|
||||
else
|
||||
deckItem.push_backDummyDefault();
|
||||
} else
|
||||
deckItem.push_back(readValueToken<ValueType>(st.valueString()));
|
||||
|
||||
const auto value_start = token.size() - valueString.size();
|
||||
// replace the first occurence of "N*FOO" by a sequence of N-1 times
|
||||
// "FOO". this is slightly hacky, but it makes it work if the
|
||||
// number of defaults pass item boundaries...
|
||||
// We can safely make a string_view of one_star because it
|
||||
// has static storage
|
||||
static const char* one_star = "1*";
|
||||
string_view rep = !st.hasValue()
|
||||
? string_view{ one_star }
|
||||
: string_view{ token.begin() + value_start, token.end() };
|
||||
|
||||
rawRecord.prepend( st.count() - 1, rep );
|
||||
} else {
|
||||
deckItem.push_back( readValueToken<ValueType>( token ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return deckItem;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<( std::ostream&, const ParserItem::item_size& );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
@@ -26,14 +28,12 @@
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserConst.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/MessageContainer.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawConsts.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@@ -82,10 +82,11 @@ namespace Opm {
|
||||
}
|
||||
|
||||
bool ParserKeyword::hasDimension() const {
|
||||
for( const auto& record : m_records )
|
||||
if( record->hasDimension() ) return true;
|
||||
auto have_dim = []( const ParserRecord& r ) {
|
||||
return r.hasDimension();
|
||||
};
|
||||
|
||||
return false;
|
||||
return std::any_of( this->begin(), this->end(), have_dim );
|
||||
}
|
||||
|
||||
|
||||
@@ -301,135 +302,134 @@ namespace Opm {
|
||||
}
|
||||
|
||||
void ParserKeyword::addItems(const Json::JsonObject& itemsConfig) {
|
||||
if (itemsConfig.is_array()) {
|
||||
size_t num_items = itemsConfig.size();
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
|
||||
for (size_t i = 0; i < num_items; i++) {
|
||||
const Json::JsonObject itemConfig = itemsConfig.get_array_item(i);
|
||||
|
||||
if (itemConfig.has_item("value_type")) {
|
||||
ParserValueTypeEnum valueType = ParserValueTypeEnumFromString(itemConfig.get_string("value_type"));
|
||||
switch (valueType) {
|
||||
case INT:
|
||||
{
|
||||
record->addItem( std::make_shared< ParserIntItem >( itemConfig ) );
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
{
|
||||
record->addItem( std::make_shared< ParserStringItem >( itemConfig ) );
|
||||
}
|
||||
break;
|
||||
case DOUBLE:
|
||||
{
|
||||
auto item = std::make_shared< ParserDoubleItem >( itemConfig );
|
||||
initDoubleItemDimension( item, itemConfig );
|
||||
record->addItem(item);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("While parsing "+getName()+": Values of type "+itemConfig.get_string("value_type")+" are not implemented.");
|
||||
}
|
||||
} else
|
||||
throw std::invalid_argument("'value_type' JSON item missing for keyword "+getName()+".");
|
||||
}
|
||||
addRecord(record);
|
||||
} else
|
||||
if( !itemsConfig.is_array() )
|
||||
throw std::invalid_argument("The 'items' JSON item missing must be an array in keyword "+getName()+".");
|
||||
}
|
||||
|
||||
void ParserKeyword::initDoubleItemDimension( std::shared_ptr< ParserDoubleItem > item, const Json::JsonObject itemConfig) {
|
||||
if (itemConfig.has_item("dimension")) {
|
||||
const Json::JsonObject dimensionConfig = itemConfig.get_item("dimension");
|
||||
if (dimensionConfig.is_string())
|
||||
item->push_backDimension( dimensionConfig.as_string() );
|
||||
else if (dimensionConfig.is_array()) {
|
||||
for (size_t idim = 0; idim < dimensionConfig.size(); idim++) {
|
||||
Json::JsonObject dimObject = dimensionConfig.get_array_item( idim );
|
||||
item->push_backDimension( dimObject.as_string());
|
||||
}
|
||||
} else
|
||||
throw std::invalid_argument("The 'dimension' attribute of keyword "+getName()+" must be a string or a list of strings");
|
||||
size_t num_items = itemsConfig.size();
|
||||
ParserRecord record;
|
||||
|
||||
for (size_t i = 0; i < num_items; i++) {
|
||||
const Json::JsonObject& itemConfig = itemsConfig.get_array_item(i);
|
||||
record.addItem( ParserItem( itemConfig ) );
|
||||
}
|
||||
|
||||
this->addRecord( record );
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void set_dimensions( ParserItem& item,
|
||||
const Json::JsonObject& json,
|
||||
const std::string& keyword ) {
|
||||
if( !json.has_item("dimension") ) return;
|
||||
|
||||
const auto& dim = json.get_item("dimension");
|
||||
if( dim.is_string() ) {
|
||||
item.push_backDimension( dim.as_string() );
|
||||
}
|
||||
else if( dim.is_array() ) {
|
||||
for (size_t idim = 0; idim < dim.size(); idim++)
|
||||
item.push_backDimension( dim.get_array_item( idim ).as_string() );
|
||||
}
|
||||
else {
|
||||
throw std::invalid_argument(
|
||||
"The 'dimension' attribute of keyword " + keyword
|
||||
+ " must be a string or a list of strings" );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::initData(const Json::JsonObject& jsonConfig) {
|
||||
m_fixedSize = 1U;
|
||||
m_keywordSizeType = FIXED;
|
||||
this->m_fixedSize = 1U;
|
||||
this->m_keywordSizeType = FIXED;
|
||||
|
||||
const Json::JsonObject dataConfig = jsonConfig.get_item("data");
|
||||
if (dataConfig.has_item("value_type")) {
|
||||
ParserValueTypeEnum valueType = ParserValueTypeEnumFromString(dataConfig.get_string("value_type"));
|
||||
const std::string itemName("data");
|
||||
bool hasDefault = dataConfig.has_item("default");
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
if (!dataConfig.has_item("value_type") )
|
||||
throw std::invalid_argument("The 'value_type' JSON item of keyword "+getName()+" is missing");
|
||||
|
||||
switch (valueType) {
|
||||
case INT:
|
||||
ParserValueTypeEnum valueType = ParserValueTypeEnumFromString(dataConfig.get_string("value_type"));
|
||||
const std::string itemName("data");
|
||||
bool hasDefault = dataConfig.has_item("default");
|
||||
|
||||
ParserRecord record;
|
||||
ParserItem item( itemName, ParserItem::item_size::ALL );
|
||||
|
||||
switch (valueType) {
|
||||
case INT:
|
||||
{
|
||||
auto item = std::make_shared< ParserIntItem >( itemName, ALL );
|
||||
if (hasDefault) {
|
||||
item.setType( int() );
|
||||
if(hasDefault) {
|
||||
int defaultValue = dataConfig.get_int("default");
|
||||
item->setDefault(defaultValue);
|
||||
item.setDefault(defaultValue);
|
||||
}
|
||||
record->addDataItem( item );
|
||||
record.addDataItem( item );
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
case STRING:
|
||||
{
|
||||
auto item = std::make_shared< ParserStringItem >(itemName, ALL);
|
||||
item.setType( std::string() );
|
||||
if (hasDefault) {
|
||||
std::string defaultValue = dataConfig.get_string("default");
|
||||
item->setDefault(defaultValue);
|
||||
item.setDefault(defaultValue);
|
||||
}
|
||||
record->addItem( item );
|
||||
record.addItem( item );
|
||||
}
|
||||
break;
|
||||
case DOUBLE:
|
||||
case DOUBLE:
|
||||
{
|
||||
auto item = std::make_shared< ParserDoubleItem >(itemName, ALL);
|
||||
item.setType( double() );
|
||||
if (hasDefault) {
|
||||
double defaultValue = dataConfig.get_double("default");
|
||||
item->setDefault(defaultValue);
|
||||
item.setDefault(defaultValue);
|
||||
}
|
||||
initDoubleItemDimension( item , dataConfig );
|
||||
record->addDataItem( item );
|
||||
set_dimensions( item, dataConfig, this->getName() );
|
||||
record.addDataItem( item );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("While initializing keyword "+getName()+": Values of type "+dataConfig.get_string("value_type")+" are not implemented.");
|
||||
}
|
||||
addDataRecord( record );
|
||||
} else
|
||||
throw std::invalid_argument("The 'value_type' JSON item of keyword "+getName()+" is missing");
|
||||
default:
|
||||
throw std::invalid_argument("While initializing keyword "+getName()+": Values of type "+dataConfig.get_string("value_type")+" are not implemented.");
|
||||
}
|
||||
|
||||
this->addDataRecord( record );
|
||||
}
|
||||
|
||||
std::shared_ptr< ParserRecord > ParserKeyword::getRecord(size_t recordIndex) const {
|
||||
return m_records.get( recordIndex );
|
||||
const ParserRecord& ParserKeyword::getRecord(size_t recordIndex) const {
|
||||
if( this->m_records.empty() )
|
||||
throw std::invalid_argument( "Trying to get record from empty keyword" );
|
||||
|
||||
if( recordIndex >= this->m_records.size() )
|
||||
return this->m_records.back();
|
||||
|
||||
return this->m_records[ recordIndex ];
|
||||
}
|
||||
|
||||
ParserRecord& ParserKeyword::getRecord( size_t index ) {
|
||||
return const_cast< ParserRecord& >(
|
||||
const_cast< const ParserKeyword& >( *this ).getRecord( index )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::shared_ptr< ParserRecord > >::const_iterator ParserKeyword::recordBegin() const {
|
||||
std::vector< ParserRecord >::const_iterator ParserKeyword::begin() const {
|
||||
return m_records.begin();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr< ParserRecord > >::const_iterator ParserKeyword::recordEnd() const {
|
||||
std::vector< ParserRecord >::const_iterator ParserKeyword::end() const {
|
||||
return m_records.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParserKeyword::addRecord(std::shared_ptr<ParserRecord> record) {
|
||||
m_records.push_back( record );
|
||||
void ParserKeyword::addRecord( ParserRecord record ) {
|
||||
m_records.push_back( std::move( record ) );
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::addDataRecord(std::shared_ptr<ParserRecord> record) {
|
||||
void ParserKeyword::addDataRecord( ParserRecord record ) {
|
||||
if ((m_keywordSizeType == FIXED) && (m_fixedSize == 1U))
|
||||
addRecord(record);
|
||||
addRecord( std::move( record ) );
|
||||
else
|
||||
throw std::invalid_argument("When calling addDataRecord() for keyword " + getName() + ", it must be configured with fixed size == 1.");
|
||||
}
|
||||
@@ -486,7 +486,7 @@ namespace Opm {
|
||||
if( m_records.size() == 0 && rawRecord.size() > 0 )
|
||||
throw std::invalid_argument("Missing item information " + rawKeyword->getKeywordName());
|
||||
|
||||
keyword.addRecord( getRecord( record_nr )->parse( parseContext, msgContainer, rawRecord ) );
|
||||
keyword.addRecord( getRecord( record_nr ).parse( parseContext, msgContainer, rawRecord ) );
|
||||
record_nr++;
|
||||
}
|
||||
|
||||
@@ -513,11 +513,9 @@ namespace Opm {
|
||||
|
||||
|
||||
bool ParserKeyword::isDataKeyword() const {
|
||||
if (m_records.size() > 0) {
|
||||
auto record = m_records.get(0);
|
||||
return record->isDataRecord();
|
||||
} else
|
||||
return false;
|
||||
if( this->m_records.empty() ) return false;
|
||||
|
||||
return this->m_records.front().isDataRecord();
|
||||
}
|
||||
|
||||
|
||||
@@ -553,43 +551,6 @@ namespace Opm {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ParserKeyword::equal(const ParserKeyword& other) const {
|
||||
// compare the deck names. we don't care about the ordering of the strings.
|
||||
if (m_deckNames != other.m_deckNames)
|
||||
return false;
|
||||
|
||||
if( m_name != other.m_name
|
||||
|| m_matchRegexString != other.m_matchRegexString
|
||||
|| m_keywordSizeType != other.m_keywordSizeType
|
||||
|| isDataKeyword() != other.isDataKeyword()
|
||||
|| m_isTableCollection != other.m_isTableCollection )
|
||||
return false;
|
||||
|
||||
switch( m_keywordSizeType ) {
|
||||
case FIXED:
|
||||
if( m_fixedSize != other.m_fixedSize )
|
||||
return false;
|
||||
break;
|
||||
|
||||
case OTHER_KEYWORD_IN_DECK:
|
||||
if( m_sizeDefinitionPair.first != other.m_sizeDefinitionPair.first
|
||||
|| m_sizeDefinitionPair.second != other.m_sizeDefinitionPair.second )
|
||||
return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for( size_t i = 0; i < m_records.size(); i++ ) {
|
||||
if( !getRecord( i )->equal( *other.getRecord( i ) ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::string ParserKeyword::createDeclaration(const std::string& indent) const {
|
||||
std::stringstream ss;
|
||||
ss << indent << "class " << className() << " : public ParserKeyword {" << std::endl;
|
||||
@@ -599,12 +560,10 @@ namespace Opm {
|
||||
ss << local_indent << className() << "();" << std::endl;
|
||||
ss << local_indent << "static const std::string keywordName;" << std::endl;
|
||||
if (m_records.size() > 0 ) {
|
||||
for (auto iter = recordBegin(); iter != recordEnd(); ++iter) {
|
||||
std::shared_ptr<ParserRecord> record = *iter;
|
||||
for (size_t i = 0; i < record->size(); i++) {
|
||||
const auto& item = record->get(i);
|
||||
for( const auto& record : *this ) {
|
||||
for( const auto& item : record ) {
|
||||
ss << std::endl;
|
||||
item->inlineClass(ss , local_indent );
|
||||
item.inlineClass(ss , local_indent );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -672,32 +631,30 @@ namespace Opm {
|
||||
|
||||
{
|
||||
if (m_records.size() > 0 ) {
|
||||
for (auto iter = recordBegin(); iter != recordEnd(); ++iter) {
|
||||
std::shared_ptr<ParserRecord> record = *iter;
|
||||
for( const auto& record : *this ) {
|
||||
const std::string local_indent = indent + " ";
|
||||
ss << indent << "{" << std::endl;
|
||||
ss << local_indent << "std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();" << std::endl;
|
||||
for (size_t i = 0; i < record->size(); i++) {
|
||||
const auto& item = record->get(i);
|
||||
ss << local_indent << "ParserRecord record;" << std::endl;
|
||||
for( const auto& item : record ) {
|
||||
ss << local_indent << "{" << std::endl;
|
||||
{
|
||||
std::string indent3 = local_indent + " ";
|
||||
ss << indent3 << "std::shared_ptr< ParserItem > item(" << item->createCode() << ");" << std::endl;
|
||||
ss << indent3 << "item->setDescription(\"" << item->getDescription() << "\");" << std::endl;
|
||||
for (size_t idim=0; idim < item->numDimensions(); idim++)
|
||||
ss << indent3 <<"item->push_backDimension(\"" << item->getDimension( idim ) << "\");" << std::endl;
|
||||
ss << indent3 << item.createCode() << std::endl
|
||||
<< indent3 << "item.setDescription(\"" << item.getDescription() << "\");" << std::endl;
|
||||
for (size_t idim=0; idim < item.numDimensions(); idim++)
|
||||
ss << indent3 <<"item.push_backDimension(\"" << item.getDimension( idim ) << "\");" << std::endl;
|
||||
{
|
||||
std::string addItemMethod = "addItem";
|
||||
if (isDataKeyword())
|
||||
addItemMethod = "addDataItem";
|
||||
|
||||
ss << indent3 << "record->" << addItemMethod << "(item);" << std::endl;
|
||||
ss << indent3 << "record." << addItemMethod << "(item);" << std::endl;
|
||||
}
|
||||
}
|
||||
ss << local_indent << "}" << std::endl;
|
||||
}
|
||||
|
||||
if (record->isDataRecord())
|
||||
if (record.isDataRecord())
|
||||
ss << local_indent << "addDataRecord( record );" << std::endl;
|
||||
else
|
||||
ss << local_indent << "addRecord( record );" << std::endl;
|
||||
@@ -709,11 +666,9 @@ namespace Opm {
|
||||
ss << "}" << std::endl;
|
||||
|
||||
ss << "const std::string " << className() << "::keywordName = \"" << getName() << "\";" << std::endl;
|
||||
for (auto iter = recordBegin(); iter != recordEnd(); ++iter) {
|
||||
std::shared_ptr<ParserRecord> record = *iter;
|
||||
for (size_t i = 0; i < record->size(); i++) {
|
||||
const auto& item = record->get(i);
|
||||
ss << item->inlineClassInit(className());
|
||||
for( const auto& record : *this ) {
|
||||
for( const auto& item : record ) {
|
||||
ss << item.inlineClassInit(className());
|
||||
}
|
||||
}
|
||||
ss << std::endl;
|
||||
@@ -723,9 +678,59 @@ namespace Opm {
|
||||
|
||||
void ParserKeyword::applyUnitsToDeck( Deck& deck, DeckKeyword& deckKeyword) const {
|
||||
for (size_t index = 0; index < deckKeyword.size(); index++) {
|
||||
std::shared_ptr<const ParserRecord> parserRecord = getRecord(index);
|
||||
auto& deckRecord = deckKeyword.getRecord(index);
|
||||
parserRecord->applyUnitsToDeck( deck , deckRecord );
|
||||
const auto& parserRecord = this->getRecord( index );
|
||||
auto& deckRecord = deckKeyword.getRecord( index );
|
||||
parserRecord.applyUnitsToDeck( deck, deckRecord );
|
||||
}
|
||||
}
|
||||
|
||||
bool ParserKeyword::operator==( const ParserKeyword& rhs ) const {
|
||||
// compare the deck names. we don't care about the ordering of the strings.
|
||||
if (m_deckNames != rhs.m_deckNames)
|
||||
return false;
|
||||
|
||||
if( m_name != rhs.m_name
|
||||
|| m_matchRegexString != rhs.m_matchRegexString
|
||||
|| m_keywordSizeType != rhs.m_keywordSizeType
|
||||
|| isDataKeyword() != rhs.isDataKeyword()
|
||||
|| m_isTableCollection != rhs.m_isTableCollection )
|
||||
return false;
|
||||
|
||||
switch( m_keywordSizeType ) {
|
||||
case FIXED:
|
||||
if( m_fixedSize != rhs.m_fixedSize )
|
||||
return false;
|
||||
break;
|
||||
|
||||
case OTHER_KEYWORD_IN_DECK:
|
||||
if( m_sizeDefinitionPair.first != rhs.m_sizeDefinitionPair.first
|
||||
|| m_sizeDefinitionPair.second != rhs.m_sizeDefinitionPair.second )
|
||||
return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return this->m_records.size() == rhs.m_records.size()
|
||||
&& std::equal( this->begin(), this->end(), rhs.begin() );
|
||||
}
|
||||
|
||||
bool ParserKeyword::operator!=( const ParserKeyword& rhs ) const {
|
||||
return !( *this == rhs );
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& stream, const ParserKeyword& kw ) {
|
||||
stream << "ParserKeyword " << kw.getName() << " { " << std::endl
|
||||
<< "records: [";
|
||||
|
||||
if( kw.begin() != kw.end() ) stream << std::endl;
|
||||
|
||||
for( const auto& record : kw )
|
||||
stream << record << std::endl;
|
||||
stream << "]";
|
||||
|
||||
return stream << std::endl << "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
#ifndef PARSER_KEYWORD_H
|
||||
#define PARSER_KEYWORD_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Util/RecordVector.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
|
||||
namespace Json {
|
||||
class JsonObject;
|
||||
@@ -37,7 +38,6 @@ namespace Opm {
|
||||
class DeckKeyword;
|
||||
class ParseContext;
|
||||
class ParserDoubleItem;
|
||||
class ParserRecord;
|
||||
class RawKeyword;
|
||||
class string_view;
|
||||
class MessageContainer;
|
||||
@@ -68,11 +68,12 @@ namespace Opm {
|
||||
void setMatchRegex(const std::string& deckNameRegexp);
|
||||
bool matches(const string_view& ) const;
|
||||
bool hasDimension() const;
|
||||
void addRecord(std::shared_ptr<ParserRecord> record);
|
||||
void addDataRecord(std::shared_ptr<ParserRecord> record);
|
||||
std::shared_ptr< ParserRecord > getRecord(size_t recordIndex) const;
|
||||
std::vector<std::shared_ptr< ParserRecord >>::const_iterator recordBegin() const;
|
||||
std::vector<std::shared_ptr< ParserRecord >>::const_iterator recordEnd() const;
|
||||
void addRecord( ParserRecord );
|
||||
void addDataRecord( ParserRecord );
|
||||
const ParserRecord& getRecord(size_t recordIndex) const;
|
||||
ParserRecord& getRecord(size_t recordIndex);
|
||||
std::vector< ParserRecord >::const_iterator begin() const;
|
||||
std::vector< ParserRecord >::const_iterator end() const;
|
||||
const std::string className() const;
|
||||
const std::string& getName() const;
|
||||
size_t getFixedSize() const;
|
||||
@@ -97,12 +98,15 @@ namespace Opm {
|
||||
enum ParserKeywordSizeEnum getSizeType() const;
|
||||
const std::pair<std::string,std::string>& getSizeDefinitionPair() const;
|
||||
bool isDataKeyword() const;
|
||||
bool equal(const ParserKeyword& other) const;
|
||||
|
||||
std::string createDeclaration(const std::string& indent) const;
|
||||
std::string createDecl() const;
|
||||
std::string createCode() const;
|
||||
void applyUnitsToDeck( Deck& deck, DeckKeyword& deckKeyword) const;
|
||||
|
||||
bool operator==( const ParserKeyword& ) const;
|
||||
bool operator!=( const ParserKeyword& ) const;
|
||||
|
||||
private:
|
||||
std::pair<std::string,std::string> m_sizeDefinitionPair;
|
||||
std::string m_name;
|
||||
@@ -110,7 +114,7 @@ namespace Opm {
|
||||
DeckNameSet m_validSectionNames;
|
||||
std::string m_matchRegexString;
|
||||
boost::regex m_matchRegex;
|
||||
RecordVector<std::shared_ptr< ParserRecord >> m_records;
|
||||
std::vector< ParserRecord > m_records;
|
||||
enum ParserKeywordSizeEnum m_keywordSizeType;
|
||||
size_t m_fixedSize;
|
||||
bool m_isTableCollection;
|
||||
@@ -125,8 +129,9 @@ namespace Opm {
|
||||
void initSizeKeyword(const Json::JsonObject& sizeObject);
|
||||
void commonInit(const std::string& name, ParserKeywordSizeEnum sizeType);
|
||||
void addItems( const Json::JsonObject& jsonConfig);
|
||||
void initDoubleItemDimension( std::shared_ptr< ParserDoubleItem > item, const Json::JsonObject itemConfig);
|
||||
};
|
||||
|
||||
std::ostream& operator<<( std::ostream&, const ParserKeyword& );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,10 +23,21 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/MessageContainer.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
namespace {
|
||||
struct name_eq {
|
||||
name_eq( const std::string& x ) : name( x ) {}
|
||||
const std::string& name;
|
||||
bool operator()( const ParserItem& x ) const {
|
||||
return x.name() == this->name;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ParserRecord::ParserRecord()
|
||||
: m_dataRecord( false )
|
||||
{
|
||||
@@ -36,87 +47,88 @@ namespace Opm {
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
void ParserRecord::addItem(std::shared_ptr< const ParserItem > item) {
|
||||
void ParserRecord::addItem( ParserItem item ) {
|
||||
if (m_dataRecord)
|
||||
throw std::invalid_argument("Record is already marked as DataRecord - can not add items");
|
||||
|
||||
if (m_itemMap.find(item->name()) == m_itemMap.end()) {
|
||||
m_items.push_back(item);
|
||||
m_itemMap[item->name()] = item;
|
||||
} else
|
||||
throw std::invalid_argument("Itemname: " + item->name() + " already exists.");
|
||||
auto itr = std::find_if( this->m_items.begin(),
|
||||
this->m_items.end(),
|
||||
name_eq( item.name() ) );
|
||||
|
||||
if( itr != this->m_items.end() )
|
||||
throw std::invalid_argument("Itemname: " + item.name() + " already exists.");
|
||||
|
||||
this->m_items.push_back( std::move( item ) );
|
||||
}
|
||||
|
||||
void ParserRecord::addDataItem(std::shared_ptr< const ParserItem > item) {
|
||||
void ParserRecord::addDataItem( ParserItem item ) {
|
||||
if (m_items.size() > 0)
|
||||
throw std::invalid_argument("Record already contains items - can not add Data Item");
|
||||
|
||||
addItem(item);
|
||||
this->addItem( std::move( item) );
|
||||
m_dataRecord = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector< std::shared_ptr< const ParserItem > >::const_iterator ParserRecord::begin() const {
|
||||
std::vector< ParserItem >::const_iterator ParserRecord::begin() const {
|
||||
return m_items.begin();
|
||||
}
|
||||
|
||||
|
||||
std::vector< std::shared_ptr< const ParserItem > >::const_iterator ParserRecord::end() const {
|
||||
std::vector< ParserItem >::const_iterator ParserRecord::end() const {
|
||||
return m_items.end();
|
||||
}
|
||||
|
||||
|
||||
bool ParserRecord::hasDimension() const {
|
||||
bool hasDim = false;
|
||||
for (auto iter=begin(); iter != end(); ++iter) {
|
||||
if ((*iter)->hasDimension())
|
||||
hasDim = true;
|
||||
}
|
||||
return hasDim;
|
||||
return std::any_of( this->begin(), this->end(),
|
||||
[]( const ParserItem& x ) { return x.hasDimension(); } );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParserRecord::applyUnitsToDeck( Deck& deck, DeckRecord& deckRecord ) const {
|
||||
for (auto iter=begin(); iter != end(); ++iter) {
|
||||
if ((*iter)->hasDimension()) {
|
||||
auto& deckItem = deckRecord.getItem( (*iter)->name() );
|
||||
std::shared_ptr<const ParserItem> parserItem = get( (*iter)->name() );
|
||||
for( const auto& item : *this ) {
|
||||
if( !item.hasDimension() ) continue;
|
||||
|
||||
for (size_t idim=0; idim < (*iter)->numDimensions(); idim++) {
|
||||
auto activeDimension = deck.getActiveUnitSystem().getNewDimension( parserItem->getDimension(idim) );
|
||||
auto defaultDimension = deck.getDefaultUnitSystem().getNewDimension( parserItem->getDimension(idim) );
|
||||
deckItem.push_backDimension( activeDimension , defaultDimension );
|
||||
}
|
||||
auto& deckItem = deckRecord.getItem( item.name() );
|
||||
|
||||
for (size_t idim = 0; idim < item.numDimensions(); idim++) {
|
||||
auto activeDimension = deck.getActiveUnitSystem().getNewDimension( item.getDimension(idim) );
|
||||
auto defaultDimension = deck.getDefaultUnitSystem().getNewDimension( item.getDimension(idim) );
|
||||
deckItem.push_backDimension( activeDimension , defaultDimension );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr< const ParserItem > ParserRecord::get(size_t index) const {
|
||||
if (index < m_items.size())
|
||||
return m_items[ index ];
|
||||
else
|
||||
throw std::out_of_range("Out of range");
|
||||
const ParserItem& ParserRecord::get(size_t index) const {
|
||||
return this->m_items.at( index );
|
||||
}
|
||||
|
||||
bool ParserRecord::hasItem(const std::string& itemName) const {
|
||||
if (m_itemMap.find(itemName) == m_itemMap.end())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
bool ParserRecord::hasItem( const std::string& name ) const {
|
||||
return std::any_of( this->m_items.begin(),
|
||||
this->m_items.end(),
|
||||
name_eq( name ) );
|
||||
}
|
||||
|
||||
std::shared_ptr< const ParserItem > ParserRecord::get(const std::string& itemName) const {
|
||||
return this->m_itemMap.at( itemName );
|
||||
const ParserItem& ParserRecord::get( const std::string& name ) const {
|
||||
auto itr = std::find_if( this->m_items.begin(),
|
||||
this->m_items.end(),
|
||||
name_eq( name ) );
|
||||
|
||||
if( itr == this->m_items.end() )
|
||||
throw std::out_of_range( "No item '" + name + "'" );
|
||||
|
||||
return *itr;
|
||||
}
|
||||
|
||||
DeckRecord ParserRecord::parse(const ParseContext& parseContext , MessageContainer& msgContainer, RawRecord& rawRecord ) const {
|
||||
std::vector< DeckItem > items;
|
||||
items.reserve( this->size() + 20 );
|
||||
for( const auto& parserItem : *this )
|
||||
items.emplace_back( parserItem->scan( rawRecord ) );
|
||||
items.emplace_back( parserItem.scan( rawRecord ) );
|
||||
|
||||
if (rawRecord.size() > 0) {
|
||||
std::string msg = "The RawRecord for keyword \"" + rawRecord.getKeywordName() + "\" in file\"" + rawRecord.getFileName() + "\" contained " +
|
||||
@@ -139,7 +151,7 @@ namespace Opm {
|
||||
const auto& item = get(itemIndex);
|
||||
const auto& otherItem = other.get(itemIndex);
|
||||
|
||||
if (!item->equal(*otherItem)) {
|
||||
if (item != otherItem ) {
|
||||
equal_ = false;
|
||||
break;
|
||||
}
|
||||
@@ -155,5 +167,21 @@ namespace Opm {
|
||||
return m_dataRecord;
|
||||
}
|
||||
|
||||
bool ParserRecord::operator==( const ParserRecord& rhs ) const {
|
||||
return this->equal( rhs );
|
||||
}
|
||||
|
||||
bool ParserRecord::operator!=( const ParserRecord& rhs ) const {
|
||||
return !( *this == rhs );
|
||||
}
|
||||
|
||||
std::ostream& operator<<( std::ostream& stream, const ParserRecord& rec ) {
|
||||
stream << " ParserRecord { " << std::endl;
|
||||
|
||||
for( const auto& item : rec )
|
||||
stream << " " << item << std::endl;
|
||||
|
||||
return stream << " }";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
#ifndef PARSERRECORD_HPP
|
||||
#define PARSERRECORD_HPP
|
||||
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class Deck;
|
||||
@@ -37,23 +39,28 @@ namespace Opm {
|
||||
public:
|
||||
ParserRecord();
|
||||
size_t size() const;
|
||||
void addItem( std::shared_ptr< const ParserItem > item );
|
||||
void addDataItem(std::shared_ptr< const ParserItem > item);
|
||||
std::shared_ptr< const ParserItem > get(size_t index) const;
|
||||
std::shared_ptr< const ParserItem > get(const std::string& itemName) const;
|
||||
void addItem( ParserItem );
|
||||
void addDataItem( ParserItem item );
|
||||
const ParserItem& get(size_t index) const;
|
||||
const ParserItem& get(const std::string& itemName) const;
|
||||
DeckRecord parse( const ParseContext&, MessageContainer&, RawRecord& ) const;
|
||||
bool isDataRecord() const;
|
||||
bool equal(const ParserRecord& other) const;
|
||||
bool hasDimension() const;
|
||||
bool hasItem(const std::string& itemName) const;
|
||||
void applyUnitsToDeck( Deck& deck, DeckRecord& deckRecord) const;
|
||||
std::vector<std::shared_ptr< const ParserItem >>::const_iterator begin() const;
|
||||
std::vector<std::shared_ptr< const ParserItem >>::const_iterator end() const;
|
||||
std::vector< ParserItem >::const_iterator begin() const;
|
||||
std::vector< ParserItem >::const_iterator end() const;
|
||||
|
||||
bool operator==( const ParserRecord& ) const;
|
||||
bool operator!=( const ParserRecord& ) const;
|
||||
|
||||
private:
|
||||
bool m_dataRecord;
|
||||
std::vector<std::shared_ptr< const ParserItem >> m_items;
|
||||
std::map<std::string , std::shared_ptr< const ParserItem >> m_itemMap;
|
||||
std::vector< ParserItem > m_items;
|
||||
};
|
||||
|
||||
std::ostream& operator<<( std::ostream&, const ParserRecord& );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 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 <opm/json/JsonObject.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/StarToken.hpp>
|
||||
namespace Opm {
|
||||
|
||||
ParserStringItem::ParserStringItem(const std::string& itemName) : ParserItem(itemName)
|
||||
{
|
||||
m_default = "";
|
||||
m_defaultSet = false;
|
||||
}
|
||||
|
||||
|
||||
ParserStringItem::ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType_) : ParserItem(itemName, sizeType_)
|
||||
{
|
||||
m_default = "";
|
||||
m_defaultSet = false;
|
||||
}
|
||||
|
||||
ParserStringItem::ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType_, const std::string& defaultValue) : ParserItem(itemName, sizeType_) {
|
||||
setDefault(defaultValue);
|
||||
}
|
||||
|
||||
|
||||
ParserStringItem::ParserStringItem(const std::string& itemName, const std::string& defaultValue) : ParserItem(itemName) {
|
||||
setDefault(defaultValue);
|
||||
}
|
||||
|
||||
|
||||
ParserStringItem::ParserStringItem(const Json::JsonObject& jsonConfig) : ParserItem(jsonConfig) {
|
||||
m_default = "";
|
||||
if (jsonConfig.has_item("default"))
|
||||
setDefault( jsonConfig.get_string("default") );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParserStringItem::setDefault(const std::string& defaultValue) {
|
||||
if (sizeType() == ALL)
|
||||
throw std::invalid_argument("The size type ALL can not be combined with an explicit default value");
|
||||
|
||||
m_default = defaultValue;
|
||||
m_defaultSet = true;
|
||||
}
|
||||
|
||||
std::string ParserStringItem::getDefault() const {
|
||||
if (hasDefault())
|
||||
return m_default;
|
||||
|
||||
if (sizeType() == Opm::ALL)
|
||||
return "";
|
||||
|
||||
throw std::invalid_argument("No default value available for item "+name());
|
||||
}
|
||||
|
||||
bool ParserStringItem::hasDefault() const {
|
||||
return m_defaultSet;
|
||||
}
|
||||
|
||||
DeckItem ParserStringItem::scan( RawRecord& rawRecord ) const {
|
||||
return ParserItemScan<ParserStringItem,std::string>(this , rawRecord);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ParserStringItem::equal(const ParserItem& other) const
|
||||
{
|
||||
return parserRawItemEqual<ParserStringItem>(other);
|
||||
}
|
||||
|
||||
std::string ParserStringItem::createCode() const {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "new ParserStringItem(" << "\"" << name() << "\"" << ",Opm::" << ParserItemSizeEnum2String( sizeType() );
|
||||
if (m_defaultSet)
|
||||
ss << ",\"" << getDefault() << "\"";
|
||||
ss << ")";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ParserStringItem::inlineClass(std::ostream& os , const std::string& indent) const {
|
||||
ParserItemInlineClassDeclaration<ParserStringItem,std::string>(this , os , indent , "std::string");
|
||||
}
|
||||
|
||||
|
||||
std::string ParserStringItem::inlineClassInit(const std::string& parentClass) const {
|
||||
if (hasDefault()) {
|
||||
std::string quotedDefault = "\"" + getDefault() + "\"";
|
||||
return ParserItemInlineClassInit<ParserStringItem,std::string>(this , parentClass , "std::string" , "edDefault);
|
||||
} else
|
||||
return ParserItemInlineClassInit<ParserStringItem,std::string>(this , parentClass , "std::string");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
Copyright 2013 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 PARSERSTRINGITEM_HPP
|
||||
#define PARSERSTRINGITEM_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
|
||||
namespace Json {
|
||||
class JsonObject;
|
||||
}
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class ParserStringItem : public ParserItem {
|
||||
public:
|
||||
ParserStringItem(const std::string& itemName);
|
||||
ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType);
|
||||
ParserStringItem(const std::string& itemName, ParserItemSizeEnum sizeType, const std::string& defaultValue);
|
||||
ParserStringItem(const std::string& itemName, const std::string& defaultValue);
|
||||
explicit ParserStringItem( const Json::JsonObject& jsonConfig);
|
||||
|
||||
bool equal(const ParserItem& other) const override;
|
||||
DeckItem scan( RawRecord& rawRecord ) const override;
|
||||
|
||||
std::string createCode() const override;
|
||||
void inlineClass(std::ostream& os, const std::string& indent) const override;
|
||||
std::string inlineClassInit(const std::string& parentClass) const override;
|
||||
void setDefault(const std::string& defaultValue);
|
||||
std::string getDefault() const;
|
||||
bool hasDefault() const;
|
||||
|
||||
private:
|
||||
std::string m_default;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* PARSERSTRINGITEM_HPP */
|
||||
|
||||
@@ -25,28 +25,6 @@
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestItemSizeEnum2String) {
|
||||
BOOST_CHECK_EQUAL( "ALL" , ParserItemSizeEnum2String(ALL));
|
||||
BOOST_CHECK_EQUAL( "SINGLE" , ParserItemSizeEnum2String(SINGLE));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestItemSizeEnumFromString) {
|
||||
BOOST_CHECK_THROW( ParserItemSizeEnumFromString("XXX") , std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( ALL , ParserItemSizeEnumFromString("ALL"));
|
||||
BOOST_CHECK_EQUAL( SINGLE , ParserItemSizeEnumFromString("SINGLE"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestItemSizeEnumLoop) {
|
||||
BOOST_CHECK_EQUAL( ALL , ParserItemSizeEnumFromString( ParserItemSizeEnum2String( ALL ) ));
|
||||
BOOST_CHECK_EQUAL( SINGLE , ParserItemSizeEnumFromString( ParserItemSizeEnum2String( SINGLE ) ));
|
||||
|
||||
BOOST_CHECK_EQUAL( "ALL" , ParserItemSizeEnum2String(ParserItemSizeEnumFromString( "ALL" ) ));
|
||||
BOOST_CHECK_EQUAL( "SINGLE" , ParserItemSizeEnum2String(ParserItemSizeEnumFromString( "SINGLE" ) ));
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestKeywordSizeEnum2String) {
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
|
||||
@@ -36,62 +33,55 @@
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
BOOST_CHECK_NO_THROW(ParserIntItem item1("ITEM1", sizeType));
|
||||
BOOST_CHECK_NO_THROW(ParserStringItem item1("ITEM1", sizeType));
|
||||
BOOST_CHECK_NO_THROW(ParserDoubleItem item1("ITEM1", sizeType));
|
||||
auto sizeType = ParserItem::item_size::SINGLE;
|
||||
BOOST_CHECK_NO_THROW(ParserItem item1("ITEM1", sizeType));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ScalarCheck) {
|
||||
ParserIntItem item1("ITEM1", SINGLE);
|
||||
ParserIntItem item2("ITEM1", ALL);
|
||||
ParserItem item1("ITEM1", ParserItem::item_size::SINGLE );
|
||||
ParserItem item2("ITEM1", ParserItem::item_size::ALL );
|
||||
|
||||
BOOST_CHECK( item1.scalar());
|
||||
BOOST_CHECK( item1.scalar());
|
||||
BOOST_CHECK( !item2.scalar());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize_DefaultSizeType) {
|
||||
ParserIntItem item1(std::string("ITEM1"));
|
||||
ParserStringItem item2(std::string("ITEM1"));
|
||||
ParserDoubleItem item3(std::string("ITEM1"));
|
||||
|
||||
BOOST_CHECK_EQUAL( SINGLE , item1.sizeType());
|
||||
BOOST_CHECK_EQUAL( SINGLE , item2.sizeType());
|
||||
BOOST_CHECK_EQUAL( SINGLE , item3.sizeType());
|
||||
ParserItem item1(std::string("ITEM1"));
|
||||
BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE, item1.sizeType());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize_Default) {
|
||||
ParserIntItem item1(std::string("ITEM1"));
|
||||
ParserIntItem item2(std::string("ITEM1"), 88);
|
||||
ParserItem item1(std::string("ITEM1"));
|
||||
ParserItem item2(std::string("ITEM1"), 88);
|
||||
BOOST_CHECK(!item1.hasDefault());
|
||||
BOOST_CHECK_THROW(item1.getDefault(), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(item1.getDefault< int >(), std::invalid_argument);
|
||||
BOOST_CHECK(item2.hasDefault());
|
||||
BOOST_CHECK_EQUAL(item2.getDefault(), 88);
|
||||
BOOST_CHECK_EQUAL(item2.getDefault< int >(), 88);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize_Default_Double) {
|
||||
ParserDoubleItem item1(std::string("ITEM1"));
|
||||
ParserDoubleItem item2("ITEM1", 88.91);
|
||||
ParserItem item1(std::string("ITEM1"));
|
||||
ParserItem item2("ITEM1", 88.91);
|
||||
BOOST_CHECK(!item1.hasDefault());
|
||||
BOOST_CHECK_THROW(item1.getDefault(), std::invalid_argument);
|
||||
BOOST_CHECK_EQUAL( 88.91 , item2.getDefault());
|
||||
BOOST_CHECK_THROW( item1.getDefault< double >(), std::invalid_argument );
|
||||
BOOST_CHECK_EQUAL( 88.91 , item2.getDefault< double >());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Initialize_Default_String) {
|
||||
ParserStringItem item1(std::string("ITEM1"));
|
||||
ParserItem item1(std::string("ITEM1"));
|
||||
BOOST_CHECK(!item1.hasDefault());
|
||||
BOOST_CHECK_THROW(item1.getDefault(), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(item1.getDefault< std::string >(), std::invalid_argument);
|
||||
|
||||
ParserStringItem item2("ITEM1", "String");
|
||||
ParserItem item2("ITEM1", "String");
|
||||
BOOST_CHECK(item2.hasDefault());
|
||||
BOOST_CHECK_EQUAL( "String" , item2.getDefault());
|
||||
BOOST_CHECK_EQUAL( "String" , item2.getDefault< std::string >());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) {
|
||||
ParserIntItem itemInt(std::string("ITEM2"), 123);
|
||||
ParserItem itemInt("ITEM2", 123);
|
||||
|
||||
RawRecord rawRecord1( "" );
|
||||
const auto defaulted = itemInt.scan(rawRecord1);
|
||||
@@ -101,7 +91,7 @@ BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_setDescription_canReadBack) {
|
||||
ParserIntItem itemInt(std::string("ITEM1"));
|
||||
ParserItem itemInt("ITEM1");
|
||||
std::string description("This is the description");
|
||||
itemInt.setDescription(description);
|
||||
|
||||
@@ -113,59 +103,59 @@ BOOST_AUTO_TEST_CASE(InitializeIntItem_setDescription_canReadBack) {
|
||||
/* <Json> */
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_missingName_throws) {
|
||||
Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}");
|
||||
BOOST_CHECK_THROW( ParserIntItem item1( jsonConfig ) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_defaultSizeType) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" }");
|
||||
ParserIntItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( SINGLE , item1.sizeType());
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }");
|
||||
ParserItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE , item1.sizeType());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\"}");
|
||||
ParserIntItem item1( jsonConfig );
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"value_type\": \"INT\" }");
|
||||
ParserItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( "ITEM1" , item1.name() );
|
||||
BOOST_CHECK_EQUAL( ALL , item1.sizeType() );
|
||||
BOOST_CHECK(item1.getDefault() < 0);
|
||||
BOOST_CHECK_EQUAL( ParserItem::item_size::ALL, item1.sizeType() );
|
||||
BOOST_CHECK(item1.getDefault< int >() < 0);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefault) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : 100}");
|
||||
ParserIntItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( 100 , item1.getDefault() );
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : 100, \"value_type\": \"INT\" }");
|
||||
ParserItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( 100 , item1.getDefault< int >() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefaultInvalid_throws) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : \"100X\"}");
|
||||
BOOST_CHECK_THROW( ParserIntItem item1( jsonConfig ) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withSizeTypeALL_throws) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"default\" : 100}");
|
||||
BOOST_CHECK_THROW( ParserIntItem item1( jsonConfig ) , std::invalid_argument );
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"size_type\" : \"ALL\", \"default\" : 100}");
|
||||
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_WithDescription_DescriptionPropertyShouldBePopulated) {
|
||||
std::string description("Description goes here");
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"description\" : \"Description goes here\"}");
|
||||
ParserIntItem item(jsonConfig);
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"description\" : \"Description goes here\"}");
|
||||
ParserItem item(jsonConfig);
|
||||
|
||||
BOOST_CHECK_EQUAL( "Description goes here", item.getDescription() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeIntItem_WithoutDescription_DescriptionPropertyShouldBeEmpty) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\"}");
|
||||
ParserIntItem item(jsonConfig);
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }");
|
||||
ParserItem item(jsonConfig);
|
||||
|
||||
BOOST_CHECK_EQUAL( "", item.getDescription() );
|
||||
}
|
||||
@@ -179,109 +169,96 @@ BOOST_AUTO_TEST_CASE(InitializeIntItem_WithoutDescription_DescriptionPropertySho
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(IntItem_Equal_ReturnsTrue) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem item1("ITEM1", sizeType);
|
||||
ParserIntItem item2("ITEM1", sizeType);
|
||||
ParserIntItem item3 = item1;
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem item1("ITEM1", sizeType);
|
||||
ParserItem item2("ITEM1", sizeType);
|
||||
ParserItem item3 = item1;
|
||||
|
||||
BOOST_CHECK( item1.equal( item2 ));
|
||||
BOOST_CHECK( item1.equal( item3 ));
|
||||
BOOST_CHECK_EQUAL( item1, item2 );
|
||||
BOOST_CHECK_EQUAL( item1, item3 );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(IntItem_Different_ReturnsFalse) {
|
||||
ParserIntItem item1("ITEM1", ALL);
|
||||
ParserIntItem item2("ITEM2", ALL);
|
||||
ParserIntItem item3(std::string("ITEM1"));
|
||||
ParserIntItem item4("ITEM1" , 42);
|
||||
ParserItem item1("ITEM1", ParserItem::item_size::ALL);
|
||||
ParserItem item2("ITEM2", ParserItem::item_size::ALL);
|
||||
ParserItem item3("ITEM1");
|
||||
ParserItem item4("ITEM1" , 42);
|
||||
|
||||
BOOST_CHECK( !item1.equal( item2 ));
|
||||
BOOST_CHECK( !item1.equal( item3 ));
|
||||
BOOST_CHECK( !item2.equal( item3 ));
|
||||
BOOST_CHECK( !item4.equal( item3 ));
|
||||
BOOST_CHECK_NE( item1, item2 );
|
||||
BOOST_CHECK_NE( item1, item3 );
|
||||
BOOST_CHECK_NE( item2, item3 );
|
||||
BOOST_CHECK_NE( item4, item3 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DoubleItem_Equal_ReturnsTrue) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserDoubleItem item1("ITEM1", sizeType);
|
||||
ParserDoubleItem item2("ITEM1", sizeType);
|
||||
ParserDoubleItem item3 = item1;
|
||||
|
||||
BOOST_CHECK( item1.equal( item2 ));
|
||||
BOOST_CHECK( item1.equal( item3 ));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DoubleItem_DimEqual_ReturnsTrue) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserDoubleItem item1("ITEM1", sizeType);
|
||||
ParserDoubleItem item2("ITEM1", sizeType);
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem item1("ITEM1", sizeType, 0.0);
|
||||
ParserItem item2("ITEM1", sizeType, 0.0);
|
||||
|
||||
item1.push_backDimension("Length*Length");
|
||||
item2.push_backDimension("Length*Length");
|
||||
|
||||
BOOST_CHECK( item1.equal( item2 ));
|
||||
BOOST_CHECK_EQUAL( item1, item2 );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DoubleItem_DimDifferent_ReturnsFalse) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserDoubleItem item1("ITEM1", sizeType); // Dim: []
|
||||
ParserDoubleItem item2("ITEM1", sizeType); // Dim: [Length]
|
||||
ParserDoubleItem item3("ITEM1", sizeType); // Dim: [Length ,Length]
|
||||
ParserDoubleItem item4("ITEM1", sizeType); // Dim: [t]
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem item1("ITEM1", sizeType, 0.0); // Dim: []
|
||||
ParserItem item2("ITEM1", sizeType, 0.0); // Dim: [Length]
|
||||
ParserItem item3("ITEM1", sizeType, 0.0); // Dim: [Length ,Length]
|
||||
ParserItem item4("ITEM1", sizeType, 0.0); // Dim: [t]
|
||||
|
||||
item2.push_backDimension("Length");
|
||||
|
||||
item3.push_backDimension("Length");
|
||||
item3.push_backDimension("Length");
|
||||
|
||||
item4.push_backDimension("Time");
|
||||
|
||||
BOOST_CHECK_EQUAL(false , item1.equal( item2 ));
|
||||
BOOST_CHECK_EQUAL(false , item2.equal( item3 ));
|
||||
BOOST_CHECK_EQUAL(false , item2.equal( item1 ));
|
||||
BOOST_CHECK_EQUAL(false , item2.equal( item4 ));
|
||||
BOOST_CHECK_EQUAL(false , item1.equal( item3 ));
|
||||
BOOST_CHECK_EQUAL(false , item3.equal( item1 ));
|
||||
BOOST_CHECK_EQUAL(false , item4.equal( item2 ));
|
||||
BOOST_CHECK_NE(item1, item2 );
|
||||
BOOST_CHECK_NE(item2, item3 );
|
||||
BOOST_CHECK_NE(item2, item1 );
|
||||
BOOST_CHECK_NE(item2, item4 );
|
||||
BOOST_CHECK_NE(item1, item3 );
|
||||
BOOST_CHECK_NE(item3, item1 );
|
||||
BOOST_CHECK_NE(item4, item2 );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DoubleItem_Different_ReturnsFalse) {
|
||||
ParserDoubleItem item1("ITEM1", ALL);
|
||||
ParserDoubleItem item2("ITEM2", ALL);
|
||||
ParserDoubleItem item3(std::string("ITEM1") );
|
||||
ParserDoubleItem item4("ITEM1" , 42.89);
|
||||
ParserItem item1("ITEM1", ParserItem::item_size::ALL, 0.0);
|
||||
ParserItem item2("ITEM2", ParserItem::item_size::ALL, 0.0);
|
||||
ParserItem item3("ITEM1", 0.0 );
|
||||
ParserItem item4("ITEM1", 42.89);
|
||||
|
||||
BOOST_CHECK( !item1.equal( item2 ));
|
||||
BOOST_CHECK( !item1.equal( item3 ));
|
||||
BOOST_CHECK( !item2.equal( item3 ));
|
||||
BOOST_CHECK( !item4.equal( item3 ));
|
||||
BOOST_CHECK_NE( item1, item2 );
|
||||
BOOST_CHECK_NE( item1, item3 );
|
||||
BOOST_CHECK_NE( item2, item3 );
|
||||
BOOST_CHECK_NE( item4, item3 );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(StringItem_Equal_ReturnsTrue) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserStringItem item1("ITEM1", sizeType);
|
||||
ParserStringItem item2("ITEM1", sizeType);
|
||||
ParserStringItem item3 = item1;
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem item1("ITEM1", sizeType, "");
|
||||
ParserItem item2("ITEM1", sizeType, "");
|
||||
ParserItem item3 = item1;
|
||||
|
||||
BOOST_CHECK( item1.equal( item2 ));
|
||||
BOOST_CHECK( item1.equal( item3 ));
|
||||
BOOST_CHECK_EQUAL( item1, item2 );
|
||||
BOOST_CHECK_EQUAL( item1, item3 );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(StringItem_Different_ReturnsFalse) {
|
||||
ParserStringItem item1("ITEM1", ALL);
|
||||
ParserStringItem item2("ITEM2", ALL);
|
||||
ParserStringItem item3(std::string("ITEM1") );
|
||||
ParserStringItem item4("ITEM1" , "42.89");
|
||||
ParserItem item1("ITEM1", ParserItem::item_size::ALL, "");
|
||||
ParserItem item2("ITEM2", ParserItem::item_size::ALL, "");
|
||||
ParserItem item3("ITEM1", "" );
|
||||
ParserItem item4("ITEM1", "42.89");
|
||||
|
||||
BOOST_CHECK( !item1.equal( item2 ));
|
||||
BOOST_CHECK( !item1.equal( item3 ));
|
||||
BOOST_CHECK( !item2.equal( item3 ));
|
||||
BOOST_CHECK( !item4.equal( item3 ));
|
||||
BOOST_CHECK_NE( item1, item2 );
|
||||
BOOST_CHECK_NE( item1, item3 );
|
||||
BOOST_CHECK_NE( item2, item3 );
|
||||
BOOST_CHECK_NE( item4, item3 );
|
||||
}
|
||||
|
||||
|
||||
@@ -290,56 +267,57 @@ BOOST_AUTO_TEST_CASE(StringItem_Different_ReturnsFalse) {
|
||||
/******************************************************************/
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Name_ReturnsCorrectName) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
|
||||
ParserIntItem item1("ITEM1", sizeType);
|
||||
ParserItem item1("ITEM1", sizeType);
|
||||
BOOST_CHECK_EQUAL("ITEM1", item1.name());
|
||||
|
||||
ParserIntItem item2("", sizeType);
|
||||
ParserItem item2("", sizeType);
|
||||
BOOST_CHECK_EQUAL("", item2.name());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeSingle) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserIntItem item1("ITEM1", sizeType);
|
||||
auto sizeType = ParserItem::item_size::SINGLE;
|
||||
ParserItem item1("ITEM1", sizeType);
|
||||
BOOST_CHECK_EQUAL(sizeType, item1.sizeType());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeAll) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem item1("ITEM1", sizeType);
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem item1("ITEM1", sizeType);
|
||||
BOOST_CHECK_EQUAL(sizeType, item1.sizeType());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM", sizeType);
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem itemInt("ITEM", sizeType, 0);
|
||||
|
||||
RawRecord rawRecord( "100 443 10*77 10*1 25" );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(23U, deckIntItem.size());
|
||||
BOOST_CHECK_EQUAL(77, deckIntItem.get< int >(3));
|
||||
BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(21));
|
||||
BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(22));
|
||||
BOOST_CHECK_EQUAL(77, deckIntItem.get< int >(3));
|
||||
BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(21));
|
||||
BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(22));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM", sizeType);
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem itemInt("ITEM", sizeType);
|
||||
itemInt.setType( int() );
|
||||
|
||||
RawRecord rawRecord( "100 10* 10*1 25" );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(22U, deckIntItem.size());
|
||||
BOOST_CHECK(!deckIntItem.defaultApplied(0));
|
||||
BOOST_CHECK(deckIntItem.defaultApplied(1));
|
||||
BOOST_CHECK( deckIntItem.defaultApplied(1));
|
||||
BOOST_CHECK(!deckIntItem.defaultApplied(11));
|
||||
BOOST_CHECK(!deckIntItem.defaultApplied(21));
|
||||
BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(20));
|
||||
BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(20));
|
||||
BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(21));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) {
|
||||
ParserIntItem itemInt(std::string("ITEM2"));
|
||||
ParserItem itemInt(std::string("ITEM2"), 0);
|
||||
|
||||
RawRecord rawRecord("100 44.3 'Heisann'" );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
@@ -347,9 +325,9 @@ BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1(std::string("ITEM1"));
|
||||
ParserIntItem itemInt2(std::string("ITEM2"));
|
||||
ParserIntItem itemInt3(std::string("ITEM3"));
|
||||
ParserItem itemInt1(std::string("ITEM1"), 0);
|
||||
ParserItem itemInt2(std::string("ITEM2"), 0);
|
||||
ParserItem itemInt3(std::string("ITEM3"), 0);
|
||||
|
||||
RawRecord rawRecord( "100 443 338932 222.33 'Heisann' " );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
@@ -367,8 +345,8 @@ BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem itemInt("ITEM2", sizeType, 0);
|
||||
|
||||
RawRecord rawRecord( "3*4 " );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
@@ -378,16 +356,16 @@ BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_StarNoMultiplier_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserIntItem itemInt("ITEM2", sizeType , 100);
|
||||
auto sizeType = ParserItem::item_size::SINGLE;
|
||||
ParserItem itemInt("ITEM2", sizeType , 100);
|
||||
|
||||
RawRecord rawRecord( "*45 " );
|
||||
BOOST_CHECK_THROW(itemInt.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1(std::string("ITEM1"));
|
||||
ParserIntItem itemInt2(std::string("ITEM2"));
|
||||
ParserItem itemInt1(std::string("ITEM1"), 0);
|
||||
ParserItem itemInt2(std::string("ITEM2"), 0);
|
||||
|
||||
RawRecord rawRecord( "10 20" );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
@@ -398,8 +376,8 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
ParserIntItem itemInt2("ITEM2", 20);
|
||||
ParserItem itemInt1("ITEM1", 10);
|
||||
ParserItem itemInt2("ITEM2", 20);
|
||||
|
||||
RawRecord rawRecord( "* * " );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
@@ -410,8 +388,8 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
ParserIntItem itemInt2("ITEM2", 20);
|
||||
ParserItem itemInt1("ITEM1", 10);
|
||||
ParserItem itemInt2("ITEM2", 20);
|
||||
|
||||
RawRecord rawRecord( "2*30" );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
@@ -422,22 +400,22 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplier_Throw) {
|
||||
ParserIntItem itemInt1("ITEM1" , 10);
|
||||
ParserItem itemInt1("ITEM1" , 10);
|
||||
|
||||
RawRecord rawRecord( "2.10*30" );
|
||||
BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplierChar_Throw) {
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
ParserItem itemInt1("ITEM1", 10);
|
||||
|
||||
RawRecord rawRecord( "210X30" );
|
||||
BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
ParserIntItem itemInt2("ITEM2", 20);
|
||||
ParserItem itemInt1("ITEM1", 10);
|
||||
ParserItem itemInt2("ITEM2", 20);
|
||||
|
||||
RawRecord rawRecord( "2*" );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
@@ -448,7 +426,7 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_RawRecordErrorInRawData_ExceptionThrown) {
|
||||
ParserIntItem itemInt(std::string("ITEM2"));
|
||||
ParserItem itemInt(std::string("ITEM2"), 0);
|
||||
|
||||
// Wrong type
|
||||
RawRecord rawRecord2( "333.2 /" );
|
||||
@@ -469,38 +447,24 @@ BOOST_AUTO_TEST_CASE(Scan_RawRecordErrorInRawData_ExceptionThrown) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_missingName_throws) {
|
||||
Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}");
|
||||
BOOST_CHECK_THROW( ParserStringItem item1( jsonConfig ) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\"}");
|
||||
ParserStringItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( "ITEM1" , item1.name() );
|
||||
BOOST_CHECK_EQUAL( ALL , item1.sizeType() );
|
||||
BOOST_CHECK(item1.getDefault() == "");
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefault) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : \"100\"}");
|
||||
ParserStringItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( "100" , item1.getDefault() );
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"STRING\", \"size_type\" : \"SINGLE\", \"default\" : \"100\"}");
|
||||
ParserItem item1( jsonConfig );
|
||||
BOOST_CHECK_EQUAL( "100" , item1.getDefault< std::string >() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefaultInvalid_throws) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"default\" : [1,2,3]}");
|
||||
BOOST_CHECK_THROW( ParserStringItem item1( jsonConfig ) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
||||
}
|
||||
/*</json>*/
|
||||
/*****************************************************************/
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_defaultvalue_defaultset) {
|
||||
ParserStringItem itemString(std::string("ITEM1") , "DEFAULT");
|
||||
ParserItem itemString(std::string("ITEM1") , "DEFAULT");
|
||||
RawRecord rawRecord( "'1*'" );
|
||||
BOOST_CHECK_EQUAL("1*", itemString.scan( rawRecord ).get< std::string >(0) );
|
||||
|
||||
@@ -510,14 +474,14 @@ BOOST_AUTO_TEST_CASE(init_defaultvalue_defaultset) {
|
||||
RawRecord rawRecord2( "*" );
|
||||
BOOST_CHECK_EQUAL("DEFAULT", itemString.scan( rawRecord2 ).get< std::string >(0) );
|
||||
|
||||
ParserStringItem itemStringDefaultChanged("ITEM2", "SPECIAL");
|
||||
ParserItem itemStringDefaultChanged("ITEM2", "SPECIAL");
|
||||
RawRecord rawRecord3( "*" );
|
||||
BOOST_CHECK_EQUAL("SPECIAL", itemStringDefaultChanged.scan( rawRecord3 ).get< std::string >(0) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserStringItem itemString("ITEMWITHMANY", sizeType);
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem itemString("ITEMWITHMANY", sizeType, "");
|
||||
RawRecord rawRecord( "'WELL1' FISK BANAN 3*X OPPLEGG_FOR_DATAANALYSE 'Foo$*!% BAR' " );
|
||||
const auto deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(8U, deckItem.size());
|
||||
@@ -533,19 +497,19 @@ BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_all_withdefaults) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemString("ITEMWITHMANY", sizeType);
|
||||
auto sizeType = ParserItem::item_size::ALL;
|
||||
ParserItem itemString("ITEMWITHMANY", sizeType, 0);
|
||||
RawRecord rawRecord( "10*1 10* 10*2 " );
|
||||
const auto deckItem = itemString.scan(rawRecord);
|
||||
|
||||
BOOST_CHECK_EQUAL(30U, deckItem.size());
|
||||
|
||||
BOOST_CHECK_EQUAL(false, deckItem.defaultApplied(0));
|
||||
BOOST_CHECK_EQUAL(false, deckItem.defaultApplied(9));
|
||||
BOOST_CHECK_EQUAL(true, deckItem.defaultApplied(10));
|
||||
BOOST_CHECK_EQUAL(true, deckItem.defaultApplied(19));
|
||||
BOOST_CHECK_EQUAL(false, deckItem.defaultApplied(20));
|
||||
BOOST_CHECK_EQUAL(false, deckItem.defaultApplied(29));
|
||||
BOOST_CHECK( !deckItem.defaultApplied(0) );
|
||||
BOOST_CHECK( !deckItem.defaultApplied(9) );
|
||||
BOOST_CHECK( deckItem.defaultApplied(10) );
|
||||
BOOST_CHECK( deckItem.defaultApplied(19) );
|
||||
BOOST_CHECK( !deckItem.defaultApplied(20) );
|
||||
BOOST_CHECK( !deckItem.defaultApplied(29) );
|
||||
|
||||
BOOST_CHECK_THROW(deckItem.get< int >(30), std::out_of_range);
|
||||
BOOST_CHECK_THROW(deckItem.defaultApplied(30), std::out_of_range);
|
||||
@@ -557,7 +521,7 @@ BOOST_AUTO_TEST_CASE(scan_all_withdefaults) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) {
|
||||
ParserStringItem itemString(std::string("ITEM1"));
|
||||
ParserItem itemString( "ITEM1", "");
|
||||
RawRecord rawRecord( "'WELL1' 'WELL2'" );
|
||||
const auto deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(1U, deckItem.size());
|
||||
@@ -565,8 +529,8 @@ BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) {
|
||||
ParserStringItem itemString(std::string("ITEM1"));
|
||||
ParserStringItem itemInt(std::string("ITEM1"));
|
||||
ParserItem itemString("ITEM1", "");
|
||||
ParserItem itemInt("ITEM1", "");
|
||||
|
||||
RawRecord rawRecord( "2 'WELL1' /" );
|
||||
itemInt.scan(rawRecord);
|
||||
@@ -578,13 +542,13 @@ BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) {
|
||||
BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) {
|
||||
RawRecord rawRecord( "'WELL1' 2 2 2*3" );
|
||||
|
||||
ParserItemSizeEnum sizeTypeItemBoxed = ALL;
|
||||
auto sizeTypeItemBoxed = ParserItem::item_size::ALL;
|
||||
|
||||
ParserStringItem itemSingleString(std::string("ITEM1"));
|
||||
ParserItem itemSingleString(std::string("ITEM1"), "");
|
||||
const auto deckItemWell1 = itemSingleString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL("WELL1", deckItemWell1.get< std::string >(0));
|
||||
|
||||
ParserIntItem itemSomeInts("SOMEINTS", sizeTypeItemBoxed);
|
||||
ParserItem itemSomeInts("SOMEINTS", sizeTypeItemBoxed, 0 );
|
||||
const auto deckItemInts = itemSomeInts.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(0));
|
||||
BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(1));
|
||||
@@ -592,32 +556,21 @@ BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) {
|
||||
BOOST_CHECK_EQUAL(3, deckItemInts.get< int >(3));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserItemCheckEqualsOverride) {
|
||||
auto itemDefault10 = std::make_shared< ParserIntItem >( "ITEM" , 10 );
|
||||
auto itemDefault20 = std::make_shared< ParserIntItem >( "ITEM" , 20 );
|
||||
|
||||
BOOST_CHECK( itemDefault10->equal( *itemDefault10 ));
|
||||
BOOST_CHECK_EQUAL( false , itemDefault10->equal( *itemDefault20 ));
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserDefaultHasDimensionReturnsFalse) {
|
||||
ParserIntItem intItem(std::string("SOMEINTS"));
|
||||
ParserStringItem stringItem(std::string("SOMESTRING"));
|
||||
ParserDoubleItem doubleItem(std::string("SOMEDOUBLE"));
|
||||
ParserItem intItem(std::string("SOMEINTS"), 0);
|
||||
ParserItem stringItem(std::string("SOMESTRING"), "");
|
||||
ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0);
|
||||
|
||||
BOOST_CHECK_EQUAL( false, intItem.hasDimension());
|
||||
BOOST_CHECK_EQUAL( false, stringItem.hasDimension());
|
||||
BOOST_CHECK_EQUAL( false, doubleItem.hasDimension());
|
||||
BOOST_CHECK( !intItem.hasDimension() );
|
||||
BOOST_CHECK( !stringItem.hasDimension() );
|
||||
BOOST_CHECK( !doubleItem.hasDimension() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserIntItemGetDimensionThrows) {
|
||||
ParserIntItem intItem(std::string("SOMEINT"));
|
||||
ParserItem intItem(std::string("SOMEINT"));
|
||||
|
||||
BOOST_CHECK_THROW( intItem.getDimension(0) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( intItem.push_backDimension("Length") , std::invalid_argument );
|
||||
@@ -626,7 +579,7 @@ BOOST_AUTO_TEST_CASE(ParserIntItemGetDimensionThrows) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserDoubleItemAddMultipleDimensionToSIngleSizeThrows) {
|
||||
ParserDoubleItem doubleItem(std::string("SOMEDOUBLE"));
|
||||
ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0);
|
||||
|
||||
doubleItem.push_backDimension("Length*Length");
|
||||
BOOST_CHECK_THROW( doubleItem.push_backDimension("Length*Length"), std::invalid_argument);
|
||||
@@ -634,18 +587,18 @@ BOOST_AUTO_TEST_CASE(ParserDoubleItemAddMultipleDimensionToSIngleSizeThrows) {
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserDoubleItemWithDimensionHasReturnsCorrect) {
|
||||
ParserDoubleItem doubleItem(std::string("SOMEDOUBLE"));
|
||||
ParserItem doubleItem("SOMEDOUBLE", 0.0);
|
||||
|
||||
BOOST_CHECK_EQUAL( false , doubleItem.hasDimension() );
|
||||
BOOST_CHECK( !doubleItem.hasDimension() );
|
||||
doubleItem.push_backDimension("Length*Length");
|
||||
BOOST_CHECK_EQUAL( true , doubleItem.hasDimension() );
|
||||
BOOST_CHECK( doubleItem.hasDimension() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserDoubleItemGetDimension) {
|
||||
ParserDoubleItem doubleItem(std::string("SOMEDOUBLE") , ALL);
|
||||
ParserItem doubleItem( "SOMEDOUBLE" , ParserItem::item_size::ALL, 0.0 );
|
||||
|
||||
BOOST_CHECK_THROW( doubleItem.getDimension( 10 ) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( doubleItem.getDimension( 0 ) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( doubleItem.getDimension( 10 ) , std::out_of_range );
|
||||
BOOST_CHECK_THROW( doubleItem.getDimension( 0 ) , std::out_of_range );
|
||||
|
||||
doubleItem.push_backDimension("Length");
|
||||
doubleItem.push_backDimension("Length*Length");
|
||||
@@ -654,5 +607,5 @@ BOOST_AUTO_TEST_CASE(ParserDoubleItemGetDimension) {
|
||||
BOOST_CHECK_EQUAL( "Length" , doubleItem.getDimension(0));
|
||||
BOOST_CHECK_EQUAL( "Length*Length" , doubleItem.getDimension(1));
|
||||
BOOST_CHECK_EQUAL( "Length*Length*Length" , doubleItem.getDimension(2));
|
||||
BOOST_CHECK_THROW( doubleItem.getDimension( 3 ) , std::invalid_argument );
|
||||
BOOST_CHECK_THROW( doubleItem.getDimension( 3 ) , std::out_of_range );
|
||||
}
|
||||
|
||||
@@ -27,14 +27,13 @@
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeywords/A.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawEnums.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
@@ -147,23 +146,23 @@ BOOST_AUTO_TEST_CASE(ParserKeywordMatches) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddDataKeyword_correctlyConfigured) {
|
||||
const auto& parserKeyword = createFixedSized("PORO", (size_t) 1);
|
||||
const auto& item = std::make_shared< ParserIntItem >( "ACTNUM" , ALL);
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
ParserItem item( "ACTNUM" , ParserItem::item_size::ALL, 0 );
|
||||
ParserRecord record;
|
||||
|
||||
BOOST_CHECK_EQUAL( false , parserKeyword->isDataKeyword() );
|
||||
record->addDataItem( item );
|
||||
BOOST_CHECK( !parserKeyword->isDataKeyword() );
|
||||
record.addDataItem( item );
|
||||
parserKeyword->addRecord( record );
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword->isDataKeyword() );
|
||||
BOOST_CHECK( parserKeyword->isDataKeyword() );
|
||||
|
||||
BOOST_CHECK_EQUAL(true , parserKeyword->hasFixedSize( ));
|
||||
BOOST_CHECK( parserKeyword->hasFixedSize() );
|
||||
BOOST_CHECK_EQUAL(1U , parserKeyword->getFixedSize() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(WrongConstructor_addDataItem_throws) {
|
||||
const auto& parserKeyword = createDynamicSized("PORO");
|
||||
const auto& dataItem = std::make_shared< ParserIntItem >( "ACTNUM" , ALL );
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
record->addDataItem( dataItem );
|
||||
ParserItem dataItem( "ACTNUM" , ParserItem::item_size::ALL );
|
||||
ParserRecord record;
|
||||
record.addDataItem( dataItem );
|
||||
BOOST_CHECK_THROW( parserKeyword->addDataRecord( record ) , std::invalid_argument);
|
||||
}
|
||||
|
||||
@@ -270,10 +269,10 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectItemsOK) {
|
||||
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" : [{\"name\" : \"I\", \"value_type\" : \"INT\"}]}");
|
||||
const auto& parserKeyword = std::make_shared<const ParserKeyword>(jsonObject);
|
||||
const auto& record = parserKeyword->getRecord(0);
|
||||
const auto& item = record->get( 0 );
|
||||
BOOST_CHECK_EQUAL( 1U , record->size( ) );
|
||||
BOOST_CHECK_EQUAL( "I" , item->name( ) );
|
||||
BOOST_CHECK_EQUAL( SINGLE , item->sizeType());
|
||||
const auto& item = record.get( 0 );
|
||||
BOOST_CHECK_EQUAL( 1U , record.size( ) );
|
||||
BOOST_CHECK_EQUAL( "I" , item.name( ) );
|
||||
BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE , item.sizeType());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_sizeFromOther) {
|
||||
@@ -296,15 +295,15 @@ BOOST_AUTO_TEST_CASE(AddDataKeywordFromJson_correctlyConfigured) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"ACTNUM\", \"sections\":[\"GRID\"], \"data\" : {\"value_type\": \"INT\"}}");
|
||||
const auto& parserKeyword = std::make_shared<const ParserKeyword>(jsonConfig);
|
||||
const auto& parserRecord = parserKeyword->getRecord(0);
|
||||
const auto& item = parserRecord->get(0);
|
||||
const auto& item = parserRecord.get(0);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword->isDataKeyword());
|
||||
BOOST_CHECK_EQUAL(true , parserKeyword->hasFixedSize( ));
|
||||
BOOST_CHECK( parserKeyword->isDataKeyword() );
|
||||
BOOST_CHECK( parserKeyword->hasFixedSize( ) );
|
||||
BOOST_CHECK_EQUAL(1U , parserKeyword->getFixedSize() );
|
||||
|
||||
BOOST_CHECK_EQUAL( item->name() , ParserKeywords::ACTNUM::data::itemName );
|
||||
BOOST_CHECK_EQUAL( ALL , item->sizeType() );
|
||||
BOOST_CHECK_EQUAL( item.name() , ParserKeywords::ACTNUM::data::itemName );
|
||||
BOOST_CHECK_EQUAL( ParserItem::item_size::ALL, item.sizeType() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AddkeywordFromJson_numTables_incoorect_throw) {
|
||||
@@ -393,15 +392,16 @@ BOOST_AUTO_TEST_CASE(ConstructorIsTableCollection) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseEmptyRecord) {
|
||||
const auto& tabdimsKeyword = createFixedSized("TEST" , 1);
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
auto item = std::make_shared< ParserIntItem >(std::string("ITEM") , ALL);
|
||||
ParserRecord record;
|
||||
ParserItem item("ITEM", ParserItem::item_size::ALL );
|
||||
item.setType( int() );
|
||||
auto rawkeyword = std::make_shared< RawKeyword >( tabdimsKeyword->getName() , "FILE" , 10U , 1 );
|
||||
ParseContext parseContext;
|
||||
MessageContainer msgContainer;
|
||||
|
||||
BOOST_CHECK_EQUAL( Raw::FIXED , rawkeyword->getSizeType());
|
||||
rawkeyword->addRawRecordString("/");
|
||||
record->addItem(item);
|
||||
record.addItem(item);
|
||||
tabdimsKeyword->addRecord( record );
|
||||
|
||||
const auto deckKeyword = tabdimsKeyword->parse( parseContext , msgContainer, rawkeyword );
|
||||
@@ -419,51 +419,53 @@ BOOST_AUTO_TEST_CASE(ParseEmptyRecord) {
|
||||
/* Dimension */
|
||||
BOOST_AUTO_TEST_CASE(ParseKeywordHasDimensionCorrect) {
|
||||
const auto& parserKeyword = createDynamicSized("JA");
|
||||
const auto& itemI = std::make_shared< ParserIntItem >("I", SINGLE);
|
||||
const auto& item2 = std::make_shared< ParserDoubleItem >("ID", SINGLE);
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
ParserItem item1("I", ParserItem::item_size::SINGLE, 0 );
|
||||
ParserItem item2("ID", ParserItem::item_size::SINGLE, 0.0 );
|
||||
ParserRecord record;
|
||||
|
||||
BOOST_CHECK_EQUAL( false , parserKeyword->hasDimension());
|
||||
BOOST_CHECK( !parserKeyword->hasDimension());
|
||||
|
||||
record->addItem( itemI );
|
||||
record->addItem( item2 );
|
||||
record.addItem( item1 );
|
||||
parserKeyword->addRecord( record );
|
||||
BOOST_CHECK_EQUAL( false , parserKeyword->hasDimension());
|
||||
BOOST_CHECK_EQUAL( 0U , itemI->numDimensions() );
|
||||
BOOST_CHECK( !parserKeyword->hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 0U , item1.numDimensions() );
|
||||
|
||||
item2->push_backDimension("Length*Length/Time");
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword->hasDimension());
|
||||
BOOST_CHECK_EQUAL( 1U , item2->numDimensions() );
|
||||
item2.push_backDimension("Length*Length/Time");
|
||||
record.addItem( item2 );
|
||||
const auto& parserKeyword2 = createDynamicSized("JA");
|
||||
parserKeyword2->addRecord( record );
|
||||
BOOST_CHECK( parserKeyword2->hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 1U , item2.numDimensions() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimension) {
|
||||
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\" , \"dimension\" : \"Length*Length/Time\"}]}");
|
||||
const auto& parserKeyword = std::make_shared<ParserKeyword>(jsonObject);
|
||||
const auto& record = parserKeyword->getRecord(0);
|
||||
const auto& item = record->get("ItemX");
|
||||
const auto& item = record.get("ItemX");
|
||||
|
||||
BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName());
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() );
|
||||
BOOST_CHECK( parserKeyword->hasFixedSize() );
|
||||
BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() );
|
||||
|
||||
BOOST_CHECK( parserKeyword->hasDimension() );
|
||||
BOOST_CHECK( item->hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 1U , item->numDimensions() );
|
||||
BOOST_CHECK( item.hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 1U , item.numDimensions() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withDimensionList) {
|
||||
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"ALL\" , \"value_type\" : \"DOUBLE\" , \"dimension\" : [\"Length*Length/Time\" , \"Time\", \"1\"]}]}");
|
||||
const auto& parserKeyword = std::make_shared<ParserKeyword>(jsonObject);
|
||||
const auto& record = parserKeyword->getRecord(0);
|
||||
const auto& item = record->get("ItemX");
|
||||
const auto& item = record.get("ItemX");
|
||||
|
||||
BOOST_CHECK_EQUAL("BPR" , parserKeyword->getName());
|
||||
BOOST_CHECK_EQUAL( true , parserKeyword->hasFixedSize() );
|
||||
BOOST_CHECK_EQUAL( 100U , parserKeyword->getFixedSize() );
|
||||
|
||||
BOOST_CHECK( parserKeyword->hasDimension() );
|
||||
BOOST_CHECK( item->hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 3U , item->numDimensions() );
|
||||
BOOST_CHECK( item.hasDimension() );
|
||||
BOOST_CHECK_EQUAL( 3U , item.numDimensions() );
|
||||
}
|
||||
|
||||
|
||||
@@ -485,7 +487,7 @@ BOOST_AUTO_TEST_CASE(ConstructFromJson_withRecords) {
|
||||
auto kw1 = std::make_shared<ParserKeyword>( jsonObject1 );
|
||||
auto kw2 = std::make_shared<ParserKeyword>( jsonObject2 );
|
||||
|
||||
BOOST_CHECK( kw1->equal( *kw2 ));
|
||||
BOOST_CHECK_EQUAL( *kw1, *kw2 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,17 +26,19 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
#include "opm/parser/eclipse/RawDeck/RawKeyword.hpp"
|
||||
#include "opm/parser/eclipse/Parser/ParserKeyword.hpp"
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
|
||||
const static auto SINGLE = ParserItem::item_size::SINGLE;
|
||||
const static auto ALL = ParserItem::item_size::ALL;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultConstructor_NoParams_NoThrow) {
|
||||
BOOST_CHECK_NO_THROW(ParserRecord record);
|
||||
}
|
||||
@@ -47,14 +49,14 @@ BOOST_AUTO_TEST_CASE(Size_NoElements_ReturnsZero) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Size_OneItem_Return1) {
|
||||
auto itemInt = std::make_shared< ParserIntItem >("ITEM1", SINGLE );
|
||||
ParserItem itemInt("ITEM1", SINGLE );
|
||||
ParserRecord record;
|
||||
record.addItem(itemInt);
|
||||
BOOST_CHECK_EQUAL(1U, record.size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Get_OneItem_Return1) {
|
||||
auto itemInt = std::make_shared< ParserIntItem >("ITEM1", SINGLE);
|
||||
ParserItem itemInt("ITEM1", SINGLE);
|
||||
ParserRecord record;
|
||||
record.addItem(itemInt);
|
||||
|
||||
@@ -71,14 +73,14 @@ BOOST_AUTO_TEST_CASE(Get_KeyNotFound_Throw) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Get_KeyFound_OK) {
|
||||
auto itemInt = std::make_shared< ParserIntItem >("ITEM1", SINGLE );
|
||||
ParserItem itemInt("ITEM1", SINGLE );
|
||||
ParserRecord record;
|
||||
record.addItem(itemInt);
|
||||
BOOST_CHECK_EQUAL(record.get("ITEM1"), itemInt);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Get_GetByNameAndIndex_OK) {
|
||||
auto itemInt = std::make_shared< ParserIntItem >("ITEM1", SINGLE);
|
||||
ParserItem itemInt("ITEM1", SINGLE);
|
||||
ParserRecord record;
|
||||
record.addItem(itemInt);
|
||||
|
||||
@@ -89,16 +91,16 @@ BOOST_AUTO_TEST_CASE(Get_GetByNameAndIndex_OK) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addItem_SameName_Throw) {
|
||||
auto itemInt1 = std::make_shared< ParserIntItem >("ITEM1", SINGLE);
|
||||
auto itemInt2 = std::make_shared< ParserIntItem >("ITEM1", SINGLE);
|
||||
ParserItem itemInt1("ITEM1", SINGLE);
|
||||
ParserItem itemInt2("ITEM1", SINGLE);
|
||||
ParserRecord record;
|
||||
record.addItem(itemInt1);
|
||||
BOOST_CHECK_THROW(record.addItem(itemInt2), std::invalid_argument);
|
||||
}
|
||||
|
||||
static ParserRecord createSimpleParserRecord() {
|
||||
auto itemInt1 = std::make_shared< ParserIntItem >("ITEM1", SINGLE);
|
||||
auto itemInt2 = std::make_shared< ParserIntItem >("ITEM2", SINGLE);
|
||||
ParserItem itemInt1("ITEM1", SINGLE, 0 );
|
||||
ParserItem itemInt2("ITEM2", SINGLE, 0 );
|
||||
ParserRecord record;
|
||||
|
||||
record.addItem(itemInt1);
|
||||
@@ -128,13 +130,13 @@ BOOST_AUTO_TEST_CASE(parse_validRecord_deckRecordCreated) {
|
||||
|
||||
static ParserRecord createMixedParserRecord() {
|
||||
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
auto itemInt1 = std::make_shared< ParserIntItem >("INTITEM1", sizeType);
|
||||
auto itemInt2 = std::make_shared< ParserIntItem >("INTITEM2", sizeType);
|
||||
auto itemInt3 = std::make_shared< ParserIntItem >("INTITEM3", sizeType);
|
||||
auto itemDouble1 = std::make_shared< ParserDoubleItem >("DOUBLEITEM1", sizeType);
|
||||
auto itemDouble2 = std::make_shared< ParserDoubleItem >("DOUBLEITEM2", sizeType);
|
||||
auto itemDouble3 = std::make_shared< ParserDoubleItem >("DOUBLEITEM3", sizeType);
|
||||
auto sizeType = SINGLE;
|
||||
ParserItem itemInt1( "INTITEM1", sizeType, 0 );
|
||||
ParserItem itemInt2( "INTITEM2", sizeType, 0 );
|
||||
ParserItem itemInt3( "INTITEM3", sizeType, 0 );
|
||||
ParserItem itemDouble1( "DOUBLEITEM1", sizeType, 0.0 );
|
||||
ParserItem itemDouble2( "DOUBLEITEM2", sizeType, 0.0 );
|
||||
ParserItem itemDouble3( "DOUBLEITEM3", sizeType, 0.0 );
|
||||
|
||||
ParserRecord record;
|
||||
record.addItem(itemInt1);
|
||||
@@ -164,10 +166,10 @@ BOOST_AUTO_TEST_CASE(Equal_Equal_ReturnsTrue) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Equal_Different_ReturnsFalse) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
auto itemInt = std::make_shared< ParserIntItem >("INTITEM1", sizeType, 0);
|
||||
auto itemDouble = std::make_shared< ParserDoubleItem >("DOUBLEITEM1", sizeType, 0);
|
||||
auto itemString = std::make_shared< ParserStringItem >("STRINGITEM1", sizeType);
|
||||
auto sizeType = SINGLE;
|
||||
ParserItem itemInt( "INTITEM1", sizeType, 0 );
|
||||
ParserItem itemDouble( "DOUBLEITEM1", sizeType, 0.0 );
|
||||
ParserItem itemString( "STRINGITEM1", sizeType, "" );
|
||||
ParserRecord record1;
|
||||
ParserRecord record2;
|
||||
ParserRecord record3;
|
||||
@@ -188,9 +190,9 @@ BOOST_AUTO_TEST_CASE(Equal_Different_ReturnsFalse) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
|
||||
ParserRecord parserRecord;
|
||||
auto itemInt = std::make_shared< ParserIntItem >("ITEM1", SINGLE , 100);
|
||||
auto itemString = std::make_shared< ParserStringItem >("ITEM2", SINGLE , "DEFAULT");
|
||||
auto itemDouble = std::make_shared< ParserDoubleItem >("ITEM3", SINGLE , 3.14 );
|
||||
ParserItem itemInt("ITEM1", SINGLE , 100 );
|
||||
ParserItem itemString("ITEM2", SINGLE , "DEFAULT" );
|
||||
ParserItem itemDouble("ITEM3", SINGLE , 3.14 );
|
||||
|
||||
parserRecord.addItem(itemInt);
|
||||
parserRecord.addItem(itemString);
|
||||
@@ -200,9 +202,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
|
||||
// but it seems to appear in the wild. Thus, we interpret this as "1*"...
|
||||
{
|
||||
RawRecord rawRecord( "* " );
|
||||
const auto deckStringItem = itemString->scan(rawRecord);
|
||||
const auto deckIntItem = itemInt->scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble->scan(rawRecord);
|
||||
const auto& deckStringItem = itemString.scan(rawRecord);
|
||||
const auto& deckIntItem = itemInt.scan(rawRecord);
|
||||
const auto& deckDoubleItem = itemDouble.scan(rawRecord);
|
||||
|
||||
BOOST_CHECK(deckStringItem.size() == 1);
|
||||
BOOST_CHECK(deckIntItem.size() == 1);
|
||||
@@ -215,13 +217,13 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
|
||||
|
||||
{
|
||||
RawRecord rawRecord( "" );
|
||||
const auto deckStringItem = itemString->scan(rawRecord);
|
||||
const auto deckIntItem = itemInt->scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble->scan(rawRecord);
|
||||
const auto deckStringItem = itemString.scan(rawRecord);
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble.scan(rawRecord);
|
||||
|
||||
BOOST_CHECK(deckStringItem.size() == 1);
|
||||
BOOST_CHECK(deckIntItem.size() == 1);
|
||||
BOOST_CHECK(deckDoubleItem.size() == 1);
|
||||
BOOST_CHECK_EQUAL(deckStringItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckIntItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1);
|
||||
|
||||
BOOST_CHECK(deckStringItem.defaultApplied(0));
|
||||
BOOST_CHECK(deckIntItem.defaultApplied(0));
|
||||
@@ -234,13 +236,13 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
|
||||
|
||||
// let the raw record be "consumed" by the items. Note that the scan() method
|
||||
// modifies the rawRecord object!
|
||||
const auto deckStringItem = itemString->scan(rawRecord);
|
||||
const auto deckIntItem = itemInt->scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble->scan(rawRecord);
|
||||
const auto& deckStringItem = itemString.scan(rawRecord);
|
||||
const auto& deckIntItem = itemInt.scan(rawRecord);
|
||||
const auto& deckDoubleItem = itemDouble.scan(rawRecord);
|
||||
|
||||
BOOST_CHECK(deckStringItem.size() == 1);
|
||||
BOOST_CHECK(deckIntItem.size() == 1);
|
||||
BOOST_CHECK(deckDoubleItem.size() == 1);
|
||||
BOOST_CHECK_EQUAL(deckStringItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckIntItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1);
|
||||
|
||||
BOOST_CHECK(!deckStringItem.defaultApplied(0));
|
||||
BOOST_CHECK(!deckIntItem.defaultApplied(0));
|
||||
@@ -250,13 +252,13 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
|
||||
// again this is invalid according to the RM, but it is used anyway in the wild...
|
||||
{
|
||||
RawRecord rawRecord( "* * *" );
|
||||
const auto deckStringItem = itemString->scan(rawRecord);
|
||||
const auto deckIntItem = itemInt->scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble->scan(rawRecord);
|
||||
const auto deckStringItem = itemString.scan(rawRecord);
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble.scan(rawRecord);
|
||||
|
||||
BOOST_CHECK(deckStringItem.size() == 1);
|
||||
BOOST_CHECK(deckIntItem.size() == 1);
|
||||
BOOST_CHECK(deckDoubleItem.size() == 1);
|
||||
BOOST_CHECK_EQUAL(deckStringItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckIntItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1);
|
||||
|
||||
BOOST_CHECK(deckStringItem.defaultApplied(0));
|
||||
BOOST_CHECK(deckIntItem.defaultApplied(0));
|
||||
@@ -265,13 +267,13 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
|
||||
|
||||
{
|
||||
RawRecord rawRecord( "3*" );
|
||||
const auto deckStringItem = itemString->scan(rawRecord);
|
||||
const auto deckIntItem = itemInt->scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble->scan(rawRecord);
|
||||
const auto deckStringItem = itemString.scan(rawRecord);
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
const auto deckDoubleItem = itemDouble.scan(rawRecord);
|
||||
|
||||
BOOST_CHECK(deckStringItem.size() == 1);
|
||||
BOOST_CHECK(deckIntItem.size() == 1);
|
||||
BOOST_CHECK(deckDoubleItem.size() == 1);
|
||||
BOOST_CHECK_EQUAL(deckStringItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckIntItem.size(), 1);
|
||||
BOOST_CHECK_EQUAL(deckDoubleItem.size(), 1);
|
||||
|
||||
BOOST_CHECK(deckStringItem.defaultApplied(0));
|
||||
BOOST_CHECK(deckIntItem.defaultApplied(0));
|
||||
@@ -281,9 +283,9 @@ BOOST_AUTO_TEST_CASE(ParseWithDefault_defaultAppliedCorrectInDeck) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) {
|
||||
ParserRecord parserRecord;
|
||||
auto itemI = std::make_shared< ParserIntItem >("I", SINGLE);
|
||||
auto itemJ = std::make_shared< ParserIntItem >("J", SINGLE);
|
||||
auto itemK = std::make_shared< ParserIntItem >("K", SINGLE);
|
||||
ParserItem itemI( "I", SINGLE, 0 );
|
||||
ParserItem itemJ( "J", SINGLE, 0 );
|
||||
ParserItem itemK( "K", SINGLE, 0 );
|
||||
ParseContext parseContext;
|
||||
|
||||
parserRecord.addItem(itemI);
|
||||
@@ -307,9 +309,12 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) {
|
||||
ParserRecord parserRecord;
|
||||
auto itemI = std::make_shared< ParserIntItem >("I", SINGLE);
|
||||
auto itemJ = std::make_shared< ParserIntItem >("J", SINGLE);
|
||||
auto itemK = std::make_shared< ParserIntItem >("K", SINGLE);
|
||||
ParserItem itemI( "I", SINGLE );
|
||||
ParserItem itemJ( "J", SINGLE );
|
||||
ParserItem itemK( "K", SINGLE );
|
||||
itemI.setType( int() );
|
||||
itemJ.setType( int() );
|
||||
itemK.setType( int() );
|
||||
|
||||
parserRecord.addItem(itemI);
|
||||
parserRecord.addItem(itemJ);
|
||||
@@ -330,16 +335,16 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParseRecordHasDimensionCorrect) {
|
||||
ParserRecord parserRecord;
|
||||
auto itemI = std::make_shared< ParserIntItem >( "I", SINGLE );
|
||||
auto item2 = std::make_shared< ParserDoubleItem >( "ID", SINGLE );
|
||||
ParserItem itemI( "I", SINGLE, 0.0 );
|
||||
|
||||
BOOST_CHECK( !parserRecord.hasDimension() );
|
||||
|
||||
parserRecord.addItem( itemI );
|
||||
parserRecord.addItem( item2 );
|
||||
BOOST_CHECK( !parserRecord.hasDimension() );
|
||||
|
||||
item2->push_backDimension("Length*Length/Time");
|
||||
ParserItem item2( "ID", SINGLE, 0.0 );
|
||||
item2.push_backDimension("Length*Length/Time");
|
||||
parserRecord.addItem( item2 );
|
||||
BOOST_CHECK( parserRecord.hasDimension() );
|
||||
}
|
||||
|
||||
@@ -351,8 +356,8 @@ BOOST_AUTO_TEST_CASE(DefaultNotDataRecord) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws1) {
|
||||
ParserRecord record;
|
||||
auto dataItem = std::make_shared< ParserIntItem >( "ACTNUM" , ALL);
|
||||
auto item = std::make_shared< ParserIntItem >( "XXX" , ALL);
|
||||
ParserItem dataItem( "ACTNUM" , ALL );
|
||||
ParserItem item ( "XXX" , ALL );
|
||||
record.addDataItem( dataItem );
|
||||
BOOST_CHECK_THROW( record.addItem( item ) , std::invalid_argument);
|
||||
BOOST_CHECK_THROW( record.addItem( dataItem ) , std::invalid_argument);
|
||||
@@ -360,8 +365,8 @@ BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws1) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws2) {
|
||||
ParserRecord record;
|
||||
auto dataItem = std::make_shared< ParserIntItem >( "ACTNUM" , ALL);
|
||||
auto item = std::make_shared< ParserIntItem >( "XXX" , ALL);
|
||||
ParserItem dataItem( "ACTNUM" , ALL);
|
||||
ParserItem item ( "XXX" , ALL);
|
||||
|
||||
record.addItem( item );
|
||||
BOOST_CHECK_THROW( record.addDataItem( dataItem ) , std::invalid_argument);
|
||||
|
||||
@@ -33,10 +33,6 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
|
||||
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
inline std::unique_ptr< ParserKeyword > createDynamicSized(const std::string& kw) {
|
||||
@@ -251,7 +247,7 @@ BOOST_AUTO_TEST_CASE(ReplaceKeyword) {
|
||||
|
||||
eqldims = parser.getParserKeywordFromDeckName("EQLDIMS");
|
||||
const auto& record = eqldims->getRecord(0);
|
||||
BOOST_CHECK(record->hasItem("NEW"));
|
||||
BOOST_CHECK(record.hasItem("NEW"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
40
opm/parser/eclipse/Utility/Typetools.hpp
Normal file
40
opm/parser/eclipse/Utility/Typetools.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef OPM_TYPETOOLS_HPP
|
||||
#define OPM_TYPETOOLS_HPP
|
||||
|
||||
namespace Opm {
|
||||
|
||||
enum class type_tag {
|
||||
/* for python interop as well as queries, must be manually synchronised
|
||||
* with cdeck_item.cc and opm/deck/item_type_enum.py
|
||||
*/
|
||||
unknown = 0,
|
||||
integer = 1,
|
||||
string = 2,
|
||||
fdouble = 3,
|
||||
};
|
||||
|
||||
inline std::string tag_name( type_tag x ) {
|
||||
switch( x ) {
|
||||
case type_tag::integer: return "int";
|
||||
case type_tag::string: return "std::string";
|
||||
case type_tag::fdouble: return "double";
|
||||
case type_tag::unknown: return "unknown";
|
||||
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
template< typename T > type_tag get_type();
|
||||
template<> inline type_tag get_type< int >() {
|
||||
return type_tag::integer;
|
||||
}
|
||||
template<> inline type_tag get_type< double >() {
|
||||
return type_tag::fdouble;
|
||||
}
|
||||
template<> inline type_tag get_type< std::string >() {
|
||||
return type_tag::string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //OPM_TYPETOOLS_HPP
|
||||
@@ -20,7 +20,7 @@ extern "C" {
|
||||
*/
|
||||
|
||||
int deck_item_get_type( const Opm::DeckItem * item ) {
|
||||
return item->getType();
|
||||
return static_cast< int >( item->getType() );
|
||||
}
|
||||
|
||||
int deck_item_iget_int( const Opm::DeckItem * item , int index) {
|
||||
|
||||
Reference in New Issue
Block a user