Add ParserKeyword member to DeckKeyword

This commit is contained in:
Joakim Hove 2019-09-08 07:56:42 +02:00
parent 49d61cb4f6
commit 15c2e69e9f
5 changed files with 38 additions and 30 deletions

View File

@ -28,15 +28,16 @@
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
namespace Opm {
class ParserKeyword;
class DeckOutput;
class ParserKeyword;
class DeckKeyword {
public:
typedef std::vector< DeckRecord >::const_iterator const_iterator;
explicit DeckKeyword(const ParserKeyword * parserKeyword);
explicit DeckKeyword(const std::string& keywordName);
DeckKeyword(const std::string& keywordName, bool knownKeyword);
DeckKeyword(const ParserKeyword * parserKeyword, const std::string& keywordName);
const std::string& name() const;
void setFixedSize();
@ -59,6 +60,7 @@ namespace Opm {
const std::vector<double>& getRawDoubleData() const;
const std::vector<double>& getSIDoubleData() const;
const std::vector<std::string>& getStringData() const;
const ParserKeyword& parserKeyword() const;
size_t getDataSize() const;
void write( DeckOutput& output ) const;
void write_data( DeckOutput& output ) const;
@ -86,9 +88,9 @@ namespace Opm {
int m_lineNumber;
std::vector< DeckRecord > m_recordList;
bool m_knownKeyword;
bool m_isDataKeyword;
bool m_slashTerminated;
const ParserKeyword * parser_keyword;
};
}

View File

@ -17,28 +17,40 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
#include <opm/parser/eclipse/Deck/DeckOutput.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
namespace Opm {
DeckKeyword::DeckKeyword(const std::string& keywordName) :
m_keywordName(keywordName),
DeckKeyword::DeckKeyword(const std::string& keyword) :
m_keywordName(keyword),
m_lineNumber(-1),
m_knownKeyword(true),
m_isDataKeyword(false),
m_slashTerminated(true)
m_slashTerminated(true),
parser_keyword(nullptr)
{
}
DeckKeyword::DeckKeyword(const std::string& keywordName, bool knownKeyword) :
DeckKeyword::DeckKeyword(const ParserKeyword * parserKeyword) :
m_keywordName(parserKeyword->getName()),
m_lineNumber(-1),
m_isDataKeyword(false),
m_slashTerminated(true),
parser_keyword(parserKeyword)
{
}
DeckKeyword::DeckKeyword(const ParserKeyword * parserKeyword, const std::string& keywordName) :
m_keywordName(keywordName),
m_lineNumber(-1),
m_knownKeyword(knownKeyword),
m_isDataKeyword(false),
m_slashTerminated(true)
m_slashTerminated(true),
parser_keyword(parserKeyword)
{
}
@ -72,6 +84,12 @@ namespace Opm {
return m_isDataKeyword;
}
const ParserKeyword& DeckKeyword::parserKeyword() const {
if (this->parser_keyword)
return *this->parser_keyword;
throw std::logic_error("INTERNAL ERROR: The " + this->m_keywordName + " deck keyword has been instantiated without ParserKeyword information.");
}
const std::string& DeckKeyword::name() const {
return m_keywordName;
@ -82,10 +100,13 @@ namespace Opm {
}
bool DeckKeyword::isKnown() const {
return m_knownKeyword;
return (this->parser_keyword != nullptr);
}
void DeckKeyword::addRecord(DeckRecord&& record) {
if (!this->parser_keyword)
throw std::logic_error("INTERNAL ERROR: The " + this->m_keywordName + " deck keyword has been instantiated without ParserKeyword information - can not add data");
this->m_recordList.push_back( std::move( record ) );
}

View File

@ -852,7 +852,7 @@ bool parseState( ParserState& parserState, const Parser& parser ) {
throw std::invalid_argument(msg);
}
} else {
DeckKeyword deckKeyword( rawKeyword->getKeywordName(), false );
DeckKeyword deckKeyword( rawKeyword->getKeywordName() );
const std::string msg = "The keyword " + rawKeyword->getKeywordName() + " is not recognized";
deckKeyword.setLocation( rawKeyword->getLocation() );
parserState.deck.addKeyword( std::move( deckKeyword ) );

View File

@ -506,7 +506,7 @@ void set_dimensions( ParserItem& item,
if( !rawKeyword.isFinished() )
throw std::invalid_argument("Tried to create a deck keyword from an incomplete raw keyword " + rawKeyword.getKeywordName());
DeckKeyword keyword( rawKeyword.getKeywordName() );
DeckKeyword keyword( this, rawKeyword.getKeywordName() );
keyword.setLocation( rawKeyword.getLocation( ) );
keyword.setDataKeyword( isDataKeyword() );

View File

@ -551,27 +551,12 @@ BOOST_AUTO_TEST_CASE(name_nameSetInConstructor_nameReturned) {
BOOST_AUTO_TEST_CASE(size_noRecords_returnszero) {
DeckKeyword deckKeyword( "KW" );
BOOST_CHECK_EQUAL(0U, deckKeyword.size());
BOOST_CHECK_THROW(deckKeyword.getRecord(0), std::out_of_range);
}
BOOST_AUTO_TEST_CASE(addRecord_onerecord_recordadded) {
DeckKeyword deckKeyword( "KW" );
deckKeyword.addRecord( DeckRecord() );
BOOST_CHECK_EQUAL(1U, deckKeyword.size());
for (auto iter = deckKeyword.begin(); iter != deckKeyword.end(); ++iter) {
//
}
}
BOOST_AUTO_TEST_CASE(getRecord_outofrange_exceptionthrown) {
DeckKeyword deckKeyword( "KW" );
deckKeyword.addRecord(DeckRecord());
BOOST_CHECK_THROW(deckKeyword.getRecord(1), std::out_of_range);
}
BOOST_AUTO_TEST_CASE(setUnknown_wasknown_nowunknown) {
DeckKeyword deckKeyword( "KW", false );
DeckKeyword deckKeyword( "KW" );
BOOST_CHECK(!deckKeyword.isKnown());
}