Make duplicate name of item check optional in DeckRecord constructor.
This is for catching programmer error mostly, so it has been disabled in the call path used in OPM Flow.
This commit is contained in:
parent
12a41a7b1f
commit
fef696d978
@ -34,7 +34,7 @@ namespace Opm {
|
||||
typedef std::vector< DeckItem >::const_iterator const_iterator;
|
||||
|
||||
DeckRecord() = default;
|
||||
DeckRecord( std::vector< DeckItem >&& );
|
||||
DeckRecord( std::vector< DeckItem >&& items, const bool check_for_duplicate_names = true );
|
||||
|
||||
static DeckRecord serializeObject();
|
||||
|
||||
|
@ -31,26 +31,28 @@
|
||||
namespace Opm {
|
||||
|
||||
|
||||
DeckRecord::DeckRecord( std::vector< DeckItem >&& items ) :
|
||||
DeckRecord::DeckRecord( std::vector< DeckItem >&& items, const bool check_for_duplicate_names ) :
|
||||
m_items( std::move( items ) ) {
|
||||
|
||||
std::unordered_set< std::string > names;
|
||||
for( const auto& item : this->m_items )
|
||||
names.insert( item.name() );
|
||||
if (check_for_duplicate_names) {
|
||||
std::unordered_set< std::string > names;
|
||||
for( const auto& item : this->m_items )
|
||||
names.insert( item.name() );
|
||||
|
||||
if( names.size() == this->m_items.size() )
|
||||
return;
|
||||
if( names.size() == this->m_items.size() )
|
||||
return;
|
||||
|
||||
names.clear();
|
||||
std::string msg = "Duplicate item names in DeckRecord:";
|
||||
for( const auto& item : this->m_items ) {
|
||||
if( names.count( item.name() ) != 0 )
|
||||
msg += std::string( " " ) += item.name();
|
||||
names.clear();
|
||||
std::string msg = "Duplicate item names in DeckRecord:";
|
||||
for( const auto& item : this->m_items ) {
|
||||
if( names.count( item.name() ) != 0 )
|
||||
msg += std::string( " " ) += item.name();
|
||||
|
||||
names.insert( item.name() );
|
||||
names.insert( item.name() );
|
||||
}
|
||||
|
||||
throw std::invalid_argument( msg );
|
||||
}
|
||||
|
||||
throw std::invalid_argument( msg );
|
||||
}
|
||||
|
||||
DeckRecord DeckRecord::serializeObject()
|
||||
|
@ -134,7 +134,7 @@ namespace {
|
||||
parseContext.handleError(ParseContext::PARSE_EXTRA_DATA , msg_format, location, errors);
|
||||
}
|
||||
|
||||
return { std::move( items ) };
|
||||
return { std::move( items ), false };
|
||||
}
|
||||
|
||||
bool ParserRecord::equal(const ParserRecord& other) const {
|
||||
|
Loading…
Reference in New Issue
Block a user