ifEntry.H
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-2025 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 Class
25  Foam::functionEntries::ifEntry
26 
27 Description
28  Conditional parsing of and within dictionary entries.
29 
30  E.g.
31  \verbatim
32  Uinlet 15;
33 
34  #if (#calc "${Uinlet} < 10")
35  ..
36  #else
37  ..
38  #endif
39 
40  pOutlet #if (#calc "${Uinlet} < 10") 0 #else 100 #endif;
41 
42  fluid waterAndSludge;
43 
44  #if (#calc #{$fluid == "waterAndSludge" || $fluid == "waterAndSand" #})
45  mixture multicomponentMixture;
46  #else
47  mixture pureMixture;
48  #endif
49  \endverbatim
50 
51  The condition should return any boolean representation supported by
52  \c Switch i.e 0, 1, true, false, on, off, yes, no.
53 
54 See also
55  Foam::functionEntries::ifeqEntry
56  Foam::functionEntries::elseEntry
57  Foam::functionEntries::endifEntry
58  Foam::Switch
59 
60 SourceFiles
61  ifEntry.C
62 
63 \*---------------------------------------------------------------------------*/
64 
65 #ifndef ifEntry_H
66 #define ifEntry_H
67 
68 #include "ifeqEntry.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 namespace functionEntries
75 {
76 
77 /*---------------------------------------------------------------------------*\
78  Class ifEntry Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 class ifEntry
82 :
83  public ifeqEntry
84 {
85  friend class ifeqEntry;
86 
87  // Private Member Functions
88 
89  //- Execute the functionEntry in the given context
90  template<class Context>
91  bool execute
92  (
93  DynamicList<filePos>& stack,
94  const dictionary& contextDict,
95  Context& context,
96  Istream& is
97  ) const;
98 
99 
100 public:
101 
102  //- Runtime type information
103  FunctionTypeName("#if");
104 
105 
106  // Constructors
107 
108  //- Construct from line number, dictionary and Istream
109  ifEntry
110  (
111  const label lineNumber,
112  const dictionary& parentDict,
113  Istream& is
114  );
115 
116  //- Copy construct
117  ifEntry(const ifEntry&) = default;
118 
119  //- Clone
120  virtual autoPtr<entry> clone(const dictionary&) const
121  {
122  return autoPtr<entry>(new ifEntry(*this));
123  }
124 
125 
126  // Member Functions
127 
128  //- Expand the functionEntry into the contextDict
129  virtual bool execute(dictionary& contextDict, Istream& is);
130 
131  //- Expand the functionEntry into the contextEntry
132  static bool execute
133  (
134  const dictionary& contextDict,
135  primitiveEntry& contextEntry,
136  Istream&
137  );
138 
139 
140  // Member Operators
141 
142  //- Disallow default bitwise assignment
143  void operator=(const ifEntry&) = delete;
144 };
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 } // End namespace functionEntries
150 } // End namespace Foam
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 #ifdef NoRepository
155  #include "ifEntryTemplates.C"
156  #include "ifeqEntryTemplates.C"
157 #endif
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
label lineNumber() const
Return current stream line number.
Definition: IOstream.H:450
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:56
Conditional parsing of and within dictionary entries.
Definition: ifEntry.H:83
ifEntry(const label lineNumber, const dictionary &parentDict, Istream &is)
Construct from line number, dictionary and Istream.
Definition: ifEntry.C:53
void operator=(const ifEntry &)=delete
Disallow default bitwise assignment.
FunctionTypeName("#if")
Runtime type information.
Conditional parsing of and within dictionary entries.
Definition: ifeqEntry.H:89
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
Namespace for OpenFOAM.
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