Removed setRecord() method ParserKeyword. Instead ParserRecord is created during ParserKeyword construction
This commit is contained in:
@@ -35,9 +35,8 @@ using namespace Opm;
|
||||
ParserPtr createWWCTParser() {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword("WWCT"));
|
||||
{
|
||||
ParserRecordPtr wwctRecord(new ParserRecord());
|
||||
ParserRecordPtr wwctRecord = parserKeyword->getRecord();
|
||||
wwctRecord->addItem(ParserStringItemConstPtr(new ParserStringItem("WELL", ALL)));
|
||||
parserKeyword->setRecord(wwctRecord);
|
||||
}
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
@@ -70,12 +69,10 @@ BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_dataIsCorrect) {
|
||||
ParserPtr createBPRParser() {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword("BPR"));
|
||||
{
|
||||
ParserRecordPtr bprRecord(new ParserRecord());
|
||||
ParserRecordPtr bprRecord = parserKeyword->getRecord();
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("I", SINGLE)));
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("J", SINGLE)));
|
||||
bprRecord->addItem(ParserIntItemConstPtr(new ParserIntItem("K", SINGLE)));
|
||||
|
||||
parserKeyword->setRecord(bprRecord);
|
||||
}
|
||||
|
||||
ParserPtr parser(new Parser());
|
||||
|
||||
@@ -30,19 +30,19 @@ namespace Opm {
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name) {
|
||||
setKeywordName(name);
|
||||
commonInit(name);
|
||||
m_keywordSizeType = UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const char * name) {
|
||||
setKeywordName(name);
|
||||
commonInit(name);
|
||||
m_keywordSizeType = UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
ParserKeyword::ParserKeyword(const std::string& name, size_t fixedKeywordSize) {
|
||||
setKeywordName(name);
|
||||
commonInit(name);
|
||||
m_keywordSizeType = FIXED;
|
||||
m_fixedSize = fixedKeywordSize;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace Opm {
|
||||
|
||||
ParserKeyword::ParserKeyword(const Json::JsonObject& jsonConfig) {
|
||||
if (jsonConfig.has_item("name")) {
|
||||
setKeywordName(jsonConfig.get_string("name"));
|
||||
commonInit(jsonConfig.get_string("name"));
|
||||
if (jsonConfig.has_item("size")) {
|
||||
m_fixedSize = (size_t) jsonConfig.get_int("size");
|
||||
m_keywordSizeType = FIXED;
|
||||
@@ -59,27 +59,25 @@ namespace Opm {
|
||||
} else
|
||||
throw std::invalid_argument("Json object is missing name: property");
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::setKeywordName(const std::string& name) {
|
||||
|
||||
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.");
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < name.length(); i++)
|
||||
if (islower(name[i]))
|
||||
throw std::invalid_argument("Keyword must be all upper case - mixed case not allowed:" + name);
|
||||
|
||||
|
||||
m_name = name;
|
||||
m_record = ParserRecordPtr(new ParserRecord);
|
||||
}
|
||||
|
||||
void ParserKeyword::setRecord(ParserRecordConstPtr record) {
|
||||
m_record = record;
|
||||
}
|
||||
|
||||
ParserRecordConstPtr ParserKeyword::getRecord() {
|
||||
ParserRecordPtr ParserKeyword::getRecord() {
|
||||
return m_record;
|
||||
}
|
||||
|
||||
|
||||
const std::string& ParserKeyword::getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
@@ -37,21 +37,20 @@ namespace Opm {
|
||||
ParserKeyword(const std::string& name);
|
||||
ParserKeyword(const std::string& name, size_t fixedKeywordSize);
|
||||
ParserKeyword(const Json::JsonObject& jsonConfig);
|
||||
void setRecord(ParserRecordConstPtr record);
|
||||
ParserRecordConstPtr getRecord();
|
||||
ParserRecordPtr getRecord();
|
||||
const std::string& getName() const;
|
||||
size_t getFixedSize() const;
|
||||
bool hasFixedSize() const;
|
||||
|
||||
|
||||
DeckKeywordPtr parse(RawKeywordConstPtr rawKeyword) const;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
ParserRecordConstPtr m_record;
|
||||
ParserRecordPtr m_record;
|
||||
enum ParserKeywordSizeEnum m_keywordSizeType;
|
||||
size_t m_fixedSize;
|
||||
|
||||
void setKeywordName(const std::string& name);
|
||||
void commonInit(const std::string& name);
|
||||
|
||||
};
|
||||
typedef boost::shared_ptr<ParserKeyword> ParserKeywordPtr;
|
||||
|
||||
@@ -66,12 +66,6 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingName_throws) {
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(setRecord_validRecord_recordSet) {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword("JA"));
|
||||
ParserRecordConstPtr parserRecord = ParserRecordConstPtr(new ParserRecord());
|
||||
parserKeyword->setRecord(parserRecord);
|
||||
BOOST_CHECK_EQUAL(parserRecord, parserKeyword->getRecord());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(constructor_nametoolongwithfixedsize_exceptionthrown) {
|
||||
std::string keyword("KEYWORDTOOLONG");
|
||||
|
||||
@@ -146,15 +146,14 @@ BOOST_AUTO_TEST_CASE(createWithValidJsonFileArgument) {
|
||||
|
||||
ParserKeywordPtr setupParserKeywordInt(std::string name, int numberOfItems) {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword(name));
|
||||
ParserRecordPtr parserRecord(new ParserRecord());
|
||||
ParserRecordPtr parserRecord = parserKeyword->getRecord();
|
||||
|
||||
for (int i = 0; i < numberOfItems; i++) {
|
||||
std::string name = "ITEM_" + boost::lexical_cast<std::string>(i);
|
||||
ParserItemPtr intItem(new ParserIntItem(name, SINGLE));
|
||||
parserRecord->addItem(intItem);
|
||||
}
|
||||
|
||||
parserKeyword->setRecord(parserRecord);
|
||||
|
||||
return parserKeyword;
|
||||
}
|
||||
|
||||
@@ -207,15 +206,13 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_severalRawRecordsSeveralIntItem_deckReturn
|
||||
|
||||
ParserKeywordPtr setupParserKeywordString(std::string name, int numberOfItems) {
|
||||
ParserKeywordPtr parserKeyword(new ParserKeyword(name));
|
||||
ParserRecordPtr parserRecord(new ParserRecord());
|
||||
ParserRecordPtr parserRecord = parserKeyword->getRecord();
|
||||
for (int i = 0; i < numberOfItems; i++) {
|
||||
std::string name = "ITEM_" + boost::lexical_cast<std::string>(i);
|
||||
ParserItemPtr stringItem(new ParserStringItem(name, SINGLE));
|
||||
parserRecord->addItem(stringItem);
|
||||
}
|
||||
|
||||
parserKeyword->setRecord(parserRecord);
|
||||
|
||||
return parserKeyword;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user