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-2015 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  {
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  {
109  << "Dictionary " << name()
110  << " constructed with IOobject::MUST_READ"
111  " instead of IOobject::MUST_READ_IF_MODIFIED." << nl
112  << "Use MUST_READ_IF_MODIFIED if you need automatic rereading."
113  << endl;
114  }
115 
116  // Everyone check or just master
117  bool masterOnly =
120 
121 
122  // Check if header is ok for READ_IF_PRESENT
123  bool isHeaderOk = false;
125  {
126  if (masterOnly)
127  {
128  if (Pstream::master())
129  {
130  isHeaderOk = headerOk();
131  }
132  Pstream::scatter(isHeaderOk);
133  }
134  else
135  {
136  isHeaderOk = headerOk();
137  }
138  }
139 
140 
141  if
142  (
143  (
146  )
147  || isHeaderOk
148  )
149  {
150  readFile(masterOnly);
151  }
152  else
153  {
154  dictionary::operator=(dict);
155  }
156 
158 }
159 
160 
162 :
163  regIOobject(io)
164 {
166  // Note that we do construct the dictionary null and read in afterwards
167  // so that if there is some fancy massaging due to a functionEntry in
168  // the dictionary at least the type information is already complete.
169  is >> *this;
170 }
171 
172 
173 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
174 
176 {}
177 
178 
179 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
180 
182 {
183  return regIOobject::name();
184 }
185 
186 
187 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
188 
190 {
192 }
193 
194 
195 // ************************************************************************* //
dictionary dict
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:363
void operator=(const dictionary &)
Definition: dictionary.C:1094
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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:253
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:411
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:103
int infoSwitch(const char *name, const int defaultValue=0)
Lookup info switch or add default value.
Definition: debug.C:175
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
static fileCheckTypes fileModificationChecking
Definition: regIOobject.H:128
void operator=(const IOdictionary &)
Assignment of other IOdictionary&#39;s entries to this IOdictionary.
Definition: IOdictionary.C:189
A class for handling words, derived from string.
Definition: word.H:59
virtual ~IOdictionary()
Destructor.
Definition: IOdictionary.C:175
const word & name() const
Name function is needed to disambiguate those inherited.
Definition: IOdictionary.C:181
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
static const char nl
Definition: Ostream.H:262
defineTypeNameAndDebug(combustionModel, 0)
IOdictionary(const IOobject &)
Construct given an IOobject.
Definition: IOdictionary.C:45
#define WarningInFunction
Report a warning using Foam::Warning.
readOption readOpt() const
Definition: IOobject.H:304
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
bool headerOk()
Read and check header info.
Definition: IOobject.C:400
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const word & name() const
Return name.
Definition: IOobject.H:260
Namespace for OpenFOAM.