Added support for keywords getting size from other keywords ~ EQUIL style
This commit is contained in:
parent
5dc350c735
commit
c046fb0bde
@ -27,7 +27,8 @@ namespace Opm {
|
||||
|
||||
enum ParserKeywordSizeEnum {
|
||||
UNDEFINED = 0,
|
||||
FIXED = 1
|
||||
FIXED = 1,
|
||||
OTHER = 2
|
||||
};
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
|
||||
#include <opm/json/JsonObject.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParserConst.hpp>
|
||||
@ -52,6 +53,12 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name , const std::string& sizeKeyword , const std::string& sizeItem) {
|
||||
commonInit(name);
|
||||
initSizeKeyword( sizeKeyword , sizeItem );
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const Json::JsonObject& jsonConfig) {
|
||||
if (jsonConfig.has_item("name")) {
|
||||
commonInit(jsonConfig.get_string("name"));
|
||||
@ -59,8 +66,16 @@ namespace Opm {
|
||||
throw std::invalid_argument("Json object is missing name: property");
|
||||
|
||||
if (jsonConfig.has_item("size")) {
|
||||
m_fixedSize = (size_t) jsonConfig.get_int("size");
|
||||
m_keywordSizeType = FIXED;
|
||||
Json::JsonObject sizeObject = jsonConfig.get_item("size");
|
||||
|
||||
if (sizeObject.is_number()) {
|
||||
m_fixedSize = (size_t) sizeObject.as_int( );
|
||||
m_keywordSizeType = FIXED;
|
||||
} else {
|
||||
std::string sizeKeyword = sizeObject.get_string("keyword");
|
||||
std::string sizeItem = sizeObject.get_string("item");
|
||||
initSizeKeyword( sizeKeyword , sizeItem);
|
||||
}
|
||||
} else
|
||||
m_keywordSizeType = UNDEFINED;
|
||||
|
||||
@ -69,6 +84,12 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem) {
|
||||
m_keywordSizeType = OTHER;
|
||||
m_sizeKeyword = std::pair<std::string , std::string>(sizeKeyword , sizeItem);
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::commonInit(const std::string& name) {
|
||||
if (name.length() > ParserConst::maxKeywordLength)
|
||||
throw std::invalid_argument("Given keyword name is too long - max 8 characters.");
|
||||
@ -150,4 +171,13 @@ namespace Opm {
|
||||
bool ParserKeyword::hasFixedSize() const {
|
||||
return m_keywordSizeType == FIXED;
|
||||
}
|
||||
|
||||
enum ParserKeywordSizeEnum ParserKeyword::getSizeType() const {
|
||||
return m_keywordSizeType;
|
||||
}
|
||||
|
||||
const std::pair<std::string,std::string>& ParserKeyword::getSizePair() const {
|
||||
return m_sizeKeyword;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,20 +36,26 @@ namespace Opm {
|
||||
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);
|
||||
ParserKeyword(const Json::JsonObject& jsonConfig);
|
||||
|
||||
|
||||
ParserRecordPtr getRecord();
|
||||
const std::string& getName() const;
|
||||
size_t getFixedSize() const;
|
||||
bool hasFixedSize() const;
|
||||
|
||||
DeckKeywordPtr parse(RawKeywordConstPtr rawKeyword) const;
|
||||
|
||||
enum ParserKeywordSizeEnum getSizeType() const;
|
||||
const std::pair<std::string,std::string>& getSizePair() const;
|
||||
private:
|
||||
std::pair<std::string,std::string> m_sizeKeyword;
|
||||
std::string m_name;
|
||||
ParserRecordPtr m_record;
|
||||
enum ParserKeywordSizeEnum m_keywordSizeType;
|
||||
size_t m_fixedSize;
|
||||
|
||||
void initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem);
|
||||
void commonInit(const std::string& name);
|
||||
void addItems( const Json::JsonObject& jsonConfig);
|
||||
};
|
||||
|
@ -42,6 +42,34 @@ BOOST_AUTO_TEST_CASE(NamedInit) {
|
||||
BOOST_CHECK_EQUAL(parserKeyword.getName(), keyword);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserKeyword_default_SizeTypedefault) {
|
||||
std::string keyword("KEYWORD");
|
||||
ParserKeyword parserKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(parserKeyword.getSizeType() , UNDEFINED);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserKeyword_withSize_SizeTypeFIXED) {
|
||||
std::string keyword("KEYWORD");
|
||||
ParserKeyword parserKeyword(keyword, 100);
|
||||
BOOST_CHECK_EQUAL(parserKeyword.getSizeType() , FIXED);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ParserKeyword_withOtherSize_SizeTypeOTHER) {
|
||||
std::string keyword("KEYWORD");
|
||||
ParserKeyword parserKeyword(keyword, "EQUILDIMS" , "NTEQUIL");
|
||||
const std::pair<std::string,std::string>& sizeKW = parserKeyword.getSizePair();
|
||||
BOOST_CHECK_EQUAL(OTHER , parserKeyword.getSizeType() );
|
||||
BOOST_CHECK_EQUAL("EQUILDIMS", sizeKW.first );
|
||||
BOOST_CHECK_EQUAL("NTEQUIL" , sizeKW.second );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************/
|
||||
/* json */
|
||||
|
||||
@ -62,6 +90,18 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSize) {
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSizeOther) {
|
||||
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"size\" : {\"keyword\" : \"Bjarne\" , \"item\": \"BjarneIgjen\"}}");
|
||||
ParserKeyword parserKeyword(jsonObject);
|
||||
const std::pair<std::string,std::string>& sizeKW = parserKeyword.getSizePair();
|
||||
BOOST_CHECK_EQUAL("BPR" , parserKeyword.getName());
|
||||
BOOST_CHECK_EQUAL( false , parserKeyword.hasFixedSize() );
|
||||
BOOST_CHECK_EQUAL( parserKeyword.getSizeType() , OTHER);
|
||||
BOOST_CHECK_EQUAL("Bjarne", sizeKW.first );
|
||||
BOOST_CHECK_EQUAL("BjarneIgjen" , sizeKW.second );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingName_throws) {
|
||||
Json::JsonObject jsonObject("{\"nameXX\": \"BPR\", \"size\" : 100}");
|
||||
BOOST_CHECK_THROW(ParserKeyword parserKeyword(jsonObject) , std::invalid_argument);
|
||||
@ -115,6 +155,12 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectItemsOK) {
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_sizeFromOther) {
|
||||
Json::JsonObject jsonConfig("{\"name\": \"EQUIL\", \"size\" : {\"keyword\":\"EQLDIMS\" , \"item\" : \"NTEQUL\"}}");
|
||||
BOOST_CHECK_NO_THROW( ParserKeyword parserKeyword(jsonConfig) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* </Json> */
|
||||
/*****************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user