My Project
Loading...
Searching...
No Matches
ParserKeyword.hpp
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#ifndef PARSER_KEYWORD_H
20#define PARSER_KEYWORD_H
21
22#include <iosfwd>
23#include <optional>
24#include <regex>
25#include <string>
26#include <unordered_set>
27#include <utility>
28#include <variant>
29
30#include <opm/input/eclipse/Parser/ParserEnums.hpp>
31#include <opm/input/eclipse/Parser/ParserRecord.hpp>
32
33namespace Json {
34 class JsonObject;
35}
36
37namespace Opm {
38 class Deck;
39 class DeckKeyword;
40 class ParseContext;
41 class ErrorGuard;
42 class ParserDoubleItem;
43 class RawKeyword;
44 class ErrorGuard;
45
46 /*
47 Small helper struct to assemble the information needed to infer the size
48 of a keyword based on another keyword in the deck.
49 */
51 public:
53 KeywordSize(const std::string& in_keyword, const std::string& in_item, int in_shift);
54 KeywordSize(const std::string& in_keyword, const std::string& in_item);
55 KeywordSize(const std::string& in_keyword, const std::string& in_item, bool table_collection, int in_shift);
56
57 KeywordSize(std::size_t min_size, const std::string& in_keyword, const std::string& in_item, bool table_collection, int in_shift);
58 explicit KeywordSize(ParserKeywordSizeEnum size_type);
59 explicit KeywordSize(std::size_t fixed_size);
60 KeywordSize(std::size_t fixed_size, bool code);
61 KeywordSize(std::size_t min_size, std::size_t fixed_size, bool code);
62
63 bool table_collection() const;
64 ParserKeywordSizeEnum size_type() const;
65 bool code() const;
66 int size_shift() const;
67 const std::string& keyword() const;
68 const std::string& item() const;
69 std::optional<std::size_t> min_size() const;
70 void min_size(int s);
71 const std::optional<std::variant<std::size_t, std::pair<std::string, std::string>>>& max_size() const;
72 std::string construct() const;
73
74 bool operator==(const KeywordSize& ) const;
75 bool operator!=(const KeywordSize& other) const;
76 private:
77 int shift{0};
78 bool is_table_collection{false};
79 ParserKeywordSizeEnum m_size_type;
80 std::optional<std::size_t> m_min_size;
81 std::optional<std::variant<std::size_t, std::pair<std::string, std::string>>> m_max_size;
82 bool is_code{false};
83 };
84
86 public:
87 ParserKeyword(const std::string& name, KeywordSize kw_size);
88 explicit ParserKeyword(const std::string& name);
89 explicit ParserKeyword(const Json::JsonObject& jsonConfig);
90
91 void initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem, bool table_collection, int size_shift);
92
93
94 static bool validInternalName(const std::string& name);
95 static bool validDeckName(const std::string_view& name);
96 bool hasMatchRegex() const;
97 bool hasMatchRegexSuffix() const;
98 void setMatchRegex(const std::string& deckNameRegexp);
99 void setMatchRegexSuffix(const std::string& deckNameRegexp);
100 bool matches(const std::string_view& ) const;
101 bool hasDimension() const;
102 void addRecord( ParserRecord );
103 void addDataRecord( ParserRecord );
104 const ParserRecord& getRecord(size_t recordIndex) const;
105 ParserRecord& getRecord(size_t recordIndex);
106 std::vector< ParserRecord >::const_iterator begin() const;
107 std::vector< ParserRecord >::const_iterator end() const;
108 const std::string className() const;
109 const std::string& getName() const;
110 std::optional<std::size_t> min_size() const;
111 size_t getFixedSize() const;
112 bool hasFixedSize() const;
113 bool isTableCollection() const;
114 std::string getDescription() const;
115 void setDescription(const std::string &description);
116
117 bool hasMultipleDeckNames() const;
118 void clearDeckNames();
119 void addDeckName( const std::string& deckName );
120 void setCodeEnd(const std::string& end);
121 const std::unordered_set<std::string>& deck_names() const;
122 const std::string& codeEnd() const;
123
124 const std::vector<std::string>& requiredKeywords() const;
125 const std::vector<std::string>& prohibitedKeywords() const;
126 void setRequiredKeywords(const std::vector<std::string>&);
127 void setProhibitedKeywords(const std::vector<std::string>&);
128
129 void clearValidSectionNames();
130 void addValidSectionName(const std::string& sectionName);
131 bool isValidSection(const std::string& sectionName) const;
132 const std::unordered_set<std::string>& sections() const;
133
134 DeckKeyword parse(const ParseContext& parseContext, ErrorGuard& errors, RawKeyword& rawKeyword, UnitSystem& active_unitsystem, UnitSystem& default_unitsystem) const;
135 enum ParserKeywordSizeEnum getSizeType() const;
136 const KeywordSize& getKeywordSize() const;
137 bool isDataKeyword() const;
138 bool rawStringKeyword() const;
139 bool isCodeKeyword() const;
140 bool isAlternatingKeyword() const;
141 bool isDoubleRecordKeyword() const;
142 void setAlternatingKeyword(bool alternating);
143 void setDoubleRecordsKeyword(bool double_rec);
144
145 std::string createDeclaration(const std::string& indent) const;
146 std::string createDecl() const;
147 std::string createCode() const;
148
149 bool operator==( const ParserKeyword& ) const;
150 bool operator!=( const ParserKeyword& ) const;
151
152 private:
153 std::string m_name;
154 KeywordSize keyword_size;
155 std::unordered_set<std::string> m_deckNames;
156 std::unordered_set<std::string> m_validSectionNames;
157 std::string m_matchRegexString;
158 std::regex m_matchRegex;
159 std::string m_matchRegexSuffix{};
160 std::vector< ParserRecord > m_records;
161 std::string m_Description;
162 bool raw_string_keyword = false;
163 bool alternating_keyword = false;
164 bool double_records = false;
165 std::string code_end;
166 std::vector<std::string> m_requires;
167 std::vector<std::string> m_prohibits;
168
169 static bool validNameStart(const std::string_view& name);
170 void initDeckNames( const Json::JsonObject& jsonConfig );
171 void initSectionNames( const Json::JsonObject& jsonConfig );
172 void initMatchRegex( const Json::JsonObject& jsonObject );
173 void initCode( const Json::JsonObject& jsonConfig );
174 void initData( const Json::JsonObject& jsonConfig );
175 void initProhibitedKeywords(const Json::JsonObject& keywordList);
176 void initRequiredKeywords(const Json::JsonObject& keywordList);
177 void initSize( const Json::JsonObject& jsonConfig );
178 void initSizeKeyword(bool table_collection, const Json::JsonObject& sizeObject);
179 void addItems( const Json::JsonObject& jsonConfig);
180 void parseRecords( const Json::JsonObject& recordsConfig);
181 bool matchesDeckNames(std::string_view name) const;
182 };
183
184std::ostream& operator<<( std::ostream&, const ParserKeyword& );
185}
186
187#endif
Definition JsonObject.hpp:31
Definition DeckKeyword.hpp:36
Definition ErrorGuard.hpp:29
Definition ParserKeyword.hpp:50
Definition ParseContext.hpp:84
Definition ParserKeyword.hpp:85
Definition ParserRecord.hpp:39
Definition RawKeyword.hpp:37
Definition UnitSystem.hpp:34
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30