diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index f0b742c14..7371295d0 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -363,8 +363,7 @@ bool Parser::parseState(std::shared_ptr parserState) const { break; } else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::paths) { - for (size_t i = 0; i < parserState->rawKeyword->size(); i++) { - auto& record = parserState->rawKeyword->getRecord(i); + for( const auto& record : *parserState->rawKeyword ) { std::string pathName = readValueToken(record.getItem(0)); std::string pathValue = readValueToken(record.getItem(1)); parserState->pathMap->insert(std::pair(pathName, pathValue)); diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.cpp b/opm/parser/eclipse/RawDeck/RawKeyword.cpp index 65155f001..3d34b644f 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.cpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.cpp @@ -107,7 +107,13 @@ namespace Opm { RawRecord& RawKeyword::getRecord(size_t index) { - return this->m_records.at( index ); + if( index >= this->m_records.size() ) + throw std::out_of_range( + "Error: looking up record " + std::to_string( index ) + + ", but RawKeyword has only " + + std::to_string( this->m_records.size() ) + " records." ); + + return *std::next( this->m_records.begin(), index ); } bool RawKeyword::isKeywordPrefix(const std::string& line, std::string& keywordName) { @@ -158,6 +164,13 @@ namespace Opm { return m_lineNR; } + RawKeyword::const_iterator RawKeyword::begin() const { + return this->m_records.begin(); + } + + RawKeyword::const_iterator RawKeyword::end() const { + return this->m_records.end(); + } Raw::KeywordSizeEnum RawKeyword::getSizeType() const { return m_sizeType; diff --git a/opm/parser/eclipse/RawDeck/RawKeyword.hpp b/opm/parser/eclipse/RawDeck/RawKeyword.hpp index a7065a020..d37711ac6 100644 --- a/opm/parser/eclipse/RawDeck/RawKeyword.hpp +++ b/opm/parser/eclipse/RawDeck/RawKeyword.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -56,6 +57,10 @@ namespace Opm { const std::string& getFilename() const; size_t getLineNR() const; + using const_iterator = std::list< RawRecord >::const_iterator; + + const_iterator begin() const; + const_iterator end() const; private: Raw::KeywordSizeEnum m_sizeType; @@ -64,7 +69,7 @@ namespace Opm { size_t m_numTables; size_t m_currentNumTables; std::string m_name; - std::vector< RawRecord > m_records; + std::list< RawRecord > m_records; std::string m_partialRecordString; size_t m_lineNR;