From 23458352331fc52e172fa0a6cc2a537b1af85fbf Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Tue, 8 Oct 2013 15:58:46 +0200 Subject: [PATCH] Added warning capabilities to the Deck --- opm/parser/eclipse/Deck/Deck.cpp | 18 ++++++++++++++++ opm/parser/eclipse/Deck/Deck.hpp | 4 ++++ opm/parser/eclipse/Deck/tests/DeckTests.cpp | 24 +++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/opm/parser/eclipse/Deck/Deck.cpp b/opm/parser/eclipse/Deck/Deck.cpp index 971d46072..2da54fc48 100644 --- a/opm/parser/eclipse/Deck/Deck.cpp +++ b/opm/parser/eclipse/Deck/Deck.cpp @@ -59,6 +59,24 @@ namespace Opm { return m_keywords->size(); } + size_t Deck::numWarnings() const { + return m_warnings.size(); + } + + void Deck::addWarning(const std::string& warningText , const std::string& filename , size_t lineNR) { + std::pair location(filename , lineNR); + std::pair > warning(warningText , location); + + m_warnings.push_back( warning ); + } + + const std::pair >& Deck::getWarning( size_t index ) const { + if (index < m_warnings.size()) + return m_warnings[index]; + else + throw std::invalid_argument("Index out of range"); + } + } diff --git a/opm/parser/eclipse/Deck/Deck.hpp b/opm/parser/eclipse/Deck/Deck.hpp index ffd1156ef..88fe67a7d 100644 --- a/opm/parser/eclipse/Deck/Deck.hpp +++ b/opm/parser/eclipse/Deck/Deck.hpp @@ -40,8 +40,12 @@ namespace Opm { size_t numKeywords(const std::string& keyword); const std::vector& getKeywordList(const std::string& keyword); size_t size() const; + size_t numWarnings() const; + void addWarning(const std::string& warningText , const std::string& filename , size_t lineNR); + const std::pair >& getWarning( size_t index ) const; private: KeywordContainerPtr m_keywords; + std::vector > > m_warnings; //<"Warning Text" , <"Filename" , LineNR>> }; typedef boost::shared_ptr DeckPtr; diff --git a/opm/parser/eclipse/Deck/tests/DeckTests.cpp b/opm/parser/eclipse/Deck/tests/DeckTests.cpp index db70bf1de..5fa547814 100644 --- a/opm/parser/eclipse/Deck/tests/DeckTests.cpp +++ b/opm/parser/eclipse/Deck/tests/DeckTests.cpp @@ -118,3 +118,27 @@ BOOST_AUTO_TEST_CASE(size_twokeyword_return2) { } +BOOST_AUTO_TEST_CASE(DECKWARNING_EMPTYOK) { + Deck deck; + BOOST_CHECK_EQUAL(0U, deck.numWarnings()); +} + + +BOOST_AUTO_TEST_CASE(DECKAddWarning) { + Deck deck; + deck.addWarning("WARNING" , "FILE" , 100U); + BOOST_CHECK_EQUAL(1U, deck.numWarnings()); + + deck.addWarning("WARNING2" , "FILE2" , 200U); + BOOST_CHECK_EQUAL(2U, deck.numWarnings()); + + const std::pair >& warning = deck.getWarning( 0 ); + const std::pair& location = warning.second; + + BOOST_CHECK_EQUAL( warning.first , "WARNING" ); + BOOST_CHECK_EQUAL( location.first , "FILE" ); + BOOST_CHECK_EQUAL( location.second , 100U ); + +} + +