Changed Deck::getKeyword() to take an additional inde argument
This commit is contained in:
parent
3bd3c7a306
commit
75954575d5
@ -33,8 +33,8 @@ namespace Opm {
|
||||
m_keywords->addKeyword(keyword);
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword) const {
|
||||
return m_keywords->getKeyword(keyword);
|
||||
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword, size_t index) const {
|
||||
return m_keywords->getKeyword(keyword , index);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace Opm {
|
||||
Deck();
|
||||
bool hasKeyword( const std::string& keyword ) const;
|
||||
void addKeyword( DeckKeywordConstPtr keyword);
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword , size_t index) const;
|
||||
|
||||
private:
|
||||
KeywordContainerPtr m_keywords;
|
||||
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/KeywordContainer.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
@ -47,10 +49,13 @@ namespace Opm {
|
||||
}
|
||||
}
|
||||
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword) const {
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword, size_t index) const {
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
|
||||
return keywordList.back();
|
||||
if (index < keywordList.size())
|
||||
return keywordList[index];
|
||||
else
|
||||
throw std::invalid_argument("Keyword index is out of range.");
|
||||
}
|
||||
else
|
||||
throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
|
||||
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#ifndef KEYWORDCONTAINER_HPP
|
||||
#define KEYWORDCONTAINER_HPP
|
||||
#define KEYWORDCONTAINER_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
@ -23,7 +23,7 @@ namespace Opm {
|
||||
bool hasKeyword(const std::string& keyword) const;
|
||||
size_t size() const;
|
||||
void addKeyword(DeckKeywordConstPtr keyword);
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword, size_t index) const;
|
||||
|
||||
|
||||
private:
|
||||
@ -34,5 +34,5 @@ namespace Opm {
|
||||
typedef boost::shared_ptr<const KeywordContainer> KeywordContainerConstPtr;
|
||||
}
|
||||
|
||||
#endif /* KEYWORDCONTAINER_HPP */
|
||||
#endif /* KEYWORDCONTAINER_HPP */
|
||||
|
||||
|
@ -45,14 +45,22 @@ BOOST_AUTO_TEST_CASE(addKeyword_singlekeyword_keywordAdded) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_nosuchkeyword_throws) {
|
||||
Deck deck;
|
||||
BOOST_CHECK_THROW(deck.getKeyword("TRULS"), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(deck.getKeyword("TRULS" , 0), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_singlekeyword_keywordreturned) {
|
||||
Deck deck;
|
||||
DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE"));
|
||||
deck.addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(keyword, deck.getKeyword("BJARNE"));
|
||||
BOOST_CHECK_EQUAL(keyword, deck.getKeyword("BJARNE" , 0));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_singlekeyword_outRange_throws) {
|
||||
Deck deck;
|
||||
DeckKeywordConstPtr keyword(new DeckKeyword("BJARNE"));
|
||||
deck.addKeyword(keyword);
|
||||
BOOST_CHECK_THROW(deck.getKeyword("BJARNE" , 10) , std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,14 +52,22 @@ BOOST_AUTO_TEST_CASE(addKeyword_keywordAdded_keywordAdded) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_nosuchkeyword_throws) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
BOOST_CHECK_THROW(container->getKeyword("TRULS"), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(container->getKeyword("TRULS" , 0), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_singleKeyword_keywordReturned) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
container->addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(keyword, container->getKeyword("TRULS"));
|
||||
BOOST_CHECK_EQUAL(keyword, container->getKeyword("TRULS", 0));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(getKeyword_outOfRange_throws) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
container->addKeyword(keyword);
|
||||
BOOST_CHECK_EQUAL(keyword, container->getKeyword("TRULS" , 2));
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,8 +62,8 @@ BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_dataIsCorrect) {
|
||||
boost::filesystem::path singleKeywordFile("testdata/integration_tests/wwct.data");
|
||||
ParserPtr parser = createWWCTParser();
|
||||
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
||||
BOOST_CHECK_EQUAL("WELL-1", deck->getKeyword("WWCT")->getRecord(0)->getItem(0)->getString(0));
|
||||
BOOST_CHECK_EQUAL("WELL-2", deck->getKeyword("WWCT")->getRecord(0)->getItem(0)->getString(1));
|
||||
BOOST_CHECK_EQUAL("WELL-1", deck->getKeyword("WWCT" , 0)->getRecord(0)->getItem(0)->getString(0));
|
||||
BOOST_CHECK_EQUAL("WELL-2", deck->getKeyword("WWCT" , 0)->getRecord(0)->getItem(0)->getString(1));
|
||||
}
|
||||
|
||||
ParserPtr createBPRParser() {
|
||||
@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(parse_fileWithBPRKeyword_dataiscorrect) {
|
||||
ParserPtr parser = createBPRParser();
|
||||
DeckPtr deck = parser->parse(singleKeywordFile.string());
|
||||
|
||||
DeckKeywordConstPtr keyword = deck->getKeyword("BPR");
|
||||
DeckKeywordConstPtr keyword = deck->getKeyword("BPR" , 0);
|
||||
BOOST_CHECK_EQUAL(2U, keyword->size());
|
||||
|
||||
DeckRecordConstPtr record1 = keyword->getRecord(0);
|
||||
|
@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( parse_WCHONHIST_OK ) {
|
||||
ParserPtr parser(new Parser(JSON_CONFIG_FILE));
|
||||
boost::filesystem::path wconhistFile("testdata/WCONHIST/WCONHIST1");
|
||||
DeckPtr deck = parser->parse(wconhistFile.string());
|
||||
DeckKeywordConstPtr kw1 = deck->getKeyword("WCONHIST");
|
||||
DeckKeywordConstPtr kw1 = deck->getKeyword("WCONHIST" , 0);
|
||||
BOOST_CHECK_EQUAL( 3U , kw1->size() );
|
||||
|
||||
|
||||
|
@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawSingleIntItem_deckReturned) {
|
||||
BOOST_CHECK(!deck->hasKeyword("ANDOM"));
|
||||
|
||||
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
||||
BOOST_CHECK_EQUAL(1U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
||||
BOOST_CHECK_EQUAL(1U, deck->getKeyword("RANDOM" , 0)->getRecord(0)->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSeveralIntItem_deckReturned) {
|
||||
@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSeveralIntItem_deckReturne
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 1, 50));
|
||||
|
||||
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
||||
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
||||
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM" , 0)->getRecord(0)->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parseFromRawDeck_severalRawRecordsSeveralIntItem_deckReturned) {
|
||||
@ -198,8 +198,8 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_severalRawRecordsSeveralIntItem_deckReturn
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckInt("RANDOM", 10, 50));
|
||||
|
||||
BOOST_CHECK(deck->hasKeyword("RANDOM"));
|
||||
BOOST_CHECK_EQUAL(10U, deck->getKeyword("RANDOM")->size());
|
||||
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM")->getRecord(0)->size());
|
||||
BOOST_CHECK_EQUAL(10U, deck->getKeyword("RANDOM", 0)->size());
|
||||
BOOST_CHECK_EQUAL(50U, deck->getKeyword("RANDOM", 0)->getRecord(0)->size());
|
||||
}
|
||||
|
||||
/***************** Simple String parsing ********************************/
|
||||
@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(parseFromRawDeck_singleRawRecordsSingleStringItem_deckRetur
|
||||
DeckPtr deck = parser->parseFromRawDeck(setupRawDeckString("WWCT",1, 1));
|
||||
|
||||
BOOST_CHECK(deck->hasKeyword("WWCT"));
|
||||
BOOST_CHECK_EQUAL(1U, deck->getKeyword("WWCT")->size());
|
||||
BOOST_CHECK_EQUAL(1U, deck->getKeyword("WWCT" , 0)->size());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user