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