ifeqEntry.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionEntries::ifeqEntry
26 
27 Description
28  Conditional parsing of dictionary entries.
29 
30  E.g.
31  \verbatim
32  a #calc "0.123";
33  b 1.23e-1;
34 
35  #ifeq $a $b
36  ..
37  #else
38  ..
39  #endif
40  \endverbatim
41 
42  \verbatim
43  ddtSchemes
44  {
45  #ifeq ${FOAM_APPLICATION} simpleFoam
46  default steadyState;
47  #else
48  default Euler;
49  #endif
50  }
51  \endverbatim
52 
53  Note:
54  - supports dictionary variables and environment variables
55  - the two arguments should be two tokens
56  - the comparison is a string comparison for any word/string/variable,
57  integer comparison for two integers and floating point comparison for
58  any floating point number.
59  - parsing of (non)matching \c #else, \c #endif is not very sophisticated
60 
61 See also
62  Foam::functionEntries::ifEntry
63 
64 SourceFiles
65  ifeqEntry.C
66 
67 \*---------------------------------------------------------------------------*/
68 
69 #ifndef ifeqEntry_H
70 #define ifeqEntry_H
71 
72 #include "functionEntry.H"
73 #include "DynamicList.H"
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 namespace Foam
78 {
79 namespace functionEntries
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class ifeqEntry Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class ifeqEntry
87 :
88  public functionEntry
89 {
90 
91 protected:
92 
94 
95  // Protected Member Functions
96 
97  //- Read tokens. Skip dummy tokens
98  static void readToken(token& t, Istream& is);
99 
100  //- Expand a variable (string/word/var starting with '$')
101  static token expand
102  (
103  const dictionary& dict,
104  const string& keyword,
105  const token& t
106  );
107 
108  //- Expand a string/word/var token
109  static token expand
110  (
111  const dictionary& dict,
112  const token& t
113  );
114 
115  static bool equalToken
116  (
117  const token& t1,
118  const token& t2
119  );
120 
121  //- Consume tokens until reached a specific word
122  static void skipUntil
123  (
124  DynamicList<filePos>& stack,
125  const dictionary& parentDict,
126  const word& endWord,
127  Istream& is
128  );
129 
130  static bool evaluate
131  (
132  const bool doIf,
133  DynamicList<filePos>& stack,
134  dictionary& parentDict,
135  Istream& is
136  );
137 
138  //- Main driver: depending on 'equal' starts evaluating or
139  // skips forward to #else
140  static bool execute
141  (
142  const bool equal,
143  DynamicList<filePos>& stack,
144  dictionary& parentDict,
145  Istream& is
146  );
147 
148  //- Main driver: depending on 'equal' starts evaluating or
149  // skips forward to #else
150  static bool execute
151  (
152  DynamicList<filePos>& stack,
153  dictionary& parentDict,
154  Istream& is
155  );
156 
157 
158 public:
159 
160  //- Runtime type information
161  ClassName("ifeq");
162 
163 
164  // Constructors
165 
166  //- Disallow default bitwise copy construction
167  ifeqEntry(const ifeqEntry&) = delete;
168 
169 
170  // Member Functions
171 
172  //- Execute the functionEntry in a sub-dict context
173  static bool execute(dictionary& parentDict, Istream& is);
174 
175 
176  // Member Operators
177 
178  //- Disallow default bitwise assignment
179  void operator=(const ifeqEntry&) = delete;
180 };
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace functionEntries
186 } // End namespace Foam
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #endif
191 
192 // ************************************************************************* //
const keyType & keyword() const
Return keyword.
Definition: entry.H:123
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
static bool equalToken(const token &t1, const token &t2)
Definition: ifeqEntry.C:143
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:69
static void skipUntil(DynamicList< filePos > &stack, const dictionary &parentDict, const word &endWord, Istream &is)
Consume tokens until reached a specific word.
Definition: ifeqEntry.C:259
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
A class for handling words, derived from string.
Definition: word.H:59
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:63
static token expand(const dictionary &dict, const string &keyword, const token &t)
Expand a variable (string/word/var starting with &#39;$&#39;)
Definition: ifeqEntry.C:74
ifeqEntry(const ifeqEntry &)=delete
Disallow default bitwise copy construction.
const dictionary & dict() const
This entry is not a dictionary,.
Conditional parsing of dictionary entries.
Definition: ifeqEntry.H:85
void operator=(const ifeqEntry &)=delete
Disallow default bitwise assignment.
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
static bool evaluate(const bool doIf, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Definition: ifeqEntry.C:291
ClassName("ifeq")
Runtime type information.
static void readToken(token &t, Istream &is)
Read tokens. Skip dummy tokens.
Definition: ifeqEntry.C:54
static bool execute(const bool equal, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Main driver: depending on &#39;equal&#39; starts evaluating or.
Definition: ifeqEntry.C:345
Tuple2< fileName, label > filePos
Definition: ifeqEntry.H:92
Namespace for OpenFOAM.