includeIfPresentEntry.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) 2011-2026 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::includeIfPresentEntry
26 
27 Description
28  Specify a file to include if it exists. Expects a single string to follow.
29 
30  The \c \#includeIfPresent directive is similar to the \c \#include
31  directive, but does not generate an error if the file does not exist.
32 
33  Additionally optional arguments may be specified which are available for
34  substitution in the included file e.g.
35  \verbatim
36  #includeIfPresent "regionFunctions"(region = heatedWall)
37  \endverbatim
38 
39 See also
40  Foam::functionEntries::includeEntry
41 
42 SourceFiles
43  includeIfPresentEntry.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef includeIfPresentEntry_H
48 #define includeIfPresentEntry_H
49 
50 #include "includeEntry.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 namespace functionEntries
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class includeIfPresentEntry Declaration
61 \*---------------------------------------------------------------------------*/
62 
64 :
65  public includeEntry
66 {
67 protected:
68 
69  // Protected Member Functions
70 
71  //- Return true if file presence is optional
72  virtual bool includeIfPresent() const
73  {
74  return true;
75  }
76 
77 
78 public:
79 
80  //- Runtime type information
81  FunctionTypeName("#includeIfPresent");
82 
83 
84  // Constructors
85 
86  //- Construct from line number, dictionary and Istream
88  (
89  const label lineNumber,
90  const dictionary& parentDict,
91  Istream& is
92  );
93 
94  //- Copy construct
96 
97  //- Clone
98  virtual autoPtr<entry> clone(const dictionary&) const
99  {
100  return autoPtr<entry>(new includeIfPresentEntry(*this));
101  }
102 
103 
104  // Member Functions
105 
106  //- Expand the functionEntry into the contextDict
107  virtual bool execute(dictionary& contextDict, Istream&);
108 
109  //- Expand the functionEntry into the contextEntry
110  static bool execute
111  (
112  const dictionary& contextDict,
113  primitiveEntry& contextEntry,
114  Istream&
115  );
116 
117 
118  // Member Operators
119 
120  //- Disallow default bitwise assignment
121  void operator=(const includeIfPresentEntry&) = delete;
122 };
123 
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 } // End namespace functionEntries
128 } // End namespace Foam
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 #endif
133 
134 // ************************************************************************* //
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
Specify an include file when reading dictionaries.
Definition: includeEntry.H:78
Specify a file to include if it exists. Expects a single string to follow.
FunctionTypeName("#includeIfPresent")
Runtime type information.
virtual bool includeIfPresent() const
Return true if file presence is optional.
includeIfPresentEntry(const label lineNumber, const dictionary &parentDict, Istream &is)
Construct from line number, dictionary and Istream.
void operator=(const includeIfPresentEntry &)=delete
Disallow default bitwise assignment.
virtual bool execute(dictionary &contextDict, Istream &)
Expand the functionEntry into the contextDict.
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