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-2019 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  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 bool Foam::functionEntries::ifEntry::execute
52 (
53  DynamicList<filePos>& stack,
54  dictionary& parentDict,
55  Istream& is
56 )
57 {
58  const label nNested = stack.size();
59 
60  stack.append(filePos(is.name(), is.lineNumber()));
61 
62  // Read line
63  string line;
64  dynamic_cast<ISstream&>(is).getLine(line);
65  line += ';';
66  IStringStream lineStream(line);
67  const primitiveEntry e("ifEntry", parentDict, lineStream);
68  const Switch doIf(e.stream());
69 
70  // Info<< "Using #" << typeName << " " << doIf
71  // << " at line " << stack.last().second()
72  // << " in file " << stack.last().first() << endl;
73 
74  bool ok = ifeqEntry::execute(doIf, stack, parentDict, is);
75 
76  if (stack.size() != nNested)
77  {
78  FatalIOErrorInFunction(parentDict)
79  << "Did not find matching #endif for condition starting"
80  << " at line " << stack.last().second()
81  << " in file " << stack.last().first() << exit(FatalIOError);
82  }
83 
84  return ok;
85 }
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
90 bool Foam::functionEntries::ifEntry::execute
91 (
92  dictionary& parentDict,
93  Istream& is
94 )
95 {
96  DynamicList<filePos> stack(10);
97  return execute(stack, parentDict, is);
98 }
99 
100 
101 // ************************************************************************* //
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
addToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
#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:105
defineTypeNameAndDebug(calcEntry, 0)
Namespace for OpenFOAM.
IOerror FatalIOError