IOdictionary.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) 2011-2012 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 "IOdictionary.H"
27 #include "objectRegistry.H"
28 #include "Pstream.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 defineTypeNameAndDebug(IOdictionary, 0);
35 
36 bool IOdictionary::writeDictionaries
37 (
38  debug::infoSwitch("writeDictionaries", 0)
39 );
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
46 :
47  regIOobject(io)
48 {
49  // Temporary warning
50  if (debug && io.readOpt() == IOobject::MUST_READ)
51  {
52  WarningIn("IOdictionary::IOdictionary(const IOobject&)")
53  << "Dictionary " << name()
54  << " constructed with IOobject::MUST_READ"
55  " instead of IOobject::MUST_READ_IF_MODIFIED." << nl
56  << "Use MUST_READ_IF_MODIFIED if you need automatic rereading."
57  << endl;
58  }
59 
60  // Everyone check or just master
61  bool masterOnly =
64 
65 
66  // Check if header is ok for READ_IF_PRESENT
67  bool isHeaderOk = false;
69  {
70  if (masterOnly)
71  {
72  if (Pstream::master())
73  {
74  isHeaderOk = headerOk();
75  }
76  Pstream::scatter(isHeaderOk);
77  }
78  else
79  {
80  isHeaderOk = headerOk();
81  }
82  }
83 
84 
85  if
86  (
87  (
90  )
91  || isHeaderOk
92  )
93  {
94  readFile(masterOnly);
95  }
96 
98 }
99 
100 
102 :
103  regIOobject(io)
104 {
105  // Temporary warning
106  if (debug && io.readOpt() == IOobject::MUST_READ)
107  {
108  WarningIn
109  (
110  "IOdictionary::IOdictionary(const IOobject& const dictionary&)"
111  ) << "Dictionary " << name()
112  << " constructed with IOobject::MUST_READ"
113  " instead of IOobject::MUST_READ_IF_MODIFIED." << nl
114  << "Use MUST_READ_IF_MODIFIED if you need automatic rereading."
115  << endl;
116  }
117 
118  // Everyone check or just master
119  bool masterOnly =
122 
123 
124  // Check if header is ok for READ_IF_PRESENT
125  bool isHeaderOk = false;
127  {
128  if (masterOnly)
129  {
130  if (Pstream::master())
131  {
132  isHeaderOk = headerOk();
133  }
134  Pstream::scatter(isHeaderOk);
135  }
136  else
137  {
138  isHeaderOk = headerOk();
139  }
140  }
141 
142 
143  if
144  (
145  (
148  )
149  || isHeaderOk
150  )
151  {
152  readFile(masterOnly);
153  }
154  else
155  {
156  dictionary::operator=(dict);
157  }
158 
160 }
161 
162 
164 :
165  regIOobject(io)
166 {
168  // Note that we do construct the dictionary null and read in afterwards
169  // so that if there is some fancy massaging due to a functionEntry in
170  // the dictionary at least the type information is already complete.
171  is >> *this;
172 }
173 
174 
175 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
176 
178 {}
179 
180 
181 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
182 
184 {
185  return regIOobject::name();
186 }
187 
188 
189 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
190 
192 {
194 }
195 
196 
197 // ************************************************************************* //
int infoSwitch(const char *name, const int defaultValue=0)
Lookup info switch or add default value.
Definition: debug.C:174
readOption readOpt() const
Definition: IOobject.H:304
virtual ~IOdictionary()
Destructor.
Definition: IOdictionary.C:177
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:103
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word & name() const
Name function is needed to disambiguate those inherited.
Definition: IOdictionary.C:183
Namespace for OpenFOAM.
dictionary dict
static const char nl
Definition: Ostream.H:260
void operator=(const IOdictionary &)
Assignment of other IOdictionary&#39;s entries to this IOdictionary.
Definition: IOdictionary.C:191
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:363
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
const word & name() const
Return name.
Definition: IOobject.H:260
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
static fileCheckTypes fileModificationChecking
Definition: regIOobject.H:128
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:398
bool headerOk()
Read and check header info.
Definition: IOobject.C:424
void operator=(const dictionary &)
Definition: dictionary.C:1098
IOdictionary(const IOobject &)
Construct given an IOobject.
Definition: IOdictionary.C:45
defineTypeNameAndDebug(combustionModel, 0)