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  (
49  functionEntry,
50  includeIfPresentEntry,
51  execute,
52  dictionaryIstream
53  );
54 
56  (
57  functionEntry,
58  includeIfPresentEntry,
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,
93  primitiveEntry& entry,
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 // ************************************************************************* //
static bool execute(dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
A class for handling file names.
Definition: fileName.H:79
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool read(Istream &, const bool keepHeader=false)
Read dictionary from Istream, optionally keeping the header.
Definition: dictionaryIO.C:104
addToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream)
A keyword and a list of tokens is a &#39;primitiveEntry&#39;. An primitiveEntry can be read, written and printed, and the types and values of its tokens analysed.
A class for handling words, derived from string.
Definition: word.H:59
const fileOperation & fileHandler()
Get current file handler.
Generic input stream.
Definition: ISstream.H:52
Macros for easy insertion into member function selection tables.
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual bool read(const dictionary &, Istream &)
Read tokens from the given stream.
static bool log
Report which file is included to stdout.
Definition: includeEntry.H:88
Namespace for OpenFOAM.