includeIfPresentEntry.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) 2011-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 "includeIfPresentEntry.H"
27 #include "dictionary.H"
28 #include "IFstream.H"
30 #include "fileOperation.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 const Foam::word Foam::functionEntries::includeIfPresentEntry::typeName
35 (
36  Foam::functionEntries::includeIfPresentEntry::typeName_()
37 );
38 
39 // Don't lookup the debug switch here as the debug switch dictionary
40 // might include includeIfPresentEntry
41 int Foam::functionEntries::includeIfPresentEntry::debug(0);
42 
43 namespace Foam
44 {
45 namespace functionEntries
46 {
48  (
51  execute,
52  dictionaryIstream
53  );
54 
56  (
59  execute,
60  primitiveEntryIstream
61  );
62 }
63 }
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
68 (
69  dictionary& parentDict,
70  Istream& is
71 )
72 {
73  const fileName fName(includeFileName(is, parentDict));
74  autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
75  ISstream& ifs = ifsPtr();
76 
77  if (ifs)
78  {
80  {
81  Info<< fName << endl;
82  }
83  parentDict.read(ifs);
84  }
85 
86  return true;
87 }
88 
89 
91 (
92  const dictionary& parentDict,
94  Istream& is
95 )
96 {
97  const fileName fName(includeFileName(is, parentDict));
98  autoPtr<ISstream> ifsPtr(fileHandler().NewIFstream(fName));
99  ISstream& ifs = ifsPtr();
100 
101  if (ifs)
102  {
104  {
105  Info<< fName << endl;
106  }
107  entry.read(parentDict, ifs);
108  }
109 
110  return true;
111 }
112 
113 // ************************************************************************* //
Macros for easy insertion into member function selection tables.
Generic input stream.
Definition: ISstream.H:55
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
bool read(Istream &, const bool keepHeader=false)
Read dictionary from Istream, optionally keeping the header.
Definition: dictionaryIO.C:108
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
A class for handling file names.
Definition: fileName.H:82
static fileName includeFileName(Istream &, const dictionary &)
Read the include fileName from Istream, expand and return.
Definition: includeEntry.C:73
static bool log
Report which file is included to stdout.
Definition: includeEntry.H:88
Specify a file to include if it exists. Expects a single string to follow.
static bool execute(dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
A class for handling words, derived from string.
Definition: word.H:62
addToMemberFunctionSelectionTable(functionEntry, includeFvConstraintEntry, execute, dictionaryIstream)
Namespace for OpenFOAM.
const fileOperation & fileHandler()
Get current file handler.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info