includeEntry.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::includeEntry
26 
27 Description
28  Specify an include file when reading dictionaries.
29 
30  The file name is provided as a string in order to support the '/' directory
31  separator and unusual characters as well as the usual expansion of
32  environment variables and other constructs
33  (eg, the \c ~OpenFOAM/ expansion).
34 
35  e.g. to include the file \c includeFile from the \c include directory:
36  \verbatim
37  #include "include/includeFile"
38  \endverbatim
39 
40  Additionally optional arguments may be specified which are available for
41  substitution in the included file e.g.
42  \verbatim
43  #include "regionFunctions"(region = heatedWall)
44  \endverbatim
45 
46  will substitute \c heatedWall for \c $region in the \c regionFunctions file
47 
48  \verbatim
49  #includeFunc sample(region = $region)
50  \endverbatim
51 
52 See also
53  fileName
54 
55 SourceFiles
56  includeEntry.C
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #ifndef includeEntry_H
61 #define includeEntry_H
62 
63 #include "functionEntry.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 namespace functionEntries
70 {
71 
72 /*---------------------------------------------------------------------------*\
73  Class includeEntry Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 class includeEntry
77 :
78  public functionEntry
79 {
80  // Private Member Functions
81 
82  //- Return the optional named arguments
83  // temporarily inserted into contextDict
84  List<Tuple3<word, string, label>> insertNamedArgs
85  (
86  dictionary& contextDict,
88  ) const;
89 
90  //- Remove named argument entries from contextDict
91  // renaming any existing entries which had the same name
92  void removeInsertNamedArgs
93  (
94  dictionary& contextDict,
95  const List<Tuple3<word, string, label>>& namedArgs
96  ) const;
97 
98 
99 
100 protected:
101 
102  // Protected Member Functions
103 
104  //- Return the file name
105  const string& fName() const
106  {
107  return operator[](0).stringToken();
108  }
109 
110  //- Return the arguments string for processing by insertNamedArgs
112  {
113  if (size() > 1)
114  {
115  return Tuple2<string, label>
116  (
117  char(operator[](1).pToken())
118  + operator[](2).stringToken()
119  + char(operator[](3).pToken()),
120  operator[](1).lineNumber()
121  );
122  }
123  else
124  {
126  }
127  }
128 
129  //- Return true if file presence is optional
130  virtual bool includeIfPresent() const
131  {
132  return false;
133  }
134 
135  //- Expand include fileName and return
136  virtual fileName includeFileName
137  (
138  const fileName& dir,
139  const fileName&,
140  const dictionary&
141  ) const;
142 
143  //- Expand the functionEntry into the contextEntry
144  virtual bool virtualExecute
145  (
146  const dictionary& contextDict,
147  primitiveEntry& contextEntry,
148  Istream&
149  );
150 
151 
152 public:
153 
154  // Static Data Members
155 
156  //- Report which file is included to stdout
157  static bool log;
158 
159  //- Runtime type information
160  FunctionTypeName("#include");
161 
162 
163  // Constructors
164 
165  //- Construct from functionType, dictionary and Istream
167  (
168  const functionName& functionType,
169  const label lineNumber,
170  const dictionary& parentDict,
171  Istream& is
172  );
173 
174  //- Construct from line number, dictionary and Istream
176  (
177  const label lineNumber,
178  const dictionary& parentDict,
179  Istream& is
180  );
181 
182  //- Copy construct
183  includeEntry(const includeEntry&) = default;
184 
185  //- Clone
186  virtual autoPtr<entry> clone(const dictionary&) const
187  {
188  return autoPtr<entry>(new includeEntry(*this));
189  }
190 
191 
192  // Member Functions
193 
194  //- Expand the functionEntry into the contextDict
195  virtual bool execute(dictionary& contextDict, Istream&);
196 
197  //- Expand the functionEntry into the contextEntry
198  static bool execute
199  (
200  const dictionary& contextDict,
201  primitiveEntry& contextEntry,
202  Istream&
203  );
204 
205 
206  // Member Operators
207 
208  //- Disallow default bitwise assignment
209  void operator=(const includeEntry&) = delete;
210 };
211 
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 } // End namespace functionEntries
216 } // End namespace Foam
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #endif
221 
222 // ************************************************************************* //
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
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
A 3-tuple for storing three objects of different types.
Definition: Tuple3.H:60
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
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
A class for handling file names.
Definition: fileName.H:82
Specify an include file when reading dictionaries.
Definition: includeEntry.H:78
virtual bool virtualExecute(const dictionary &contextDict, primitiveEntry &contextEntry, Istream &)
Expand the functionEntry into the contextEntry.
Definition: includeEntry.C:159
virtual bool includeIfPresent() const
Return true if file presence is optional.
Definition: includeEntry.H:129
const string & fName() const
Return the file name.
Definition: includeEntry.H:104
includeEntry(const functionName &functionType, const label lineNumber, const dictionary &parentDict, Istream &is)
Construct from functionType, dictionary and Istream.
Definition: includeEntry.C:228
virtual fileName includeFileName(const fileName &dir, const fileName &, const dictionary &) const
Expand include fileName and return.
Definition: includeEntry.C:134
Tuple2< string, label > args() const
Return the arguments string for processing by insertNamedArgs.
Definition: includeEntry.H:110
void operator=(const includeEntry &)=delete
Disallow default bitwise assignment.
virtual bool execute(dictionary &contextDict, Istream &)
Expand the functionEntry into the contextDict.
Definition: includeEntry.C:260
FunctionTypeName("#include")
Runtime type information.
static bool log
Report which file is included to stdout.
Definition: includeEntry.H:156
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A functionName is a word starting with '#'.
Definition: functionName.H:60
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
static const string null
An empty string.
Definition: string.H:88
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