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 protected:
91 
93 
94 
95 private:
96 
97  // Private Member Functions
98 
99  //- Read tokens. Skip dummy tokens
100  static void readToken(token& t, Istream& is);
101 
102  //- Expand token if it is a variable
103  static token expand(const dictionary& dict, const token& t);
104 
105  static bool equalToken(const token& t1, const token& t2);
106 
107  //- Consume tokens until reached a specific word
108  static void skipUntil
109  (
110  DynamicList<filePos>& stack,
111  const dictionary& parentDict,
112  const functionName& endWord,
113  Istream& is
114  );
115 
116  static bool evaluate
117  (
118  const bool doIf,
119  DynamicList<filePos>& stack,
120  dictionary& parentDict,
121  Istream& is
122  );
123 
124  //- Main driver: depending on 'equal' starts evaluating or
125  // skips forward to #else
126  static bool execute
127  (
128  DynamicList<filePos>& stack,
129  dictionary& parentDict,
130  Istream& is
131  );
132 
133 
134 protected:
135 
136  // Protected Member Functions
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 
149 public:
150 
151  //- Runtime type information
152  ClassName("ifeq");
153 
154  // Function names for the individual elements of the conditional
155  static const functionName ifName;
156  static const functionName ifeqName;
157  static const functionName elifName;
158  static const functionName elseName;
159  static const functionName endifName;
160 
161 
162  // Constructors
163 
164  //- Disallow default bitwise copy construction
165  ifeqEntry(const ifeqEntry&) = delete;
166 
167 
168  // Member Functions
169 
170  //- Execute the functionEntry in a sub-dict context
171  static bool execute(dictionary& parentDict, Istream& is);
172 
173 
174  // Member Operators
175 
176  //- Disallow default bitwise assignment
177  void operator=(const ifeqEntry&) = delete;
178 };
179 
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 } // End namespace functionEntries
184 } // End namespace Foam
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 #endif
189 
190 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
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:72
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
A functionName is a word starting with &#39;#&#39;.
Definition: functionName.H:57
static const functionName endifName
Definition: ifeqEntry.H:158
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:63
static const functionName ifName
Definition: ifeqEntry.H:154
static const functionName ifeqName
Definition: ifeqEntry.H:155
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
static const functionName elifName
Definition: ifeqEntry.H:156
void operator=(const ifeqEntry &)=delete
Disallow default bitwise assignment.
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
ClassName("ifeq")
Runtime type information.
static const functionName elseName
Definition: ifeqEntry.H:157
Tuple2< fileName, label > filePos
Definition: ifeqEntry.H:91
Namespace for OpenFOAM.