Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / db / regIOobject / regIOobjectRead.C
blobec6cca4df1c5857a31d9b855a159cc969c027412
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
27 #include "IFstream.H"
28 #include "objectRegistry.H"
29 #include "PstreamReduceOps.H"
32 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
34 Foam::Istream& Foam::regIOobject::readStream()
36     if (IFstream::debug)
37     {
38         Info<< "regIOobject::readStream() : "
39             << "reading object " << name()
40             << " from file " << objectPath()
41             << endl;
42     }
44     if (readOpt() == NO_READ)
45     {
46         FatalErrorIn("regIOobject::readStream()")
47             << "NO_READ specified for read-constructor of object " << name()
48             << " of class " << headerClassName()
49             << abort(FatalError);
50     }
52     // Construct object stream and read header if not already constructed
53     if (!isPtr_)
54     {
55         if (!(isPtr_ = objectStream()))
56         {
57             FatalIOError
58             (
59                 "regIOobject::readStream()",
60                 __FILE__,
61                 __LINE__,
62                 objectPath(),
63                 0
64             )   << "cannot open file"
65                 << exit(FatalIOError);
66         }
67         else if (!readHeader(*isPtr_))
68         {
69             FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
70                 << "problem while reading header for object " << name()
71                 << exit(FatalIOError);
72         }
73     }
75     if (!lastModified_)
76     {
77         lastModified_ = lastModified(filePath());
78     }
80     return *isPtr_;
84 Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
86     if (IFstream::debug)
87     {
88         Info<< "regIOobject::readStream(const word&) : "
89             << "reading object " << name()
90             << " from file " << objectPath()
91             << endl;
92     }
94     // Construct IFstream if not already constructed
95     if (!isPtr_)
96     {
97         readStream();
99         // Check the className of the regIOobject
100         // dictionary is an allowable name in case the actual class
101         // instantiated is a dictionary
102         if
103         (
104             expectName.size()
105          && headerClassName() != expectName
106          && headerClassName() != "dictionary"
107         )
108         {
109             FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
110                 << "unexpected class name " << headerClassName()
111                 << " expected " << expectName << endl
112                 << "    while reading object " << name()
113                 << exit(FatalIOError);
114         }
115     }
117     return *isPtr_;
121 void Foam::regIOobject::close()
123     if (IFstream::debug)
124     {
125         Info<< "regIOobject::close() : "
126             << "finished reading " << filePath()
127             << endl;
128     }
130     if (isPtr_)
131     {
132         delete isPtr_;
133         isPtr_ = NULL;
134     }
138 bool Foam::regIOobject::readData(Istream&)
140     return false;
144 bool Foam::regIOobject::read()
146     bool ok = readData(readStream(type()));
147     close();
148     return ok;
152 bool Foam::regIOobject::modified() const
154     return
155     (
156         lastModified_
157      && lastModified(filePath()) > (lastModified_ + fileModificationSkew())
158     );
162 bool Foam::regIOobject::readIfModified()
164     if (lastModified_)
165     {
166         time_t newTimeStamp = lastModified(filePath());
168         bool readFile = false;
170         if (newTimeStamp > (lastModified_ + fileModificationSkew()))
171         {
172             readFile = true;
173         }
175         if (Pstream::parRun())
176         {
177             bool readFileOnThisProc = readFile;
178             reduce(readFile, andOp<bool>());
180             if (readFileOnThisProc && !readFile)
181             {
182                 WarningIn("regIOobject::readIfModified()")
183                     << "Delaying reading " << name()
184                     << " of class " << headerClassName()
185                     << " due to inconsistent "
186                        "file time-stamps between processors"
187                     << endl;
188             }
189         }
191         if (readFile)
192         {
193             lastModified_ = newTimeStamp;
194             Info<< "regIOobject::readIfModified() : " << nl
195                 << "    Reading object " << name()
196                 << " from file " << filePath() << endl;
197             return read();
198         }
199         else
200         {
201             return false;
202         }
203     }
204     else
205     {
206         return false;
207     }
211 // ************************************************************************* //