calcIncludeEntry.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) 2023 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 "calcIncludeEntry.H"
27 #include "dictionary.H"
28 #include "IFstream.H"
30 #include "stringOps.H"
31 #include "IOobject.H"
32 #include "fileOperation.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionEntries
39 {
41 
43  (
46  execute,
47  dictionaryIstream
48  );
49 }
50 }
51 
52 // Construct the static include file name cache
54  Foam::functionEntries::calcIncludeEntry::includeFiles_;
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
59 (
60  dictionary& parentDict,
61  Istream& is
62 )
63 {
64  // Read the include file name
65  fileName fName(is);
66 
67  // Substitute dictionary and environment variables. Allow empty
68  // substitutions.
69  stringOps::inplaceExpandEntry(fName, parentDict, true, true);
70 
71  // Add the file name to the cache
72  includeFiles_.append(fName);
73 
74  return true;
75 }
76 
77 
79 {
80  includeFiles_.clear();
81 }
82 
83 
85 {
86  if (includeFiles_.size())
87  {
88  verbatimString codeInclude;
89  forAll(includeFiles_, i)
90  {
91  codeInclude += "#include \"" + includeFiles_[i] + '"' + '\n';
92  }
93 
94  codeDict.add("codeInclude", codeInclude);
95  }
96 }
97 
98 
99 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into member function selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1169
A class for handling file names.
Definition: fileName.H:82
Specify an include file for #calc, expects a single string to follow.
static bool execute(dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
static void codeInclude(dictionary &codeDict)
Add the cached include file names to the codeInclude entry.
static void clear()
Reset the cache of #calc include file names.
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A class for handling verbatimStrings, derived from string.
defineTypeNameAndDebug(includeFvConstraintEntry, 0)
addToMemberFunctionSelectionTable(functionEntry, includeFvConstraintEntry, execute, dictionaryIstream)
string & inplaceExpandEntry(string &s, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty, const char sigil='$')
Inplace expand occurrences of variables according to the dictionary.
Definition: stringOps.C:753
Namespace for OpenFOAM.