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 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"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
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.peekFirst().isScalar())
60 {
61 // Use default rounding tolerance
62 logic = Switch(its.first().scalarToken());
63 }
64 else
65 {
66 its >> logic;
67 }
68
69 return logic;
70}
71
72
73// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
74
76(
77 DynamicList<filePos>& stack,
78 dictionary& parentDict,
79 Istream& is
80)
81{
82 const label nNested = stack.size();
83
84 stack.append(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.last().second()
98 // << " in file " << stack.last().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.last().second()
107 << " in file " << stack.last().first() << exit(FatalIOError);
108 }
109
110 return ok;
111}
112
113
114// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115
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:72
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Conditional parsing of dictionary entries.
Definition: ifEntry.H:75
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:69
virtual bool execute()
Calculate the output fields.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Namespace for OpenFOAM.
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
volScalarField & e
Definition: createFields.H:11