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 -------------------------------------------------------------------------------
11 License
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 
35 namespace Foam
36 {
37 namespace functionEntries
38 {
39  defineTypeNameAndDebug(ifEntry, 0);
40 
42  (
43  functionEntry,
44  ifEntry,
45  execute,
46  dictionaryIstream,
47  if
48  );
49 } // End namespace functionEntries
50 } // End namespace Foam
51 
52 
53 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
54 
55 bool 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 
75 bool 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  }
109 
110  return ok;
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
116 bool 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 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
defineTypeNameAndDebug(codeStream, 0)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Macros for easy insertion into member function selection tables.
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
static bool execute(const bool equal, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Main driver: depending on &#39;equal&#39; starts evaluating or skips forward to else.
Definition: ifeqEntry.C:340
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...