From 8ac17f744ecead6711db0a8be2e9f1858721069f Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 26 Feb 2015 11:46:25 +0100 Subject: [PATCH] Added Data awareness to ParserRecord. --- opm/parser/eclipse/Parser/ParserRecord.cpp | 22 +++++++++++++++- opm/parser/eclipse/Parser/ParserRecord.hpp | 3 +++ .../Parser/tests/ParserRecordTests.cpp | 26 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/opm/parser/eclipse/Parser/ParserRecord.cpp b/opm/parser/eclipse/Parser/ParserRecord.cpp index b784fc5f4..da9452ff4 100644 --- a/opm/parser/eclipse/Parser/ParserRecord.cpp +++ b/opm/parser/eclipse/Parser/ParserRecord.cpp @@ -23,7 +23,9 @@ namespace Opm { - ParserRecord::ParserRecord() { + ParserRecord::ParserRecord() + : m_dataRecord( false ) + { } size_t ParserRecord::size() const { @@ -31,6 +33,9 @@ namespace Opm { } void ParserRecord::addItem(ParserItemConstPtr item) { + if (m_dataRecord) + throw std::invalid_argument("Record is already marked as DataRecord - can not add items"); + if (m_itemMap.find(item->name()) == m_itemMap.end()) { m_items.push_back(item); m_itemMap[item->name()] = item; @@ -38,6 +43,16 @@ namespace Opm { throw std::invalid_argument("Itemname: " + item->name() + " already exists."); } + void ParserRecord::addDataItem(ParserItemConstPtr item) { + if (m_items.size() > 0) + throw std::invalid_argument("Record already contains items - can not add Data Item"); + + addItem(item); + m_dataRecord = true; + } + + + std::vector::const_iterator ParserRecord::begin() const { return m_items.begin(); } @@ -131,4 +146,9 @@ namespace Opm { return equal_; } + bool ParserRecord::isDataRecord() const { + return m_dataRecord; + } + + } diff --git a/opm/parser/eclipse/Parser/ParserRecord.hpp b/opm/parser/eclipse/Parser/ParserRecord.hpp index ba90e1d22..b0d090236 100644 --- a/opm/parser/eclipse/Parser/ParserRecord.hpp +++ b/opm/parser/eclipse/Parser/ParserRecord.hpp @@ -36,15 +36,18 @@ namespace Opm { ParserRecord(); size_t size() const; void addItem( ParserItemConstPtr item ); + void addDataItem(ParserItemConstPtr item); ParserItemConstPtr get(size_t index) const; ParserItemConstPtr get(const std::string& itemName) const; DeckRecordConstPtr parse(RawRecordPtr rawRecord) const; + bool isDataRecord() const; bool equal(const ParserRecord& other) const; bool hasDimension() const; void applyUnitsToDeck(std::shared_ptr deck , std::shared_ptr deckRecord) const; std::vector::const_iterator begin() const; std::vector::const_iterator end() const; private: + bool m_dataRecord; std::vector m_items; std::map m_itemMap; }; diff --git a/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp b/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp index 6eb1a5fbf..6196c0fac 100644 --- a/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp @@ -350,3 +350,29 @@ BOOST_AUTO_TEST_CASE(ParseRecordHasDimensionCorrect) { item2->push_backDimension("Length*Length/Time"); BOOST_CHECK_EQUAL( true , parserRecord->hasDimension()); } + + +BOOST_AUTO_TEST_CASE(DefaultNotDataRecord) { + ParserRecord record; + BOOST_CHECK_EQUAL( false , record.isDataRecord() ); +} + + + +BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws1) { + ParserRecord record; + ParserIntItemConstPtr dataItem = ParserIntItemConstPtr(new ParserIntItem( "ACTNUM" , ALL)); + ParserIntItemConstPtr item = ParserIntItemConstPtr(new ParserIntItem( "XXX" , ALL)); + record.addDataItem( dataItem ); + BOOST_CHECK_THROW( record.addItem( item ) , std::invalid_argument); + BOOST_CHECK_THROW( record.addItem( dataItem ) , std::invalid_argument); +} + +BOOST_AUTO_TEST_CASE(MixingDataAndItems_throws2) { + ParserRecord record; + ParserIntItemConstPtr dataItem = ParserIntItemConstPtr(new ParserIntItem( "ACTNUM" , ALL)); + ParserIntItemConstPtr item = ParserIntItemConstPtr(new ParserIntItem( "XXX" , ALL)); + + record.addItem( item ); + BOOST_CHECK_THROW( record.addDataItem( dataItem ) , std::invalid_argument); +}