1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "regIOobject.H"
28 #include "objectRegistry.H"
29 #include "PstreamReduceOps.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 Foam::Istream& Foam::regIOobject::readStream()
38 Info<< "regIOobject::readStream() : "
39 << "reading object " << name()
40 << " from file " << objectPath()
44 if (readOpt() == NO_READ)
46 FatalErrorIn("regIOobject::readStream()")
47 << "NO_READ specified for read-constructor of object " << name()
48 << " of class " << headerClassName()
52 // Construct object stream and read header if not already constructed
55 if (!(isPtr_ = objectStream()))
59 "regIOobject::readStream()",
64 ) << "cannot open file"
65 << exit(FatalIOError);
67 else if (!readHeader(*isPtr_))
69 FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
70 << "problem while reading header for object " << name()
71 << exit(FatalIOError);
77 lastModified_ = lastModified(filePath());
84 Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
88 Info<< "regIOobject::readStream(const word&) : "
89 << "reading object " << name()
90 << " from file " << objectPath()
94 // Construct IFstream if not already constructed
99 // Check the className of the regIOobject
100 // dictionary is an allowable name in case the actual class
101 // instantiated is a dictionary
105 && headerClassName() != expectName
106 && headerClassName() != "dictionary"
109 FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
110 << "unexpected class name " << headerClassName()
111 << " expected " << expectName << endl
112 << " while reading object " << name()
113 << exit(FatalIOError);
121 void Foam::regIOobject::close()
125 Info<< "regIOobject::close() : "
126 << "finished reading " << filePath()
138 bool Foam::regIOobject::readData(Istream&)
144 bool Foam::regIOobject::read()
146 bool ok = readData(readStream(type()));
152 bool Foam::regIOobject::modified() const
157 && lastModified(filePath()) > (lastModified_ + fileModificationSkew())
162 bool Foam::regIOobject::readIfModified()
166 time_t newTimeStamp = lastModified(filePath());
168 bool readFile = false;
170 if (newTimeStamp > (lastModified_ + fileModificationSkew()))
175 if (Pstream::parRun())
177 bool readFileOnThisProc = readFile;
178 reduce(readFile, andOp<bool>());
180 if (readFileOnThisProc && !readFile)
182 WarningIn("regIOobject::readIfModified()")
183 << "Delaying reading " << name()
184 << " of class " << headerClassName()
185 << " due to inconsistent "
186 "file time-stamps between processors"
193 lastModified_ = newTimeStamp;
194 Info<< "regIOobject::readIfModified() : " << nl
195 << " Reading object " << name()
196 << " from file " << filePath() << endl;
211 // ************************************************************************* //