Added some iterator support in KeywordContainer and Section. Not finished.
This commit is contained in:
@@ -88,4 +88,11 @@ namespace Opm {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator KeywordContainer::begin() {
|
||||
return m_keywordList.begin();
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator KeywordContainer::end() {
|
||||
return m_keywordList.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace Opm {
|
||||
const std::vector<DeckKeywordPtr>& getKeywordList(const std::string& keyword) const;
|
||||
size_t numKeywords(const std::string& keyword) const;
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator begin();
|
||||
std::vector<DeckKeywordPtr>::iterator end();
|
||||
|
||||
private:
|
||||
std::vector<DeckKeywordPtr> m_keywordList;
|
||||
std::map<std::string, std::vector<DeckKeywordPtr> > m_keywordMap;
|
||||
|
||||
@@ -25,25 +25,25 @@
|
||||
#include <opm/parser/eclipse/Deck/Section.hpp>
|
||||
|
||||
namespace Opm {
|
||||
Section::Section(Deck& deck, const std::string& startKeyword, const std::vector<std::string>& stopKeywords ) {
|
||||
Section::Section(DeckConstPtr deck, const std::string& startKeyword, const std::vector<std::string>& stopKeywords ) {
|
||||
populateKeywords(deck, startKeyword, stopKeywords);
|
||||
}
|
||||
|
||||
void Section::populateKeywords(const Deck& deck, const std::string& startKeyword,
|
||||
void Section::populateKeywords(DeckConstPtr deck, const std::string& startKeyword,
|
||||
const std::vector<std::string>& stopKeywords)
|
||||
{
|
||||
size_t i;
|
||||
bool isCollecting = false;
|
||||
for (i=0; i<deck.size(); i++) {
|
||||
std::cout << deck.getKeyword(i)->name() << std::endl;
|
||||
if (!isCollecting && startKeyword.compare(deck.getKeyword(i)->name()) == 0) {
|
||||
for (i=0; i<deck->size(); i++) {
|
||||
std::string currentKeyword = deck->getKeyword(i)->name();
|
||||
if (!isCollecting && startKeyword.compare(currentKeyword) == 0) {
|
||||
isCollecting = true;
|
||||
}
|
||||
if (std::find(stopKeywords.begin(), stopKeywords.end(), deck.getKeyword(i)->name()) != stopKeywords.end()) {
|
||||
if (std::find(stopKeywords.begin(), stopKeywords.end(), currentKeyword) != stopKeywords.end()) {
|
||||
break;
|
||||
}
|
||||
if (isCollecting) {
|
||||
m_keywords.addKeyword(deck.getKeyword(i));
|
||||
m_keywords.addKeyword(deck->getKeyword(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,12 @@ namespace Opm {
|
||||
bool Section::hasKeyword( const std::string& keyword ) const {
|
||||
return m_keywords.hasKeyword(keyword);
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator Section::begin() {
|
||||
return m_keywords.begin();
|
||||
}
|
||||
|
||||
std::vector<DeckKeywordPtr>::iterator Section::end() {
|
||||
return m_keywords.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,48 +21,61 @@
|
||||
#define SECTION_HPP
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
class Section
|
||||
class Section : public boost::iterator_facade<Section, DeckKeywordPtr, boost::forward_traversal_tag>
|
||||
{
|
||||
public:
|
||||
Section(Deck& deck, const std::string& startKeyword, const std::vector<std::string>& stopKeywords );
|
||||
Section(DeckConstPtr deck, const std::string& startKeyword, const std::vector<std::string>& stopKeywords );
|
||||
bool hasKeyword( const std::string& keyword ) const;
|
||||
std::vector<DeckKeywordPtr>::iterator begin();
|
||||
std::vector<DeckKeywordPtr>::iterator end();
|
||||
|
||||
bool isStopKeyword(const std::vector<std::string>& stopKeywords, std::string currentKeyword);
|
||||
private:
|
||||
KeywordContainer m_keywords;
|
||||
void populateKeywords(const Deck& deck, const std::string& startKeyword, const std::vector<std::string>& stopKeywords);
|
||||
void populateKeywords(DeckConstPtr deck, const std::string& startKeyword, const std::vector<std::string>& stopKeywords);
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Section> SectionPtr;
|
||||
typedef std::shared_ptr<const Section> SectionConstPtr;
|
||||
|
||||
|
||||
class RUNSPECSection : public Section {
|
||||
public:
|
||||
RUNSPECSection(Deck& deck) : Section (deck, "RUNSPEC", std::vector<std::string>() = {"GRID"}) {}
|
||||
RUNSPECSection(DeckConstPtr deck) : Section (deck, "RUNSPEC", std::vector<std::string>() = {"GRID"}) {}
|
||||
};
|
||||
|
||||
class GRIDSection : public Section {
|
||||
public:
|
||||
GRIDSection(Deck& deck) : Section (deck, "GRID", std::vector<std::string>() = {"EDIT", "PROPS"}) {}
|
||||
GRIDSection(DeckConstPtr deck) : Section (deck, "GRID", std::vector<std::string>() = {"EDIT", "PROPS"}) {}
|
||||
};
|
||||
|
||||
class EDITSection : public Section {
|
||||
public:
|
||||
EDITSection(Deck& deck) : Section (deck, "EDIT", std::vector<std::string>() = {"PROPS"}) {}
|
||||
EDITSection(DeckConstPtr deck) : Section (deck, "EDIT", std::vector<std::string>() = {"PROPS"}) {}
|
||||
};
|
||||
|
||||
class PROPSSection : public Section {
|
||||
public:
|
||||
PROPSSection(Deck& deck) : Section (deck, "PROPS", std::vector<std::string>() = {"REGIONS", "SOLUTION"}) {}
|
||||
PROPSSection(DeckConstPtr deck) : Section (deck, "PROPS", std::vector<std::string>() = {"REGIONS", "SOLUTION"}) {}
|
||||
};
|
||||
|
||||
class REGIONSSection : public Section {
|
||||
public:
|
||||
REGIONSSection(Deck& deck) : Section (deck, "REGIONS", std::vector<std::string>() = {"SOLUTION"}) {}
|
||||
REGIONSSection(DeckConstPtr deck) : Section (deck, "REGIONS", std::vector<std::string>() = {"SOLUTION"}) {}
|
||||
};
|
||||
|
||||
class SOLUTIONSection : public Section {
|
||||
public:
|
||||
SOLUTIONSection(Deck& deck) : Section (deck, "SOLUTION", std::vector<std::string>() = {"SUMMARY", "SCHEDULE"}) {}
|
||||
SOLUTIONSection(DeckConstPtr deck) : Section (deck, "SOLUTION", std::vector<std::string>() = {"SUMMARY", "SCHEDULE"}) {}
|
||||
};
|
||||
|
||||
class SCHEDULESection : public Section {
|
||||
public:
|
||||
SCHEDULESection(DeckConstPtr deck) : Section (deck, "SCHEDULE", std::vector<std::string>() = {}) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +152,22 @@ BOOST_AUTO_TEST_CASE(keywordList_getbyindex_correctkeywordreturned) {
|
||||
BOOST_CHECK_EQUAL("TRULSX", container->getKeyword(2)->name());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keywordList_canIterate) {
|
||||
KeywordContainerPtr container(new KeywordContainer());
|
||||
DeckKeywordPtr keyword1 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword2 = DeckKeywordPtr(new DeckKeyword("TRULS"));
|
||||
DeckKeywordPtr keyword3 = DeckKeywordPtr(new DeckKeyword("TRULSX"));
|
||||
container->addKeyword(keyword1);
|
||||
container->addKeyword(keyword2);
|
||||
container->addKeyword(keyword3);
|
||||
int numberOfItems = 0;
|
||||
for (auto iter=container->begin(); iter != container->end(); ++iter) {
|
||||
// std::cout << typeid(iter).name() << std::endl;
|
||||
// std::cout << iter->name() << std::endl;
|
||||
numberOfItems++;
|
||||
}
|
||||
BOOST_CHECK_EQUAL(3, numberOfItems);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,21 +21,22 @@
|
||||
#define BOOST_TEST_MODULE SectionTests
|
||||
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Section.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SectionTest) {
|
||||
Deck deck;
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr test1(new DeckKeyword("TEST1"));
|
||||
deck.addKeyword(test1);
|
||||
deck->addKeyword(test1);
|
||||
DeckKeywordPtr test2(new DeckKeyword("TEST2"));
|
||||
deck.addKeyword(test2);
|
||||
deck->addKeyword(test2);
|
||||
DeckKeywordPtr test3(new DeckKeyword("TEST3"));
|
||||
deck.addKeyword(test3);
|
||||
deck->addKeyword(test3);
|
||||
DeckKeywordPtr test4(new DeckKeyword("TEST4"));
|
||||
deck.addKeyword(test4);
|
||||
deck->addKeyword(test4);
|
||||
Section section(deck, "TEST1", std::vector<std::string>() = {"TEST3", "TEST4"});
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("TEST1"));
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("TEST2"));
|
||||
@@ -43,25 +44,46 @@ BOOST_AUTO_TEST_CASE(SectionTest) {
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("TEST4"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(IteratorTest) {
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr test1(new DeckKeyword("TEST1"));
|
||||
deck->addKeyword(test1);
|
||||
DeckKeywordPtr test2(new DeckKeyword("TEST2"));
|
||||
deck->addKeyword(test2);
|
||||
DeckKeywordPtr test3(new DeckKeyword("TEST3"));
|
||||
deck->addKeyword(test3);
|
||||
DeckKeywordPtr test4(new DeckKeyword("TEST4"));
|
||||
deck->addKeyword(test4);
|
||||
Section section(deck, "TEST1", std::vector<std::string>() = {"TEST3", "TEST4"});
|
||||
|
||||
int numberOfItems = 0;
|
||||
for (auto iter=section.begin(); iter != section.end(); ++iter) {
|
||||
// std::cout << typeid(iter).name() << std::endl;
|
||||
// std::cout << iter->name() << std::endl;
|
||||
numberOfItems++;
|
||||
}
|
||||
BOOST_CHECK_EQUAL(2, numberOfItems);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RUNSPECSection_EmptyDeck) {
|
||||
Deck deck;
|
||||
DeckPtr deck(new Deck());
|
||||
BOOST_REQUIRE_NO_THROW(RUNSPECSection section(deck));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RUNSPECSection_ReadSimpleDeck) {
|
||||
Deck deck;
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr test1(new DeckKeyword("TEST1"));
|
||||
deck.addKeyword(test1);
|
||||
deck->addKeyword(test1);
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("RUNSPEC"));
|
||||
deck.addKeyword(runSpec);
|
||||
deck->addKeyword(runSpec);
|
||||
DeckKeywordPtr test2(new DeckKeyword("TEST2"));
|
||||
deck.addKeyword(test2);
|
||||
deck->addKeyword(test2);
|
||||
DeckKeywordPtr test3(new DeckKeyword("TEST3"));
|
||||
deck.addKeyword(test3);
|
||||
deck->addKeyword(test3);
|
||||
DeckKeywordPtr grid(new DeckKeyword("GRID"));
|
||||
deck.addKeyword(grid);
|
||||
deck->addKeyword(grid);
|
||||
DeckKeywordPtr test4(new DeckKeyword("TEST4"));
|
||||
deck.addKeyword(test4);
|
||||
deck->addKeyword(test4);
|
||||
RUNSPECSection section(deck);
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("TEST1"));
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("RUNSPEC"));
|
||||
@@ -72,100 +94,117 @@ BOOST_AUTO_TEST_CASE(RUNSPECSection_ReadSimpleDeck) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RUNSPECSection_ReadSmallestPossibleDeck) {
|
||||
Deck deck;
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("RUNSPEC"));
|
||||
deck.addKeyword(runSpec);
|
||||
deck->addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("GRID"));
|
||||
deck.addKeyword(grid);
|
||||
deck->addKeyword(grid);
|
||||
RUNSPECSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("RUNSPEC"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("GRID"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GRIDSection_TerminatedByEDITKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("GRID"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("EDIT"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr grid(new DeckKeyword("GRID"));
|
||||
deck->addKeyword(grid);
|
||||
DeckKeywordPtr edit(new DeckKeyword("EDIT"));
|
||||
deck->addKeyword(edit);
|
||||
GRIDSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("GRID"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("EDIT"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(GRIDSection_TerminatedByPROPSKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("GRID"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("PROPS"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr grid(new DeckKeyword("GRID"));
|
||||
deck->addKeyword(grid);
|
||||
DeckKeywordPtr props(new DeckKeyword("PROPS"));
|
||||
deck->addKeyword(props);
|
||||
GRIDSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("GRID"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("PROPS"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EDITSection_TerminatedByPROPSKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("EDIT"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("PROPS"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr edit(new DeckKeyword("EDIT"));
|
||||
deck->addKeyword(edit);
|
||||
DeckKeywordPtr props(new DeckKeyword("PROPS"));
|
||||
deck->addKeyword(props);
|
||||
EDITSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("EDIT"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("PROPS"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PROPSSection_TerminatedByREGIONSKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("PROPS"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("REGIONS"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr props(new DeckKeyword("PROPS"));
|
||||
deck->addKeyword(props);
|
||||
DeckKeywordPtr regions(new DeckKeyword("REGIONS"));
|
||||
deck->addKeyword(regions);
|
||||
PROPSSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("PROPS"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("REGIONS"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(PROPSSection_TerminatedBySOLUTIONKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("PROPS"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("SOLUTION"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr props(new DeckKeyword("PROPS"));
|
||||
deck->addKeyword(props);
|
||||
DeckKeywordPtr solution(new DeckKeyword("SOLUTION"));
|
||||
deck->addKeyword(solution);
|
||||
PROPSSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("PROPS"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("SOLUTION"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(REGIONSSection_TerminatedBySOLUTIONKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("REGIONS"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("SOLUTION"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr regions(new DeckKeyword("REGIONS"));
|
||||
deck->addKeyword(regions);
|
||||
DeckKeywordPtr solution(new DeckKeyword("SOLUTION"));
|
||||
deck->addKeyword(solution);
|
||||
REGIONSSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("REGIONS"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("SOLUTION"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SOLUTIONSection_TerminatedBySUMMARYKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("SOLUTION"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("SUMMARY"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr solution(new DeckKeyword("SOLUTION"));
|
||||
deck->addKeyword(solution);
|
||||
DeckKeywordPtr summary(new DeckKeyword("SUMMARY"));
|
||||
deck->addKeyword(summary);
|
||||
SOLUTIONSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("SOLUTION"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("SUMMARY"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SOLUTIONSection_TerminatedBySCHEDULEKeyword) {
|
||||
Deck deck;
|
||||
DeckKeywordPtr runSpec(new DeckKeyword("SOLUTION"));
|
||||
deck.addKeyword(runSpec);
|
||||
DeckKeywordPtr grid(new DeckKeyword("SCHEDULE"));
|
||||
deck.addKeyword(grid);
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr solution(new DeckKeyword("SOLUTION"));
|
||||
deck->addKeyword(solution);
|
||||
DeckKeywordPtr schedule(new DeckKeyword("SCHEDULE"));
|
||||
deck->addKeyword(schedule);
|
||||
SOLUTIONSection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("SOLUTION"));
|
||||
BOOST_CHECK_EQUAL(false, section.hasKeyword("SCHEDULE"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SCHEDULESection_NotTerminated) {
|
||||
DeckPtr deck(new Deck());
|
||||
DeckKeywordPtr schedule(new DeckKeyword("SCHEDULE"));
|
||||
deck->addKeyword(schedule);
|
||||
DeckKeywordPtr test1(new DeckKeyword("TEST1"));
|
||||
deck->addKeyword(test1);
|
||||
DeckKeywordPtr test2(new DeckKeyword("TEST2"));
|
||||
deck->addKeyword(test2);
|
||||
DeckKeywordPtr test3(new DeckKeyword("TEST3"));
|
||||
deck->addKeyword(test3);
|
||||
SCHEDULESection section(deck);
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("SCHEDULE"));
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("TEST1"));
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("TEST2"));
|
||||
BOOST_CHECK_EQUAL(true, section.hasKeyword("TEST3"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user