FreeFOAM The Cross-Platform CFD Toolkit
includeEntry.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 "includeEntry.H"
27 #include <OpenFOAM/dictionary.H>
28 #include <OpenFOAM/IFstream.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 const Foam::word Foam::functionEntries::includeEntry::typeName
34 (
35  Foam::functionEntries::includeEntry::typeName_()
36 );
37 
38 // Don't lookup the debug switch here as the debug switch dictionary
39 // might include includeEntry
40 int Foam::functionEntries::includeEntry::debug(0);
41 
42 namespace Foam
43 {
44 namespace functionEntries
45 {
47  (
48  functionEntry,
49  includeEntry,
50  execute,
51  dictionaryIstream
52  );
53 
55  (
56  functionEntry,
57  includeEntry,
58  execute,
59  primitiveEntryIstream
60  );
61 }
62 }
63 
64 // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
65 
67 (
68  Istream& is
69 )
70 {
71  fileName fName(is);
72  fName.expand();
73 
74  // relative name
75  if (fName.size() && fName[0] != '/')
76  {
77  fName = fileName(is.name()).path()/fName;
78  }
79 
80  return fName;
81 }
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
87 (
88  dictionary& parentDict,
89  Istream& is
90 )
91 {
92  IFstream ifs(includeFileName(is));
93 
94  if (ifs)
95  {
96  parentDict.read(ifs);
97  return true;
98  }
99  else
100  {
102  (
103  "functionEntries::includeEntry::includeEntry"
104  "(dictionary& parentDict, Istream&)",
105  is
106  ) << "Cannot open include file " << ifs.name()
107  << " while reading dictionary " << parentDict.name()
108  << exit(FatalIOError);
109 
110  return false;
111  }
112 }
113 
114 
116 (
117  const dictionary& parentDict,
119  Istream& is
120 )
121 {
122  IFstream ifs(includeFileName(is));
123 
124  if (ifs)
125  {
126  entry.read(parentDict, ifs);
127  return true;
128  }
129  else
130  {
132  (
133  "functionEntries::includeEntry::includeEntry"
134  "(dictionary& parentDict, primitiveEntry&, Istream&)",
135  is
136  ) << "Cannot open include file " << ifs.name()
137  << " while reading dictionary " << parentDict.name()
138  << exit(FatalIOError);
139 
140  return false;
141  }
142 }
143 
144 // ************************ vim: set sw=4 sts=4 et: ************************ //