Added action value to ParserKeyword constructor
This commit is contained in:
parent
9b96d6dfa5
commit
e6b38c6445
@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE( parse_PVTG_OK ) {
|
||||
ParserPtr parser2(new Parser());
|
||||
ParserPtr parser(new Parser(false));
|
||||
ParserKeywordPtr tabdimsKeyword( new ParserKeyword("TABDIMS" , 1));
|
||||
ParserKeywordPtr pvtgKeyword( new ParserKeyword("PVTG" , "TABDIMS" , "NTPVT" , true));
|
||||
ParserKeywordPtr pvtgKeyword( new ParserKeyword("PVTG" , "TABDIMS" , "NTPVT" , INTERNALIZE , true));
|
||||
{
|
||||
ParserIntItemConstPtr item(new ParserIntItem(std::string("NTSFUN")));
|
||||
tabdimsKeyword->addItem(item);
|
||||
|
@ -33,28 +33,44 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name) {
|
||||
commonInit(name);
|
||||
void ParserKeyword::commonInit(const std::string& name , ParserKeywordActionEnum action) {
|
||||
if (!validName(name))
|
||||
throw std::invalid_argument("Invalid name: " + name + "keyword must be all upper case, max 8 characters. Starting with character.");
|
||||
|
||||
m_keywordSizeType = SLASH_TERMINATED;
|
||||
m_isDataKeyword = false;
|
||||
m_isTableCollection = false;
|
||||
m_name = name;
|
||||
m_action = action;
|
||||
m_record = ParserRecordPtr(new ParserRecord);
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const char * name) {
|
||||
commonInit(name);
|
||||
ParserKeyword::ParserKeyword(const std::string& name, ParserKeywordActionEnum action) {
|
||||
commonInit(name , action);
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name , const std::string& sizeKeyword , const std::string& sizeItem, bool isTableCollection) {
|
||||
commonInit(name);
|
||||
ParserKeyword::ParserKeyword(const char * name , ParserKeywordActionEnum action) {
|
||||
commonInit(name , action);
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name, size_t fixedKeywordSize , ParserKeywordActionEnum action) {
|
||||
commonInit(name,action);
|
||||
m_keywordSizeType = FIXED;
|
||||
m_fixedSize = fixedKeywordSize;
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name , const std::string& sizeKeyword , const std::string& sizeItem , ParserKeywordActionEnum action , bool isTableCollection) {
|
||||
commonInit(name,action);
|
||||
m_isTableCollection = isTableCollection;
|
||||
initSizeKeyword(sizeKeyword , sizeItem);
|
||||
}
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name, size_t fixedKeywordSize) {
|
||||
commonInit(name);
|
||||
m_keywordSizeType = FIXED;
|
||||
m_fixedSize = fixedKeywordSize;
|
||||
}
|
||||
|
||||
|
||||
bool ParserKeyword::isTableCollection() const {
|
||||
@ -99,7 +115,7 @@ namespace Opm {
|
||||
|
||||
ParserKeyword::ParserKeyword(const Json::JsonObject& jsonConfig) {
|
||||
if (jsonConfig.has_item("name")) {
|
||||
commonInit(jsonConfig.get_string("name"));
|
||||
commonInit(jsonConfig.get_string("name") , INTERNALIZE);
|
||||
} else
|
||||
throw std::invalid_argument("Json object is missing name: property");
|
||||
|
||||
@ -155,17 +171,6 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::commonInit(const std::string& name) {
|
||||
if (!validName(name))
|
||||
throw std::invalid_argument("Invalid name: " + name + "keyword must be all upper case, max 8 characters. Starting with character.");
|
||||
|
||||
m_keywordSizeType = SLASH_TERMINATED;
|
||||
m_isDataKeyword = false;
|
||||
m_isTableCollection = false;
|
||||
m_name = name;
|
||||
m_record = ParserRecordPtr(new ParserRecord);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -287,6 +292,11 @@ namespace Opm {
|
||||
return m_record;
|
||||
}
|
||||
|
||||
|
||||
ParserKeywordActionEnum ParserKeyword::getAction() const {
|
||||
return m_action;
|
||||
}
|
||||
|
||||
|
||||
const std::string& ParserKeyword::getName() const {
|
||||
return m_name;
|
||||
@ -360,39 +370,41 @@ namespace Opm {
|
||||
|
||||
|
||||
void ParserKeyword::inlineNew(std::ostream& os , const std::string& lhs, const std::string& indent) const {
|
||||
switch(m_keywordSizeType) {
|
||||
case SLASH_TERMINATED:
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\");" << std::endl;
|
||||
break;
|
||||
case FIXED:
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\",(size_t)" << m_fixedSize << ");" << std::endl;
|
||||
break;
|
||||
case OTHER:
|
||||
if (isTableCollection())
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\" , true);" << std::endl;
|
||||
else
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\");" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_record->size(); i++) {
|
||||
os << indent << "{" << std::endl;
|
||||
{
|
||||
const std::string local_indent = indent + " ";
|
||||
ParserItemConstPtr item = m_record->get(i);
|
||||
os << local_indent << "ParserItemConstPtr item(";
|
||||
item->inlineNew(os);
|
||||
os << ");" << std::endl;
|
||||
{
|
||||
std::string addItemMethod = "addItem";
|
||||
if (m_isDataKeyword)
|
||||
addItemMethod = "addDataItem";
|
||||
|
||||
os << local_indent << lhs << "->" << addItemMethod << "(item);" << std::endl;
|
||||
}
|
||||
}
|
||||
os << indent << "}" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const std::string actionString(ParserKeywordActionEnum2String( m_action ));
|
||||
switch(m_keywordSizeType) {
|
||||
case SLASH_TERMINATED:
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\"," << actionString << ");" << std::endl;
|
||||
break;
|
||||
case FIXED:
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\",(size_t)" << m_fixedSize << "," << actionString << ");" << std::endl;
|
||||
break;
|
||||
case OTHER:
|
||||
if (isTableCollection())
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\"," << actionString << ", true);" << std::endl;
|
||||
else
|
||||
os << lhs << " = new ParserKeyword(\"" << m_name << "\",\"" << m_sizeDefinitionPair.first << "\",\"" << m_sizeDefinitionPair.second << "\"," << actionString << ");" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_record->size(); i++) {
|
||||
os << indent << "{" << std::endl;
|
||||
{
|
||||
const std::string local_indent = indent + " ";
|
||||
ParserItemConstPtr item = m_record->get(i);
|
||||
os << local_indent << "ParserItemConstPtr item(";
|
||||
item->inlineNew(os);
|
||||
os << ");" << std::endl;
|
||||
{
|
||||
std::string addItemMethod = "addItem";
|
||||
if (m_isDataKeyword)
|
||||
addItemMethod = "addDataItem";
|
||||
|
||||
os << local_indent << lhs << "->" << addItemMethod << "(item);" << std::endl;
|
||||
}
|
||||
}
|
||||
os << indent << "}" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
|
||||
@ -34,17 +35,17 @@ namespace Opm {
|
||||
|
||||
class ParserKeyword {
|
||||
public:
|
||||
ParserKeyword(const char * name);
|
||||
ParserKeyword(const std::string& name);
|
||||
ParserKeyword(const std::string& name, size_t fixedKeywordSize);
|
||||
ParserKeyword(const std::string& name , const std::string& sizeKeyword , const std::string& sizeItem, bool isTableCollection = false);
|
||||
ParserKeyword(const char * name , ParserKeywordActionEnum action = INTERNALIZE);
|
||||
ParserKeyword(const std::string& name , ParserKeywordActionEnum action = INTERNALIZE);
|
||||
ParserKeyword(const std::string& name, size_t fixedKeywordSize,ParserKeywordActionEnum action = INTERNALIZE);
|
||||
ParserKeyword(const std::string& name , const std::string& sizeKeyword , const std::string& sizeItem, ParserKeywordActionEnum action = INTERNALIZE , bool isTableCollection = false);
|
||||
ParserKeyword(const Json::JsonObject& jsonConfig);
|
||||
|
||||
static bool validName(const std::string& name);
|
||||
|
||||
ParserRecordPtr getRecord() const;
|
||||
const std::string& getName() const;
|
||||
|
||||
ParserKeywordActionEnum getAction() const;
|
||||
size_t getFixedSize() const;
|
||||
bool hasFixedSize() const;
|
||||
bool isTableCollection() const;
|
||||
@ -68,12 +69,13 @@ namespace Opm {
|
||||
size_t m_fixedSize;
|
||||
bool m_isDataKeyword;
|
||||
bool m_isTableCollection;
|
||||
|
||||
ParserKeywordActionEnum m_action;
|
||||
|
||||
void initData( const Json::JsonObject& jsonConfig );
|
||||
void initSize( const Json::JsonObject& jsonConfig );
|
||||
void initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem);
|
||||
void initSizeKeyword(const Json::JsonObject& sizeObject);
|
||||
void commonInit(const std::string& name);
|
||||
void commonInit(const std::string& name, ParserKeywordActionEnum action);
|
||||
void addItems( const Json::JsonObject& jsonConfig);
|
||||
void addTableItems();
|
||||
};
|
||||
|
@ -324,7 +324,7 @@ BOOST_AUTO_TEST_CASE(DefaultIsNot_TableKeyword) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructorIsTableCollection) {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword("JA" , "TABDIMS" , "NTPVT" , true));
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword("JA" , "TABDIMS" , "NTPVT" , INTERNALIZE , true));
|
||||
const std::pair<std::string,std::string>& sizeKW = parserKeyword->getSizeDefinitionPair();
|
||||
BOOST_CHECK(parserKeyword->isTableCollection());
|
||||
BOOST_CHECK(!parserKeyword->hasFixedSize());
|
||||
@ -356,3 +356,17 @@ BOOST_AUTO_TEST_CASE(ParseEmptyRecord) {
|
||||
BOOST_CHECK_EQUAL(0U , deckItem->size());
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
/* Action value */
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DefaultActionISINTERNALIZE) {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword("JA"));
|
||||
BOOST_CHECK_EQUAL(INTERNALIZE , parserKeyword->getAction());
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateWithAction) {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword("JA" , IGNORE));
|
||||
BOOST_CHECK_EQUAL(IGNORE , parserKeyword->getAction());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user