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 -------------------------------------------------------------------------------
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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 
55 bool Foam::functionEntries::ifEntry::isTrue(ITstream& its)
56 {
57  Switch logic;
58 
59  if (its.size() && its.first().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 bool Foam::functionEntries::ifEntry::execute
74 (
75  DynamicList<filePos>& stack,
76  dictionary& parentDict,
77  Istream& is
78 )
79 {
80  const label nNested = stack.size();
81 
82  stack.append(filePos(is.name(), is.lineNumber()));
83 
84  // Read line
85  string line;
86  dynamic_cast<ISstream&>(is).getLine(line);
87  line += ';';
88 
89  IStringStream lineStream(line);
90  const primitiveEntry e("ifEntry", parentDict, lineStream);
91 
92  const bool doIf = ifEntry::isTrue(e.stream());
93 
94  // Info<< "Using #" << typeName << " " << Switch::name(doIf)
95  // << " at line " << stack.last().second()
96  // << " in file " << stack.last().first() << endl;
97 
98  const bool ok = ifeqEntry::execute(doIf, stack, parentDict, is);
99 
100  if (stack.size() != nNested)
101  {
102  FatalIOErrorInFunction(parentDict)
103  << "Did not find matching #endif for condition starting"
104  << " at line " << stack.last().second()
105  << " in file " << stack.last().first() << exit(FatalIOError);
106  }
107 
108  return ok;
109 }
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
114 bool Foam::functionEntries::ifEntry::execute
115 (
116  dictionary& parentDict,
117  Istream& is
118 )
119 {
120  DynamicList<filePos> stack(10);
121  return execute(stack, parentDict, is);
122 }
123 
124 
125 // ************************************************************************* //
Foam::functionEntries::ifeqEntry::execute
static bool execute(const bool equal, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Definition: ifeqEntry.C:330
ifEntry.H
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::functionEntries::defineTypeNameAndDebug
defineTypeNameAndDebug(codeStream, 0)
Foam::FatalIOError
IOerror FatalIOError
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
addToMemberFunctionSelectionTable.H
Macros for easy insertion into member function selection tables.
Switch.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionEntries::addNamedToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401