ifEntry.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ifEntry.H"
27 #include "Switch.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionEntries
35 {
36  defineTypeNameAndDebug(ifEntry, 0);
37 
39  (
40  functionEntry,
41  ifEntry,
42  execute,
43  dictionaryIstream,
44  if
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
52 bool Foam::functionEntries::ifEntry::execute
53 (
54  DynamicList<filePos>& stack,
55  dictionary& parentDict,
56  Istream& is
57 )
58 {
59  const label nNested = stack.size();
60 
61  stack.append(filePos(is.name(), is.lineNumber()));
62 
63  // Read line
64  string line;
65  dynamic_cast<ISstream&>(is).getLine(line);
66  line += ';';
67  IStringStream lineStream(line);
68  const primitiveEntry e("ifEntry", parentDict, lineStream);
69  const Switch doIf(e.stream());
70 
71  // Info<< "Using #" << typeName << " " << doIf
72  // << " at line " << stack.last().second()
73  // << " in file " << stack.last().first() << endl;
74 
75  bool ok = ifeqEntry::execute(doIf, stack, parentDict, is);
76 
77  if (stack.size() != nNested)
78  {
79  FatalIOErrorInFunction(parentDict)
80  << "Did not find matching #endif for condition starting"
81  << " at line " << stack.last().second()
82  << " in file " << stack.last().first() << exit(FatalIOError);
83  }
84 
85  return ok;
86 }
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
91 bool Foam::functionEntries::ifEntry::execute
92 (
93  dictionary& parentDict,
94  Istream& is
95 )
96 {
97  DynamicList<filePos> stack(10);
98  return execute(stack, parentDict, is);
99 }
100 
101 
102 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
addNamedToMemberFunctionSelectionTable(functionEntry, ifEntry, execute, dictionaryIstream, if)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Macros for easy insertion into member function selection tables.
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:98
static bool execute(const bool equal, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Main driver: depending on &#39;equal&#39; starts evaluating or.
Definition: ifeqEntry.C:345
defineTypeNameAndDebug(calcEntry, 0)
Namespace for OpenFOAM.
IOerror FatalIOError