All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IOobjectTemplates.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) 2015-2018 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 "IOobject.H"
27 #include "fileOperation.H"
28 #include "Istream.H"
29 #include "IOstreams.H"
30 #include "Pstream.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Type>
35 bool Foam::IOobject::typeHeaderOk(const bool checkType)
36 {
37  bool ok = true;
38 
39  // Everyone check or just master
40  bool masterOnly =
41  typeGlobal<Type>()
42  && (
45  );
46 
47  const fileOperation& fp = Foam::fileHandler();
48 
49  // Determine local status
50  if (!masterOnly || Pstream::master())
51  {
52  fileName fName(typeFilePath<Type>(*this));
53 
54  ok = fp.readHeader(*this, fName, Type::typeName);
55  if (ok && checkType && headerClassName_ != Type::typeName)
56  {
58  << "unexpected class name " << headerClassName_
59  << " expected " << Type::typeName
60  << " when reading " << fName << endl;
61 
62  ok = false;
63  }
64  }
65 
66  // If masterOnly make sure all processors know about it
67  if (masterOnly)
68  {
69  Pstream::scatter(ok);
70  }
71 
72  return ok;
73 }
74 
75 
76 template<class Type>
78 {
80  {
82  << Type::typeName << ' ' << name()
83  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
84  " but " << Type::typeName
85  << " does not support automatic rereading."
86  << endl;
87  }
88 }
89 
90 
91 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:303
bool typeHeaderOk(const bool checkType=true)
Read header (uses typeFilePath to find file) and check header.
A class for handling file names.
Definition: fileName.H:79
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
const fileOperation & fileHandler()
Get current file handler.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Definition: IOobject.H:219
#define WarningInFunction
Report a warning using Foam::Warning.
readOption readOpt() const
Definition: IOobject.H:353
void warnNoRereading() const
Helper: warn that type does not support re-reading.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const =0
Read object header from supplied file.