Files
opm-common/opm/parser/eclipse/EclipseState/checkDeck.cpp
Jørgen Kvalsvik 7eb52f1023 Removes DeckKeyword's dependency on ParserKeyword
The completely constructed Deck isn't supposed to have any relationship
with the Parser structures (which are completely stateless in terms of
input data), and ParserKeyword in DeckKeyword was an anomaly. With
recent refactorings this lead to subtle lifetime issues.

This patch breaks this dependency and cleans up DeckKeyword accordingly,
while changing checkDeck to now take the parser as an additional
argument, to look up whether or not some DeckKeyword is in the right
section. This now also means that Parser* objects can be destroyed once
the Deck is created.

The Section::checkSectionTopology has been moved to Parser.cpp. It is a
temporary home for the feature to make the project compile nicely (i.e.
createKeywordList can be compiled as before, without introducing a
circular dependency on itself via Parser.cpp), until some proper cleanup
of the parser code has been done. It never really fully belonged in
Section.cpp anyway, so this is a first step in the direction of some
slight renaming.
2016-02-18 13:27:24 +01:00

54 lines
2.0 KiB
C++

/*
Copyright 2014 Andreas Lauser
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "checkDeck.hpp"
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Deck/Section.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
namespace Opm {
bool checkDeck(DeckConstPtr deck, ParserConstPtr parser, size_t enabledChecks) {
bool deckValid = true;
// make sure that the deck does not contain unknown keywords
if (enabledChecks & UnknownKeywords) {
size_t keywordIdx = 0;
for (; keywordIdx < deck->size(); keywordIdx++) {
const auto& keyword = deck->getKeyword(keywordIdx);
if (!parser->isRecognizedKeyword( keyword.name() ) ) {
std::string msg("Keyword '" + keyword.name() + "' is unknown.");
OpmLog::addMessage(Log::MessageType::Warning , Log::fileMessage( keyword.getFileName(), keyword.getLineNumber(), msg));
deckValid = false;
}
}
}
// make sure all mandatory sections are present and that their order is correct
if (enabledChecks & SectionTopology) {
bool ensureKeywordSection = enabledChecks & KeywordSection;
deckValid = deckValid && Section::checkSectionTopology(*deck, *parser, ensureKeywordSection);
}
return deckValid;
}
}