Loading...
Searching...
No Matches
ifEntry.C
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) 2019-2022 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
27\*---------------------------------------------------------------------------*/
28
29#include "ifEntry.H"
30#include "Switch.H"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35namespace Foam
36{
37namespace functionEntries
38{
40
42 (
44 ifEntry,
45 execute,
46 dictionaryIstream,
47 if
48 );
49} // End namespace functionEntries
50} // End namespace Foam
51
52
53// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
54
55bool Foam::functionEntries::ifEntry::isTrue(ITstream& its)
56{
57 Switch logic;
58
59 if (its.front().isScalar())
60 {
61 // Use default rounding tolerance
62 logic = Switch(its.front().scalarToken());
63 }
64 else
65 {
66 its >> logic;
67 }
68
69 return logic;
70}
71
72
73// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
74
75bool Foam::functionEntries::ifEntry::execute
76(
77 DynamicList<filePos>& stack,
78 dictionary& parentDict,
79 Istream& is
80)
81{
82 const label nNested = stack.size();
83
84 stack.push_back(filePos(is.name(), is.lineNumber()));
85
86 // Read line
87 string line;
88 dynamic_cast<ISstream&>(is).getLine(line);
89 line += ';';
90
91 IStringStream lineStream(line);
92 const primitiveEntry e("ifEntry", parentDict, lineStream);
93
94 const bool doIf = ifEntry::isTrue(e.stream());
95
96 // Info<< "Using #" << typeName << " " << Switch::name(doIf)
97 // << " at line " << stack.back().second()
98 // << " in file " << stack.back().first() << endl;
99
100 const bool ok = ifeqEntry::execute(doIf, stack, parentDict, is);
101
102 if (stack.size() != nNested)
103 {
104 FatalIOErrorInFunction(parentDict)
105 << "Did not find matching #endif for condition starting"
106 << " at line " << stack.back().second()
107 << " in file " << stack.back().first() << exit(FatalIOError);
108 }
110 return ok;
111}
112
113
114// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115
116bool Foam::functionEntries::ifEntry::execute
117(
118 dictionary& parentDict,
119 Istream& is
120)
121{
122 DynamicList<filePos> stack(10);
123 return execute(stack, parentDict, is);
124}
125
126
127// ************************************************************************* //
Macros for easy insertion into member function selection tables.
#define addNamedToMemberFunctionSelectionTable(baseType, thisType, funcName, argNames, lookupName)
Add to hash-table of functions with 'lookupName' as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
An input stream of tokens.
Definition ITstream.H:56
const token & front() const noexcept
Failsafe peek at the token at the front of the tokenList.
Definition ITstream.H:364
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition Switch.H:81
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Conditional parsing of dictionary entries.
Definition ifEntry.H:71
static bool execute(const bool equal, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Main driver: depending on 'equal' starts evaluating or skips forward to else.
Definition ifeqEntry.C:407
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
bool isScalar() const noexcept
Token is FLOAT or DOUBLE.
Definition tokenI.H:971
scalar scalarToken() const
Return float or double value.
Definition tokenI.H:981
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
Namespace for containing a functionEntry.
Definition calcEntry.C:33
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
volScalarField & e