Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "regIOobject.H"
00027 #include <OpenFOAM/IFstream.H>
00028 #include <OpenFOAM/Time.H>
00029 #include <OpenFOAM/PstreamReduceOps.H>
00030
00031
00032
00033
00034 Foam::Istream& Foam::regIOobject::readStream()
00035 {
00036 if (IFstream::debug)
00037 {
00038 Info<< "regIOobject::readStream() : "
00039 << "reading object " << name()
00040 << " from file " << objectPath()
00041 << endl;
00042 }
00043
00044 if (readOpt() == NO_READ)
00045 {
00046 FatalErrorIn("regIOobject::readStream()")
00047 << "NO_READ specified for read-constructor of object " << name()
00048 << " of class " << headerClassName()
00049 << abort(FatalError);
00050 }
00051
00052
00053 if (!isPtr_)
00054 {
00055 if (!(isPtr_ = objectStream()))
00056 {
00057 FatalIOError
00058 (
00059 "regIOobject::readStream()",
00060 __FILE__,
00061 __LINE__,
00062 objectPath(),
00063 0
00064 ) << "cannot open file"
00065 << exit(FatalIOError);
00066 }
00067 else if (!readHeader(*isPtr_))
00068 {
00069 FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
00070 << "problem while reading header for object " << name()
00071 << exit(FatalIOError);
00072 }
00073 }
00074
00075 if (!lastModified_)
00076 {
00077 lastModified_ = lastModified(filePath());
00078 }
00079
00080 return *isPtr_;
00081 }
00082
00083
00084 Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
00085 {
00086 if (IFstream::debug)
00087 {
00088 Info<< "regIOobject::readStream(const word&) : "
00089 << "reading object " << name()
00090 << " from file " << objectPath()
00091 << endl;
00092 }
00093
00094
00095 if (!isPtr_)
00096 {
00097 readStream();
00098
00099
00100
00101
00102 if
00103 (
00104 expectName.size()
00105 && headerClassName() != expectName
00106 && headerClassName() != "dictionary"
00107 )
00108 {
00109 FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
00110 << "unexpected class name " << headerClassName()
00111 << " expected " << expectName << endl
00112 << " while reading object " << name()
00113 << exit(FatalIOError);
00114 }
00115 }
00116
00117 return *isPtr_;
00118 }
00119
00120
00121 void Foam::regIOobject::close()
00122 {
00123 if (IFstream::debug)
00124 {
00125 Info<< "regIOobject::close() : "
00126 << "finished reading " << filePath()
00127 << endl;
00128 }
00129
00130 if (isPtr_)
00131 {
00132 delete isPtr_;
00133 isPtr_ = NULL;
00134 }
00135 }
00136
00137
00138 bool Foam::regIOobject::readData(Istream&)
00139 {
00140 return false;
00141 }
00142
00143
00144 bool Foam::regIOobject::read()
00145 {
00146 bool ok = readData(readStream(type()));
00147 close();
00148 return ok;
00149 }
00150
00151
00152 bool Foam::regIOobject::modified() const
00153 {
00154 return
00155 (
00156 lastModified_
00157 && lastModified(filePath()) > (lastModified_ + fileModificationSkew)
00158 );
00159 }
00160
00161
00162 bool Foam::regIOobject::readIfModified()
00163 {
00164 if (lastModified_)
00165 {
00166 time_t newTimeStamp = lastModified(filePath());
00167
00168 bool readFile = false;
00169
00170 if (newTimeStamp > (lastModified_ + fileModificationSkew))
00171 {
00172 readFile = true;
00173 }
00174
00175 if (Pstream::parRun())
00176 {
00177 bool readFileOnThisProc = readFile;
00178 reduce(readFile, andOp<bool>());
00179
00180 if (readFileOnThisProc && !readFile)
00181 {
00182 WarningIn("regIOobject::readIfModified()")
00183 << "Delaying reading " << name()
00184 << " of class " << headerClassName()
00185 << " due to inconsistent "
00186 "file time-stamps between processors"
00187 << endl;
00188 }
00189 }
00190
00191 if (readFile)
00192 {
00193 lastModified_ = newTimeStamp;
00194 Info<< "regIOobject::readIfModified() : " << nl
00195 << " Reading object " << name()
00196 << " from file " << filePath() << endl;
00197 return read();
00198 }
00199 else
00200 {
00201 return false;
00202 }
00203 }
00204 else
00205 {
00206 return false;
00207 }
00208 }
00209
00210
00211