DeckKeyword is immutable.
This commit is contained in:
parent
081b87b5b4
commit
b924f6cd02
@ -32,19 +32,19 @@ namespace Opm {
|
||||
return m_keywords->hasKeyword(keyword);
|
||||
}
|
||||
|
||||
void Deck::addKeyword( DeckKeywordPtr keyword) {
|
||||
void Deck::addKeyword( DeckKeywordConstPtr keyword) {
|
||||
m_keywords->addKeyword(keyword);
|
||||
}
|
||||
|
||||
DeckKeywordPtr Deck::getKeyword(const std::string& keyword, size_t index) const {
|
||||
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword, size_t index) const {
|
||||
return m_keywords->getKeyword(keyword , index);
|
||||
}
|
||||
|
||||
DeckKeywordPtr Deck::getKeyword(const std::string& keyword) const {
|
||||
DeckKeywordConstPtr Deck::getKeyword(const std::string& keyword) const {
|
||||
return m_keywords->getKeyword(keyword);
|
||||
}
|
||||
|
||||
DeckKeywordPtr Deck::getKeyword(size_t index) const {
|
||||
DeckKeywordConstPtr Deck::getKeyword(size_t index) const {
|
||||
return m_keywords->getKeyword(index);
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ namespace Opm {
|
||||
return m_keywords->numKeywords( keyword );
|
||||
}
|
||||
|
||||
const std::vector<DeckKeywordPtr>& Deck::getKeywordList(const std::string& keyword) const {
|
||||
const std::vector<DeckKeywordConstPtr>& Deck::getKeywordList(const std::string& keyword) const {
|
||||
return m_keywords->getKeywordList( keyword );
|
||||
}
|
||||
|
||||
|
@ -32,13 +32,13 @@ namespace Opm {
|
||||
public:
|
||||
Deck();
|
||||
bool hasKeyword( const std::string& keyword ) const;
|
||||
void addKeyword( DeckKeywordPtr keyword);
|
||||
DeckKeywordPtr getKeyword(const std::string& keyword , size_t index) const;
|
||||
DeckKeywordPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordPtr getKeyword(size_t index) const;
|
||||
void addKeyword( DeckKeywordConstPtr keyword);
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword , size_t index) const;
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordConstPtr getKeyword(size_t index) const;
|
||||
|
||||
size_t numKeywords(const std::string& keyword) const;
|
||||
const std::vector<DeckKeywordPtr>& getKeywordList(const std::string& keyword) const;
|
||||
const std::vector<DeckKeywordConstPtr>& getKeywordList(const std::string& keyword) const;
|
||||
size_t size() const;
|
||||
void initUnitSystem();
|
||||
std::shared_ptr<UnitSystem> getDefaultUnitSystem() const;
|
||||
|
@ -36,30 +36,30 @@ namespace Opm {
|
||||
return m_keywordList.size();
|
||||
}
|
||||
|
||||
void KeywordContainer::addKeyword(DeckKeywordPtr keyword) {
|
||||
void KeywordContainer::addKeyword(DeckKeywordConstPtr keyword) {
|
||||
m_keywordList.push_back(keyword);
|
||||
|
||||
if (!hasKeyword(keyword->name())) {
|
||||
m_keywordMap[keyword->name()] = std::vector<DeckKeywordPtr>();
|
||||
m_keywordMap[keyword->name()] = std::vector<DeckKeywordConstPtr>();
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<DeckKeywordPtr>& keywordList = m_keywordMap[keyword->name()];
|
||||
std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap[keyword->name()];
|
||||
keywordList.push_back(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<DeckKeywordPtr>& KeywordContainer::getKeywordList(const std::string& keyword) const {
|
||||
const std::vector<DeckKeywordConstPtr>& KeywordContainer::getKeywordList(const std::string& keyword) const {
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKeywordPtr>& keywordList = m_keywordMap.find(keyword)->second;
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = m_keywordMap.find(keyword)->second;
|
||||
return keywordList;
|
||||
} else
|
||||
throw std::invalid_argument("Keyword: " + keyword + " is not found in the container");
|
||||
}
|
||||
|
||||
|
||||
DeckKeywordPtr KeywordContainer::getKeyword(const std::string& keyword, size_t index) const {
|
||||
const std::vector<DeckKeywordPtr>& keywordList = getKeywordList( keyword );
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword, size_t index) const {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
if (index < keywordList.size())
|
||||
return keywordList[index];
|
||||
else
|
||||
@ -67,12 +67,12 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
DeckKeywordPtr KeywordContainer::getKeyword(const std::string& keyword) const {
|
||||
const std::vector<DeckKeywordPtr>& keywordList = getKeywordList( keyword );
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(const std::string& keyword) const {
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
return keywordList.back();
|
||||
}
|
||||
|
||||
DeckKeywordPtr KeywordContainer::getKeyword(size_t index) const {
|
||||
DeckKeywordConstPtr KeywordContainer::getKeyword(size_t index) const {
|
||||
if (index < m_keywordList.size())
|
||||
return m_keywordList[index];
|
||||
else
|
||||
@ -81,17 +81,17 @@ namespace Opm {
|
||||
|
||||
size_t KeywordContainer::numKeywords(const std::string& keyword) const{
|
||||
if (hasKeyword(keyword)) {
|
||||
const std::vector<DeckKeywordPtr>& keywordList = getKeywordList( keyword );
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = getKeywordList( keyword );
|
||||
return keywordList.size();
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator KeywordContainer::begin() {
|
||||
std::vector<DeckKeywordConstPtr>::iterator KeywordContainer::begin() {
|
||||
return m_keywordList.begin();
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator KeywordContainer::end() {
|
||||
std::vector<DeckKeywordConstPtr>::iterator KeywordContainer::end() {
|
||||
return m_keywordList.end();
|
||||
}
|
||||
}
|
||||
|
@ -22,20 +22,20 @@ namespace Opm {
|
||||
KeywordContainer();
|
||||
bool hasKeyword(const std::string& keyword) const;
|
||||
size_t size() const;
|
||||
void addKeyword(DeckKeywordPtr keyword);
|
||||
DeckKeywordPtr getKeyword(const std::string& keyword, size_t index) const;
|
||||
DeckKeywordPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordPtr getKeyword(size_t index) const;
|
||||
void addKeyword(DeckKeywordConstPtr keyword);
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword, size_t index) const;
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordConstPtr getKeyword(size_t index) const;
|
||||
|
||||
const std::vector<DeckKeywordPtr>& getKeywordList(const std::string& keyword) const;
|
||||
const std::vector<DeckKeywordConstPtr>& getKeywordList(const std::string& keyword) const;
|
||||
size_t numKeywords(const std::string& keyword) const;
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator begin();
|
||||
std::vector<DeckKeywordPtr>::iterator end();
|
||||
std::vector<DeckKeywordConstPtr>::iterator begin();
|
||||
std::vector<DeckKeywordConstPtr>::iterator end();
|
||||
|
||||
private:
|
||||
std::vector<DeckKeywordPtr> m_keywordList;
|
||||
std::map<std::string, std::vector<DeckKeywordPtr> > m_keywordMap;
|
||||
std::vector<DeckKeywordConstPtr> m_keywordList;
|
||||
std::map<std::string, std::vector<DeckKeywordConstPtr> > m_keywordMap;
|
||||
};
|
||||
typedef std::shared_ptr<KeywordContainer> KeywordContainerPtr;
|
||||
typedef std::shared_ptr<const KeywordContainer> KeywordContainerConstPtr;
|
||||
|
@ -77,11 +77,11 @@ namespace Opm {
|
||||
return m_keywords.hasKeyword(keyword);
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator Section::begin() {
|
||||
std::vector<DeckKeywordConstPtr>::iterator Section::begin() {
|
||||
return m_keywords.begin();
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator Section::end() {
|
||||
std::vector<DeckKeywordConstPtr>::iterator Section::end() {
|
||||
return m_keywords.end();
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@ namespace Opm {
|
||||
public:
|
||||
Section(DeckConstPtr deck, const std::string& startKeyword);
|
||||
bool hasKeyword( const std::string& keyword ) const;
|
||||
std::vector<DeckKeywordPtr>::iterator begin();
|
||||
std::vector<DeckKeywordPtr>::iterator end();
|
||||
std::vector<DeckKeywordConstPtr>::iterator begin();
|
||||
std::vector<DeckKeywordConstPtr>::iterator end();
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword, size_t index) const;
|
||||
DeckKeywordConstPtr getKeyword(const std::string& keyword) const;
|
||||
DeckKeywordConstPtr getKeyword(size_t index) const;
|
||||
|
@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(getKeywordList_OK) {
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
|
||||
const std::vector<DeckKeywordPtr>& keywordList = container->getKeywordList("TRULS");
|
||||
const std::vector<DeckKeywordConstPtr>& keywordList = container->getKeywordList("TRULS");
|
||||
BOOST_CHECK_EQUAL( 3U , keywordList.size() );
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(ParseDENSITY) {
|
||||
ParserPtr parser(new Parser());
|
||||
boost::filesystem::path file("testdata/integration_tests/DENSITY/DENSITY1");
|
||||
DeckPtr deck = parser->parseFile(file.string());
|
||||
DeckKeywordPtr densityKw = deck->getKeyword("DENSITY" , 0);
|
||||
DeckKeywordConstPtr densityKw = deck->getKeyword("DENSITY" , 0);
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL( 2U , densityKw->size());
|
||||
|
@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE(ParsePOROandPERMX) {
|
||||
boost::filesystem::path poroFile("testdata/integration_tests/PORO/PORO1");
|
||||
DeckPtr deck = parser->parseFile(poroFile.string());
|
||||
DeckKeywordConstPtr kw1 = deck->getKeyword("PORO" , 0);
|
||||
DeckKeywordPtr kw2 = deck->getKeyword("PERMX" , 0);
|
||||
DeckKeywordConstPtr kw2 = deck->getKeyword("PERMX" , 0);
|
||||
|
||||
BOOST_CHECK_THROW( kw1->getIntData() , std::logic_error );
|
||||
BOOST_CHECK_THROW( kw1->getStringData() , std::logic_error );
|
||||
|
@ -476,7 +476,7 @@ namespace Opm {
|
||||
void Parser::applyUnitsToDeck(DeckPtr deck) const {
|
||||
deck->initUnitSystem();
|
||||
for (size_t index=0; index < deck->size(); ++index) {
|
||||
DeckKeywordPtr deckKeyword = deck->getKeyword( index );
|
||||
DeckKeywordConstPtr deckKeyword = deck->getKeyword( index );
|
||||
if (isRecognizedKeyword( deckKeyword->name())) {
|
||||
ParserKeywordConstPtr parserKeyword = getParserKeywordFromDeckName( deckKeyword->name() );
|
||||
if (parserKeyword->hasDimension()) {
|
||||
|
@ -694,7 +694,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
|
||||
void ParserKeyword::applyUnitsToDeck(std::shared_ptr<const Deck> deck , std::shared_ptr<DeckKeyword> deckKeyword) const {
|
||||
void ParserKeyword::applyUnitsToDeck(std::shared_ptr<const Deck> deck , std::shared_ptr<const DeckKeyword> deckKeyword) const {
|
||||
std::shared_ptr<const ParserRecord> parserRecord = getRecord();
|
||||
for (size_t index = 0; index < deckKeyword->size(); index++) {
|
||||
std::shared_ptr<const DeckRecord> deckRecord = deckKeyword->getRecord(index);
|
||||
|
@ -142,7 +142,7 @@ namespace Opm {
|
||||
bool isDataKeyword() const;
|
||||
bool equal(const ParserKeyword& other) const;
|
||||
void inlineNew(std::ostream& os , const std::string& lhs, const std::string& indent) const;
|
||||
void applyUnitsToDeck(std::shared_ptr<const Deck> deck , std::shared_ptr<DeckKeyword> deckKeyword) const;
|
||||
void applyUnitsToDeck(std::shared_ptr<const Deck> deck , std::shared_ptr<const DeckKeyword> deckKeyword) const;
|
||||
private:
|
||||
std::pair<std::string,std::string> m_sizeDefinitionPair;
|
||||
std::string m_name;
|
||||
|
Loading…
Reference in New Issue
Block a user