custom-opm-common/opm-common/opm/parser/eclipse/Parser/Parser.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Statoil ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef OPM_PARSER_HPP
21#define OPM_PARSER_HPP
22
23#include <iosfwd>
24#include <list>
25#include <map>
26#include <memory>
27#include <string>
28#include <utility>
29#include <vector>
30
31#include <stddef.h>
32
34
38
39namespace Json {
40 class JsonObject;
41}
42
43namespace Opm {
44
45 class Deck;
46 class ParseContext;
47 class ErrorGuard;
48 class RawKeyword;
49
53
54 class Parser {
55 public:
56 explicit Parser(bool addDefault = true);
57
58 static std::string stripComments(const std::string& inputString);
59
61 Deck parseFile(const std::string &dataFile,
62 const ParseContext&,
63 ErrorGuard& errors) const;
64
66 const ParseContext&) const;
67
68 Deck parseFile(const std::string& datafile) const;
69
71 const ParseContext&,
72 ErrorGuard& errors) const;
75
76 Deck parseStream(std::unique_ptr<std::istream>&& inputStream , const ParseContext& parseContext, ErrorGuard& errors) const;
77
79 void addParserKeyword(const Json::JsonObject& jsonKeyword);
80 void addParserKeyword(ParserKeyword&& parserKeyword);
81
85 bool hasKeyword( const std::string& ) const;
87
88 bool isRecognizedKeyword( const string_view& deckKeywordName) const;
89 const ParserKeyword& getParserKeywordFromDeckName(const string_view& deckKeywordName) const;
90 std::vector<std::string> getAllDeckNames () const;
91
92 void loadKeywords(const Json::JsonObject& jsonKeywords);
93 bool loadKeywordFromFile(const Opm::filesystem::path& configFile);
94
95 void loadKeywordsFromDirectory(const Opm::filesystem::path& directory , bool recursive = true);
96 void applyUnitsToDeck(Deck& deck) const;
97
103 size_t size() const;
104
105 template <class T>
106 void addKeyword() {
107 addParserKeyword( T() );
108 }
109
110 static EclipseState parse(const Deck& deck, const ParseContext& context);
111 static EclipseState parse(const std::string &filename, const ParseContext& context, ErrorGuard& errors);
112 static EclipseState parseData(const std::string &data, const ParseContext& context, ErrorGuard& errors);
113
117 static EclipseGrid parseGrid(const std::string &filename,
118 const ParseContext& context,
119 ErrorGuard& errors);
120
124 static EclipseGrid parseGrid(const Deck& deck,
125 const ParseContext& context);
126
131 const ParseContext& context,
132 ErrorGuard& errors);
133
134 const std::vector<std::pair<std::string,std::string>> codeKeywords() const;
135
136 private:
137 bool hasWildCardKeyword(const std::string& keyword) const;
138 const ParserKeyword* matchingKeyword(const string_view& keyword) const;
139 void addDefaultKeywords();
140
141 // std::vector< std::unique_ptr< const ParserKeyword > > keyword_storage;
142 std::list<ParserKeyword> keyword_storage;
143
144 // associative map of deck names and the corresponding ParserKeyword object
145 std::map< string_view, const ParserKeyword* > m_deckParserKeywords;
146
147 // associative map of the parser internal names and the corresponding
148 // ParserKeyword object for keywords which match a regular expression
149 std::map< string_view, const ParserKeyword* > m_wildCardKeywords;
150
151 std::vector<std::pair<std::string,std::string>> code_keywords;
152 };
153
154} // namespace Opm
155#endif /* PARSER_H */
156
const char *const name
Definition: cJSON.h:258
const char *const string
Definition: cJSON.h:170
Definition: JsonObject.hpp:31
Definition: Deck.hpp:115
Definition: EclipseGrid.hpp:54
Definition: EclipseState.hpp:63
Definition: ErrorGuard.hpp:29
Definition: ParseContext.hpp:84
Definition: ParserKeyword.hpp:73
Definition: custom-opm-common/opm-common/opm/parser/eclipse/Parser/Parser.hpp:54
void loadKeywords(const Json::JsonObject &jsonKeywords)
Deck parseFile(const std::string &dataFile, const ParseContext &, ErrorGuard &errors) const
The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is ret...
Deck parseFile(const std::string &, const ParseContext &) const
static EclipseState parse(const Deck &deck, const ParseContext &context)
bool isRecognizedKeyword(const string_view &deckKeywordName) const
const ParserKeyword & getParserKeywordFromDeckName(const string_view &deckKeywordName) const
std::vector< std::string > getAllDeckNames() const
void addParserKeyword(const Json::JsonObject &jsonKeyword)
Method to add ParserKeyword instances, these holding type and size information about the keywords and...
Deck parseString(const std::string &data, const ParseContext &) const
void addKeyword()
Definition: custom-opm-common/opm-common/opm/parser/eclipse/Parser/Parser.hpp:106
static EclipseState parse(const std::string &filename, const ParseContext &context, ErrorGuard &errors)
const std::vector< std::pair< std::string, std::string > > codeKeywords() const
bool loadKeywordFromFile(const Opm::filesystem::path &configFile)
static EclipseState parseData(const std::string &data, const ParseContext &context, ErrorGuard &errors)
const ParserKeyword & getKeyword(const std::string &name) const
Deck parseFile(const std::string &datafile) const
static EclipseGrid parseGrid(const Deck &deck, const ParseContext &context)
static std::string stripComments(const std::string &inputString)
Deck parseString(const std::string &data, const ParseContext &, ErrorGuard &errors) const
static EclipseGrid parseGridData(const std::string &data, const ParseContext &context, ErrorGuard &errors)
bool hasKeyword(const std::string &) const
Returns whether the parser knows about a keyword.
size_t size() const
Returns the approximate number of recognized keywords in decks.
Deck parseString(const std::string &data) const
Deck parseStream(std::unique_ptr< std::istream > &&inputStream, const ParseContext &parseContext, ErrorGuard &errors) const
void applyUnitsToDeck(Deck &deck) const
void addParserKeyword(ParserKeyword &&parserKeyword)
Parser(bool addDefault=true)
static EclipseGrid parseGrid(const std::string &filename, const ParseContext &context, ErrorGuard &errors)
void loadKeywordsFromDirectory(const Opm::filesystem::path &directory, bool recursive=true)
Definition: Stringview.hpp:48
Definition: JsonObject.hpp:29
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4
static std::string data()
Definition: exprtk.hpp:40022