Merge pull request #691 from jokva/parser-keywords-unique
Parser stores keywords as unique_ptr
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
|
||||
|
||||
static void printKeyword(Opm::ParserKeywordConstPtr keyword)
|
||||
static void printKeyword( const Opm::ParserKeyword* keyword)
|
||||
{
|
||||
std::string indent = " ";
|
||||
std::cout << keyword->getName() << std::endl;
|
||||
@@ -65,7 +65,7 @@ static void printItem(Opm::ParserItemConstPtr item, std::string indent)
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
static void printItems(Opm::ParserKeywordConstPtr keyword)
|
||||
static void printItems( const Opm::ParserKeyword* keyword)
|
||||
{
|
||||
std::string indent = " ";
|
||||
std::cout << std::endl;
|
||||
@@ -80,7 +80,7 @@ static void printItems(Opm::ParserKeywordConstPtr keyword)
|
||||
static void printKeywords (Opm::ParserPtr parser, std::vector<std::string>& keywords)
|
||||
{
|
||||
for (auto iterator = keywords.begin(); iterator != keywords.end(); ++iterator) {
|
||||
Opm::ParserKeywordConstPtr keyword = parser->getParserKeywordFromDeckName(*iterator);
|
||||
const auto* keyword = parser->getParserKeywordFromDeckName(*iterator);
|
||||
printKeyword(keyword);
|
||||
printItems(keyword);
|
||||
}
|
||||
|
||||
@@ -37,32 +37,30 @@
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
std::shared_ptr<ParserKeyword> createFixedSized(const std::string& kw , size_t size) {
|
||||
std::shared_ptr<ParserKeyword> pkw = std::make_shared<ParserKeyword>(kw);
|
||||
std::unique_ptr< ParserKeyword > createFixedSized(const std::string& kw , size_t size) {
|
||||
std::unique_ptr< ParserKeyword > pkw( new ParserKeyword( kw ) );
|
||||
pkw->setFixedSize( size );
|
||||
return pkw;
|
||||
}
|
||||
|
||||
std::shared_ptr<ParserKeyword> createDynamicSized(const std::string& kw) {
|
||||
std::shared_ptr<ParserKeyword> pkw = std::make_shared<ParserKeyword>(kw);
|
||||
std::unique_ptr< ParserKeyword > createDynamicSized(const std::string& kw) {
|
||||
std::unique_ptr< ParserKeyword > pkw( new ParserKeyword( kw ) );
|
||||
pkw->setSizeType(SLASH_TERMINATED);
|
||||
return pkw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ParserPtr createWWCTParser() {
|
||||
ParserKeywordPtr parserKeyword = createDynamicSized("WWCT");
|
||||
auto parserKeyword = createDynamicSized("WWCT");
|
||||
{
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
record->addItem( ParserStringItemConstPtr(new ParserStringItem("WELL", ALL)) );
|
||||
parserKeyword->addRecord( record );
|
||||
}
|
||||
ParserKeywordPtr summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
||||
auto summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addParserKeyword(parserKeyword);
|
||||
parser->addParserKeyword(summaryKeyword);
|
||||
parser->addParserKeyword( std::move( parserKeyword ) );
|
||||
parser->addParserKeyword( std::move( summaryKeyword ) );
|
||||
return parser;
|
||||
}
|
||||
|
||||
@@ -143,7 +141,7 @@ BOOST_AUTO_TEST_CASE(parser_internal_name_vs_deck_name) {
|
||||
}
|
||||
|
||||
static ParserPtr createBPRParser() {
|
||||
ParserKeywordPtr parserKeyword = createDynamicSized("BPR");
|
||||
auto parserKeyword = createDynamicSized("BPR");
|
||||
{
|
||||
std::shared_ptr<ParserRecord> bprRecord = std::make_shared<ParserRecord>();
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("I", SINGLE)));
|
||||
@@ -151,10 +149,10 @@ static ParserPtr createBPRParser() {
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("K", SINGLE)));
|
||||
parserKeyword->addRecord( bprRecord );
|
||||
}
|
||||
ParserKeywordPtr summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
||||
auto summaryKeyword = createFixedSized("SUMMARY" , (size_t) 0);
|
||||
ParserPtr parser(new Parser());
|
||||
parser->addParserKeyword(parserKeyword);
|
||||
parser->addParserKeyword(summaryKeyword);
|
||||
parser->addParserKeyword( std::move( parserKeyword ) );
|
||||
parser->addParserKeyword( std::move( summaryKeyword ) );
|
||||
return parser;
|
||||
}
|
||||
|
||||
@@ -233,7 +231,7 @@ BOOST_AUTO_TEST_CASE(parse_truncatedrecords_deckFilledWithDefaults) {
|
||||
BOOST_CHECK(lastItem_1.defaultApplied(0));
|
||||
BOOST_CHECK_EQUAL(lastItem_1.get< int >(0), 1);
|
||||
|
||||
ParserKeywordConstPtr parserKeyword = parser->getParserKeywordFromDeckName("RADFIN4");
|
||||
auto* parserKeyword = parser->getParserKeywordFromDeckName("RADFIN4");
|
||||
ParserRecordConstPtr parserRecord = parserKeyword->getRecord(0);
|
||||
ParserItemConstPtr nwmaxItem = parserRecord->get("NWMAX");
|
||||
ParserIntItemConstPtr intItem = std::static_pointer_cast<const ParserIntItem>(nwmaxItem);
|
||||
|
||||
@@ -263,16 +263,16 @@ namespace Opm {
|
||||
return (m_internalParserKeywords.count(internalKeywordName) > 0);
|
||||
}
|
||||
|
||||
ParserKeywordConstPtr Parser::getParserKeywordFromInternalName(const std::string& internalKeywordName) const {
|
||||
return m_internalParserKeywords.at(internalKeywordName);
|
||||
const ParserKeyword* Parser::getParserKeywordFromInternalName(const std::string& internalKeywordName) const {
|
||||
return m_internalParserKeywords.at(internalKeywordName).get();
|
||||
}
|
||||
|
||||
ParserKeywordConstPtr Parser::matchingKeyword(const std::string& name) const {
|
||||
const ParserKeyword* Parser::matchingKeyword(const std::string& name) const {
|
||||
for (auto iter = m_wildCardKeywords.begin(); iter != m_wildCardKeywords.end(); ++iter) {
|
||||
if (iter->second->matches(name))
|
||||
return iter->second;
|
||||
}
|
||||
return ParserKeywordConstPtr();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Parser::hasWildCardKeyword(const std::string& internalKeywordName) const {
|
||||
@@ -282,127 +282,126 @@ namespace Opm {
|
||||
bool Parser::isRecognizedKeyword(const std::string& deckKeywordName) const {
|
||||
if (!ParserKeyword::validDeckName(deckKeywordName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_deckParserKeywords.count(deckKeywordName) > 0)
|
||||
return true;
|
||||
|
||||
ParserKeywordConstPtr wildCardKeyword = matchingKeyword( deckKeywordName );
|
||||
return wildCardKeyword?true:false;
|
||||
}
|
||||
|
||||
void Parser::addParserKeyword(ParserKeywordConstPtr parserKeyword) {
|
||||
m_internalParserKeywords[parserKeyword->getName()] = parserKeyword;
|
||||
if (m_deckParserKeywords.count(deckKeywordName) > 0)
|
||||
return true;
|
||||
|
||||
for (auto nameIt = parserKeyword->deckNamesBegin();
|
||||
nameIt != parserKeyword->deckNamesEnd();
|
||||
++nameIt)
|
||||
{
|
||||
m_deckParserKeywords[*nameIt] = parserKeyword;
|
||||
}
|
||||
return matchingKeyword( deckKeywordName );
|
||||
}
|
||||
|
||||
if (parserKeyword->hasMatchRegex())
|
||||
m_wildCardKeywords[parserKeyword->getName()] = parserKeyword;
|
||||
void Parser::addParserKeyword( std::unique_ptr< const ParserKeyword >&& parserKeyword) {
|
||||
for (auto nameIt = parserKeyword->deckNamesBegin();
|
||||
nameIt != parserKeyword->deckNamesEnd();
|
||||
++nameIt)
|
||||
{
|
||||
m_deckParserKeywords[*nameIt] = parserKeyword.get();
|
||||
}
|
||||
|
||||
if (parserKeyword->hasMatchRegex())
|
||||
m_wildCardKeywords[parserKeyword->getName()] = parserKeyword.get();
|
||||
|
||||
void Parser::addParserKeyword(const Json::JsonObject& jsonKeyword) {
|
||||
ParserKeywordConstPtr parserKeyword = std::make_shared<const ParserKeyword>(jsonKeyword);
|
||||
addParserKeyword(parserKeyword);
|
||||
}
|
||||
m_internalParserKeywords[parserKeyword->getName()] = std::move( parserKeyword );
|
||||
|
||||
}
|
||||
|
||||
|
||||
ParserKeywordConstPtr Parser::getKeyword(const std::string& name ) const {
|
||||
auto iter = m_deckParserKeywords.find( name );
|
||||
if (iter == m_deckParserKeywords.end())
|
||||
throw std::invalid_argument("Keyword not found");
|
||||
void Parser::addParserKeyword(const Json::JsonObject& jsonKeyword) {
|
||||
addParserKeyword( std::unique_ptr< ParserKeyword >( new ParserKeyword( jsonKeyword ) ) );
|
||||
}
|
||||
|
||||
|
||||
const ParserKeyword* Parser::getKeyword(const std::string& name ) const {
|
||||
auto iter = m_deckParserKeywords.find( name );
|
||||
if (iter == m_deckParserKeywords.end())
|
||||
throw std::invalid_argument("Keyword not found");
|
||||
else
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
|
||||
bool Parser::dropParserKeyword(const std::string& parserKeywordName) {
|
||||
// remove from the internal from the internal names
|
||||
bool erase = (m_internalParserKeywords.erase( parserKeywordName ) > 0);
|
||||
|
||||
// remove keyword from the deck names map
|
||||
auto deckParserKeywordIt = m_deckParserKeywords.begin();
|
||||
while (deckParserKeywordIt != m_deckParserKeywords.end()) {
|
||||
if (deckParserKeywordIt->second->getName() == parserKeywordName)
|
||||
// note the post-increment of the iterator. this is required to keep the
|
||||
// iterator valid for while at the same time erasing it...
|
||||
m_deckParserKeywords.erase(deckParserKeywordIt++);
|
||||
else
|
||||
return iter->second;
|
||||
++ deckParserKeywordIt;
|
||||
}
|
||||
|
||||
// remove the keyword from the wildcard list
|
||||
m_wildCardKeywords.erase( parserKeywordName );
|
||||
|
||||
bool Parser::dropParserKeyword(const std::string& parserKeywordName) {
|
||||
// remove from the internal from the internal names
|
||||
bool erase = (m_internalParserKeywords.erase( parserKeywordName ) > 0);
|
||||
return erase;
|
||||
}
|
||||
|
||||
// remove keyword from the deck names map
|
||||
auto deckParserKeywordIt = m_deckParserKeywords.begin();
|
||||
while (deckParserKeywordIt != m_deckParserKeywords.end()) {
|
||||
if (deckParserKeywordIt->second->getName() == parserKeywordName)
|
||||
// note the post-increment of the iterator. this is required to keep the
|
||||
// iterator valid for while at the same time erasing it...
|
||||
m_deckParserKeywords.erase(deckParserKeywordIt++);
|
||||
else
|
||||
++ deckParserKeywordIt;
|
||||
}
|
||||
|
||||
// remove the keyword from the wildcard list
|
||||
m_wildCardKeywords.erase( parserKeywordName );
|
||||
|
||||
return erase;
|
||||
const ParserKeyword* Parser::getParserKeywordFromDeckName(const std::string& deckKeywordName) const {
|
||||
if (m_deckParserKeywords.count(deckKeywordName)) {
|
||||
return m_deckParserKeywords.at(deckKeywordName);
|
||||
} else {
|
||||
const auto* wildCardKeyword = matchingKeyword( deckKeywordName );
|
||||
|
||||
if (wildCardKeyword)
|
||||
return wildCardKeyword;
|
||||
else
|
||||
throw std::invalid_argument("Do not have parser keyword for parsing: " + deckKeywordName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ParserKeywordConstPtr Parser::getParserKeywordFromDeckName(const std::string& deckKeywordName) const {
|
||||
if (m_deckParserKeywords.count(deckKeywordName)) {
|
||||
return m_deckParserKeywords.at(deckKeywordName);
|
||||
} else {
|
||||
ParserKeywordConstPtr wildCardKeyword = matchingKeyword( deckKeywordName );
|
||||
|
||||
if (wildCardKeyword)
|
||||
return wildCardKeyword;
|
||||
else
|
||||
throw std::invalid_argument("Do not have parser keyword for parsing: " + deckKeywordName);
|
||||
}
|
||||
std::vector<std::string> Parser::getAllDeckNames () const {
|
||||
std::vector<std::string> keywords;
|
||||
for (auto iterator = m_deckParserKeywords.begin(); iterator != m_deckParserKeywords.end(); iterator++) {
|
||||
keywords.push_back(iterator->first);
|
||||
}
|
||||
|
||||
std::vector<std::string> Parser::getAllDeckNames () const {
|
||||
std::vector<std::string> keywords;
|
||||
for (auto iterator = m_deckParserKeywords.begin(); iterator != m_deckParserKeywords.end(); iterator++) {
|
||||
keywords.push_back(iterator->first);
|
||||
}
|
||||
for (auto iterator = m_wildCardKeywords.begin(); iterator != m_wildCardKeywords.end(); iterator++) {
|
||||
keywords.push_back(iterator->first);
|
||||
}
|
||||
return keywords;
|
||||
for (auto iterator = m_wildCardKeywords.begin(); iterator != m_wildCardKeywords.end(); iterator++) {
|
||||
keywords.push_back(iterator->first);
|
||||
}
|
||||
return keywords;
|
||||
}
|
||||
|
||||
bool Parser::parseState(std::shared_ptr<ParserState> parserState) const {
|
||||
bool stopParsing = false;
|
||||
bool Parser::parseState(std::shared_ptr<ParserState> parserState) const {
|
||||
bool stopParsing = false;
|
||||
|
||||
if (parserState->inputstream) {
|
||||
while (true) {
|
||||
bool streamOK = tryParseKeyword(parserState);
|
||||
if (parserState->rawKeyword) {
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::end) {
|
||||
stopParsing = true;
|
||||
break;
|
||||
if (parserState->inputstream) {
|
||||
while (true) {
|
||||
bool streamOK = tryParseKeyword(parserState);
|
||||
if (parserState->rawKeyword) {
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::end) {
|
||||
stopParsing = true;
|
||||
break;
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::endinclude) {
|
||||
break;
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::paths) {
|
||||
for (size_t i = 0; i < parserState->rawKeyword->size(); i++) {
|
||||
RawRecordConstPtr record = parserState->rawKeyword->getRecord(i);
|
||||
std::string pathName = readValueToken<std::string>(record->getItem(0));
|
||||
std::string pathValue = readValueToken<std::string>(record->getItem(1));
|
||||
parserState->pathMap.insert(std::pair<std::string, std::string>(pathName, pathValue));
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::endinclude) {
|
||||
break;
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::paths) {
|
||||
for (size_t i = 0; i < parserState->rawKeyword->size(); i++) {
|
||||
RawRecordConstPtr record = parserState->rawKeyword->getRecord(i);
|
||||
std::string pathName = readValueToken<std::string>(record->getItem(0));
|
||||
std::string pathValue = readValueToken<std::string>(record->getItem(1));
|
||||
parserState->pathMap.insert(std::pair<std::string, std::string>(pathName, pathValue));
|
||||
}
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::include) {
|
||||
RawRecordConstPtr firstRecord = parserState->rawKeyword->getRecord(0);
|
||||
std::string includeFileAsString = readValueToken<std::string>(firstRecord->getItem(0));
|
||||
boost::filesystem::path includeFile = getIncludeFilePath(*parserState, includeFileAsString);
|
||||
std::shared_ptr<ParserState> newParserState = parserState->includeState( includeFile );
|
||||
}
|
||||
else if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::include) {
|
||||
RawRecordConstPtr firstRecord = parserState->rawKeyword->getRecord(0);
|
||||
std::string includeFileAsString = readValueToken<std::string>(firstRecord->getItem(0));
|
||||
boost::filesystem::path includeFile = getIncludeFilePath(*parserState, includeFileAsString);
|
||||
std::shared_ptr<ParserState> newParserState = parserState->includeState( includeFile );
|
||||
|
||||
|
||||
stopParsing = parseState(newParserState);
|
||||
if (stopParsing) break;
|
||||
} else {
|
||||
stopParsing = parseState(newParserState);
|
||||
if (stopParsing) break;
|
||||
} else {
|
||||
|
||||
if (isRecognizedKeyword(parserState->rawKeyword->getKeywordName())) {
|
||||
ParserKeywordConstPtr parserKeyword = getParserKeywordFromDeckName(parserState->rawKeyword->getKeywordName());
|
||||
if (isRecognizedKeyword(parserState->rawKeyword->getKeywordName())) {
|
||||
const auto* parserKeyword = getParserKeywordFromDeckName(parserState->rawKeyword->getKeywordName());
|
||||
parserState->deck->addKeyword( parserKeyword->parse(parserState->parseMode , parserState->rawKeyword ) );
|
||||
} else {
|
||||
DeckKeyword deckKeyword(parserState->rawKeyword->getKeywordName(), false);
|
||||
@@ -428,9 +427,7 @@ namespace Opm {
|
||||
if (jsonKeywords.is_array()) {
|
||||
for (size_t index = 0; index < jsonKeywords.size(); index++) {
|
||||
Json::JsonObject jsonKeyword = jsonKeywords.get_array_item(index);
|
||||
ParserKeywordConstPtr parserKeyword = std::make_shared<const ParserKeyword>(jsonKeyword);
|
||||
|
||||
addParserKeyword(parserKeyword);
|
||||
addParserKeyword( std::unique_ptr< ParserKeyword >( new ParserKeyword( jsonKeyword ) ) );
|
||||
}
|
||||
} else
|
||||
throw std::invalid_argument("Input JSON object is not an array");
|
||||
@@ -440,7 +437,7 @@ namespace Opm {
|
||||
std::string keywordString = ParserKeyword::getDeckName(initialLine);
|
||||
|
||||
if (isRecognizedKeyword(keywordString)) {
|
||||
ParserKeywordConstPtr parserKeyword = getParserKeywordFromDeckName( keywordString );
|
||||
const auto* parserKeyword = getParserKeywordFromDeckName( keywordString );
|
||||
|
||||
if (parserKeyword->getSizeType() == SLASH_TERMINATED || parserKeyword->getSizeType() == UNKNOWN) {
|
||||
Raw::KeywordSizeEnum rawSizeType;
|
||||
@@ -559,7 +556,7 @@ namespace Opm {
|
||||
try {
|
||||
Json::JsonObject jsonKeyword(configFile);
|
||||
ParserKeywordConstPtr parserKeyword = std::make_shared<const ParserKeyword>(jsonKeyword);
|
||||
addParserKeyword(parserKeyword);
|
||||
addParserKeyword( std::unique_ptr< ParserKeyword >( new ParserKeyword( jsonKeyword ) ) );
|
||||
return true;
|
||||
}
|
||||
catch (...) {
|
||||
@@ -593,7 +590,7 @@ namespace Opm {
|
||||
for (size_t index=0; index < deck.size(); ++index) {
|
||||
auto& deckKeyword = deck.getKeyword( index );
|
||||
if (isRecognizedKeyword( deckKeyword.name())) {
|
||||
ParserKeywordConstPtr parserKeyword = getParserKeywordFromDeckName( deckKeyword.name() );
|
||||
const auto* parserKeyword = getParserKeywordFromDeckName( deckKeyword.name() );
|
||||
if (parserKeyword->hasDimension()) {
|
||||
parserKeyword->applyUnitsToDeck(deck , deckKeyword);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
class path;
|
||||
@@ -40,7 +42,6 @@ namespace Opm {
|
||||
|
||||
class Deck;
|
||||
class ParseMode;
|
||||
class ParserKeyword;
|
||||
class RawKeyword;
|
||||
struct ParserState;
|
||||
|
||||
@@ -68,12 +69,12 @@ namespace Opm {
|
||||
|
||||
/// Method to add ParserKeyword instances, these holding type and size information about the keywords and their data.
|
||||
void addParserKeyword(const Json::JsonObject& jsonKeyword);
|
||||
void addParserKeyword(std::shared_ptr< const ParserKeyword > parserKeyword);
|
||||
void addParserKeyword(std::unique_ptr< const ParserKeyword >&& parserKeyword);
|
||||
bool dropParserKeyword(const std::string& parserKeywordName);
|
||||
std::shared_ptr< const ParserKeyword > getKeyword(const std::string& name) const;
|
||||
const ParserKeyword* getKeyword(const std::string& name) const;
|
||||
|
||||
bool isRecognizedKeyword( const std::string& deckKeywordName) const;
|
||||
std::shared_ptr< const ParserKeyword > getParserKeywordFromDeckName(const std::string& deckKeywordName) const;
|
||||
const ParserKeyword* getParserKeywordFromDeckName(const std::string& deckKeywordName) const;
|
||||
std::vector<std::string> getAllDeckNames () const;
|
||||
|
||||
void loadKeywords(const Json::JsonObject& jsonKeywords);
|
||||
@@ -98,26 +99,26 @@ namespace Opm {
|
||||
/*!
|
||||
* \brief Retrieve a ParserKeyword object given an internal keyword name.
|
||||
*/
|
||||
std::shared_ptr< const ParserKeyword > getParserKeywordFromInternalName(const std::string& internalKeywordName) const;
|
||||
const ParserKeyword* getParserKeywordFromInternalName(const std::string& internalKeywordName) const;
|
||||
|
||||
|
||||
template <class T>
|
||||
void addKeyword() {
|
||||
addParserKeyword( std::make_shared<T>());
|
||||
addParserKeyword( std::unique_ptr< ParserKeyword >( new T ) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// associative map of the parser internal name and the corresponding ParserKeyword object
|
||||
std::map<std::string, std::shared_ptr< const ParserKeyword >> m_internalParserKeywords;
|
||||
std::map<std::string, std::unique_ptr< const ParserKeyword > > m_internalParserKeywords;
|
||||
// associative map of deck names and the corresponding ParserKeyword object
|
||||
std::map<std::string, std::shared_ptr< const ParserKeyword >> m_deckParserKeywords;
|
||||
std::map<std::string, const ParserKeyword* > m_deckParserKeywords;
|
||||
// associative map of the parser internal names and the corresponding
|
||||
// ParserKeyword object for keywords which match a regular expression
|
||||
std::map<std::string, std::shared_ptr< const ParserKeyword >> m_wildCardKeywords;
|
||||
std::map<std::string, const ParserKeyword* > m_wildCardKeywords;
|
||||
|
||||
bool hasWildCardKeyword(const std::string& keyword) const;
|
||||
std::shared_ptr< const ParserKeyword > matchingKeyword(const std::string& keyword) const;
|
||||
const ParserKeyword* matchingKeyword(const std::string& keyword) const;
|
||||
|
||||
bool tryParseKeyword(std::shared_ptr<ParserState> parserState) const;
|
||||
bool parseState(std::shared_ptr<ParserState> parserState) const;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseMode.hpp>
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
std::shared_ptr<ParserKeyword> createDynamicSized(const std::string& kw) {
|
||||
std::shared_ptr<ParserKeyword> pkw = std::make_shared<ParserKeyword>(kw);
|
||||
std::unique_ptr< ParserKeyword > createDynamicSized(const std::string& kw) {
|
||||
std::unique_ptr< ParserKeyword > pkw( new ParserKeyword( kw ) );
|
||||
pkw->setSizeType(SLASH_TERMINATED);
|
||||
return pkw;
|
||||
}
|
||||
@@ -53,10 +53,7 @@ BOOST_AUTO_TEST_CASE(Initializing) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addKeyword_keyword_doesntfail) {
|
||||
Parser parser;
|
||||
{
|
||||
ParserKeywordPtr equilKeyword = createDynamicSized("EQUIL");
|
||||
parser.addParserKeyword(equilKeyword);
|
||||
}
|
||||
parser.addParserKeyword( createDynamicSized( "EQUIL" ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -69,25 +66,21 @@ BOOST_AUTO_TEST_CASE(canParseDeckKeyword_returnstrue) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_haskeyword_returnskeyword) {
|
||||
ParserPtr parser(new Parser());
|
||||
ParserKeywordConstPtr parserKeyword = createDynamicSized("FJAS");
|
||||
parser->addParserKeyword(parserKeyword);
|
||||
BOOST_CHECK_EQUAL(parserKeyword, parser->getParserKeywordFromDeckName("FJAS"));
|
||||
parser->addParserKeyword( createDynamicSized( "FJAS" ) );
|
||||
BOOST_CHECK_EQUAL("FJAS", parser->getParserKeywordFromDeckName("FJAS")->getName());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_hasnotkeyword_getKeywordThrowsException) {
|
||||
ParserPtr parser(new Parser());
|
||||
ParserKeywordConstPtr parserKeyword = createDynamicSized("FJAS");
|
||||
parser->addParserKeyword(parserKeyword);
|
||||
parser->addParserKeyword( createDynamicSized( "FJAS" ) );
|
||||
BOOST_CHECK_THROW(parser->getParserKeywordFromDeckName("FJASS"), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getAllDeckNames_hasTwoKeywords_returnsCompleteList) {
|
||||
ParserPtr parser(new Parser(false));
|
||||
std::cout << parser->getAllDeckNames().size() << std::endl;
|
||||
ParserKeywordConstPtr firstParserKeyword = createDynamicSized("FJAS");
|
||||
parser->addParserKeyword(firstParserKeyword);
|
||||
ParserKeywordConstPtr secondParserKeyword = createDynamicSized("SAJF");
|
||||
parser->addParserKeyword(secondParserKeyword);
|
||||
parser->addParserKeyword( createDynamicSized( "FJAS" ) );
|
||||
parser->addParserKeyword( createDynamicSized( "SAJF" ) );
|
||||
BOOST_CHECK_EQUAL(2U, parser->getAllDeckNames().size());
|
||||
}
|
||||
|
||||
@@ -104,7 +97,7 @@ BOOST_AUTO_TEST_CASE(getAllDeckNames_hasNoKeywords_returnsEmptyList) {
|
||||
BOOST_AUTO_TEST_CASE(addParserKeywordJSON_isRecognizedKeyword_returnstrue) {
|
||||
ParserPtr parser(new Parser());
|
||||
Json::JsonObject jsonConfig("{\"name\": \"BPR\", \"sections\":[\"SUMMARY\"], \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\"}]}");
|
||||
parser->addParserKeyword(std::make_shared<const ParserKeyword>( jsonConfig ));
|
||||
parser->addParserKeyword( jsonConfig );
|
||||
BOOST_CHECK(parser->isRecognizedKeyword("BPR"));
|
||||
}
|
||||
|
||||
@@ -112,7 +105,7 @@ BOOST_AUTO_TEST_CASE(addParserKeywordJSON_isRecognizedKeyword_returnstrue) {
|
||||
BOOST_AUTO_TEST_CASE(addParserKeywordJSON_size_isObject_allGood) {
|
||||
ParserPtr parser(new Parser());
|
||||
Json::JsonObject jsonConfig("{\"name\": \"EQUIXL\", \"sections\":[], \"size\" : {\"keyword\":\"EQLDIMS\" , \"item\" : \"NTEQUL\"}, \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"DOUBLE\"}]}");
|
||||
parser->addParserKeyword(std::make_shared<const ParserKeyword>( jsonConfig ));
|
||||
parser->addParserKeyword( jsonConfig );
|
||||
BOOST_CHECK(parser->isRecognizedKeyword("EQUIXL"));
|
||||
}
|
||||
|
||||
@@ -266,7 +259,7 @@ BOOST_AUTO_TEST_CASE(DropKeyword) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ReplaceKeyword) {
|
||||
ParserPtr parser(new Parser());
|
||||
ParserKeywordConstPtr eqldims = parser->getParserKeywordFromDeckName("EQLDIMS");
|
||||
const auto* eqldims = parser->getParserKeywordFromDeckName("EQLDIMS");
|
||||
|
||||
BOOST_CHECK( parser->loadKeywordFromFile( "testdata/parser/EQLDIMS2" ) );
|
||||
|
||||
@@ -287,32 +280,15 @@ BOOST_AUTO_TEST_CASE(WildCardTest) {
|
||||
|
||||
BOOST_CHECK(!parser->isRecognizedKeyword("TVDP"));
|
||||
|
||||
ParserKeywordConstPtr keyword1 = parser->getParserKeywordFromDeckName("TVDPA");
|
||||
ParserKeywordConstPtr keyword2 = parser->getParserKeywordFromDeckName("TVDPBC");
|
||||
ParserKeywordConstPtr keyword3 = parser->getParserKeywordFromDeckName("TVDPXXX");
|
||||
const auto* keyword1 = parser->getParserKeywordFromDeckName("TVDPA");
|
||||
const auto* keyword2 = parser->getParserKeywordFromDeckName("TVDPBC");
|
||||
const auto* keyword3 = parser->getParserKeywordFromDeckName("TVDPXXX");
|
||||
|
||||
BOOST_CHECK_EQUAL( keyword1 , keyword2 );
|
||||
BOOST_CHECK_EQUAL( keyword1 , keyword3 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************** Simple Int parsing ********************************/
|
||||
|
||||
static ParserKeywordPtr __attribute__((unused)) setupParserKeywordInt(std::string name, int numberOfItems) {
|
||||
ParserKeywordPtr parserKeyword = createDynamicSized(name);
|
||||
ParserRecordPtr parserRecord = parserKeyword->getRecord(0);
|
||||
|
||||
for (int i = 0; i < numberOfItems; i++) {
|
||||
std::string another_name = "ITEM_" + boost::lexical_cast<std::string>(i);
|
||||
ParserItemPtr intItem(new ParserIntItem(another_name, SINGLE));
|
||||
parserRecord->addItem(intItem);
|
||||
}
|
||||
|
||||
return parserKeyword;
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( quoted_comments ) {
|
||||
BOOST_CHECK_EQUAL( Parser::stripComments( "ABC" ) , "ABC");
|
||||
BOOST_CHECK_EQUAL( Parser::stripComments( "--ABC") , "");
|
||||
@@ -326,9 +302,3 @@ BOOST_AUTO_TEST_CASE( quoted_comments ) {
|
||||
BOOST_CHECK_EQUAL( Parser::stripComments("ABC'--'DEF'--GHI") , "ABC'--'DEF'--GHI");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user