IOobjectTemplates.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "IOobject.H"
30 #include "fileOperation.H"
31 #include "Istream.H"
32 #include "IOstreams.H"
33 #include "Pstream.H"
34 
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 
37 template<class Type>
39 (
40  const bool checkType,
41  const bool search,
42  const bool verbose
43 )
44 {
45  bool ok = true;
46 
47  // Everyone check or just master
48  bool masterOnly =
49  typeGlobal<Type>()
50  && (
51  IOobject::fileModificationChecking == timeStampMaster
52  || IOobject::fileModificationChecking == inotifyMaster
53  );
54 
55  const fileOperation& fp = Foam::fileHandler();
56 
57  // Determine local status
58  if (!masterOnly || Pstream::master())
59  {
60  fileName fName(typeFilePath<Type>(*this, search));
61 
62  ok = fp.readHeader(*this, fName, Type::typeName);
63  if (ok && checkType && headerClassName_ != Type::typeName)
64  {
65  if (verbose)
66  {
68  << "unexpected class name " << headerClassName_
69  << " expected " << Type::typeName
70  << " when reading " << fName << endl;
71  }
72 
73  ok = false;
74  }
75  }
76 
77  // If masterOnly make sure all processors know about it
78  if (masterOnly)
79  {
80  Pstream::scatter(ok);
81  }
82 
83  return ok;
84 }
85 
86 
87 template<class Type>
89 {
91  {
93  << Type::typeName << ' ' << name()
94  << " constructed with IOobject::MUST_READ_IF_MODIFIED but "
95  << Type::typeName << " does not support automatic rereading."
96  << endl;
97  }
98 }
99 
100 
101 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::fileOperation
An encapsulation of filesystem-related operations.
Definition: fileOperation.H:68
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::IOobject::typeHeaderOk
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
Definition: IOobjectTemplates.C:39
Foam::fileHandler
const fileOperation & fileHandler()
Get current file handler.
Definition: fileOperation.C:1485
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fileOperation::readHeader
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const =0
Read object header from supplied file.
Foam::IOobject::warnNoRereading
void warnNoRereading() const
Helper: warn that type does not support re-reading.
Definition: IOobjectTemplates.C:88
Istream.H
IOobject.H
fileOperation.H
Pstream.H
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
Foam::search
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:571
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328