1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "regIOobject.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::regIOobject, 0);
34 int Foam::regIOobject::fileModificationSkew
36 Foam::debug::optimisationSwitch("fileModificationSkew", 30)
42 const char* Foam::NamedEnum
44 Foam::regIOobject::fileCheckTypes,
56 const Foam::NamedEnum<Foam::regIOobject::fileCheckTypes, 4>
57 Foam::regIOobject::fileCheckTypesNames;
59 // Default fileCheck type
60 Foam::regIOobject::fileCheckTypes Foam::regIOobject::fileModificationChecking
62 fileCheckTypesNames.read
64 debug::optimisationSwitches().lookup
66 "fileModificationChecking"
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 // Construct from IOobject
75 Foam::regIOobject::regIOobject(const IOobject& io, const bool isTime)
79 ownedByRegistry_(false),
81 eventNo_ // Do not get event for top level Time database
89 // Register with objectRegistry if requested
98 Foam::regIOobject::regIOobject(const regIOobject& rio)
102 ownedByRegistry_(false),
103 watchIndex_(rio.watchIndex_),
104 eventNo_(db().getEvent()),
107 // Do not register copy with objectRegistry
111 // Construct as copy, and transfering objectRegistry registration to copy
112 // if registerCopy is true
113 Foam::regIOobject::regIOobject(const regIOobject& rio, bool registerCopy)
117 ownedByRegistry_(false),
119 eventNo_(db().getEvent()),
122 if (registerCopy && rio.registered_)
124 const_cast<regIOobject&>(rio).checkOut();
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 // Delete read stream, checkout from objectRegistry and destroy
133 Foam::regIOobject::~regIOobject()
135 if (objectRegistry::debug)
137 Info<< "Destroying regIOobject called " << name()
138 << " of type " << type()
139 << " in directory " << path()
149 // Check out of objectRegistry if not owned by the registry
151 if (!ownedByRegistry_)
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 bool Foam::regIOobject::checkIn()
164 // multiple checkin of same object is disallowed - this would mess up
166 registered_ = db().checkIn(*this);
171 && readOpt() == MUST_READ_IF_MODIFIED
172 && time().runTimeModifiable()
175 if (watchIndex_ != -1)
177 FatalErrorIn("regIOobject::checkIn()")
178 << "Object " << objectPath()
179 << " already watched with index " << watchIndex_
180 << abort(FatalError);
183 fileName f = filePath();
186 // We don't have this file but would like to re-read it.
187 // Possibly if master-only reading mode.
190 watchIndex_ = time().addWatch(f);
193 // check-in on defaultRegion is allowed to fail, since subsetted meshes
194 // are created with the same name as their originating mesh
195 if (!registered_ && debug && name() != polyMesh::defaultRegion)
199 // for ease of finding where attempted duplicate check-in
201 FatalErrorIn("regIOobject::checkIn()")
202 << "failed to register object " << objectPath()
203 << " the name already exists in the objectRegistry"
204 << abort(FatalError);
208 WarningIn("regIOobject::checkIn()")
209 << "failed to register object " << objectPath()
210 << " the name already exists in the objectRegistry"
220 bool Foam::regIOobject::checkOut()
226 if (watchIndex_ != -1)
228 time().removeWatch(watchIndex_);
231 return db().checkOut(*this);
238 bool Foam::regIOobject::upToDate(const regIOobject& a) const
240 if (a.eventNo() >= eventNo_)
251 bool Foam::regIOobject::upToDate
253 const regIOobject& a,
259 a.eventNo() >= eventNo_
260 || b.eventNo() >= eventNo_
272 bool Foam::regIOobject::upToDate
274 const regIOobject& a,
275 const regIOobject& b,
281 a.eventNo() >= eventNo_
282 || b.eventNo() >= eventNo_
283 || c.eventNo() >= eventNo_
295 bool Foam::regIOobject::upToDate
297 const regIOobject& a,
298 const regIOobject& b,
299 const regIOobject& c,
305 a.eventNo() >= eventNo_
306 || b.eventNo() >= eventNo_
307 || c.eventNo() >= eventNo_
308 || d.eventNo() >= eventNo_
320 //- Flag me as up to date
321 void Foam::regIOobject::setUpToDate()
323 eventNo_ = db().getEvent();
327 // Rename object and re-register with objectRegistry under new name
328 void Foam::regIOobject::rename(const word& newName)
330 // Check out of objectRegistry
333 IOobject::rename(newName);
335 if (registerObject())
337 // Re-register object with objectRegistry
343 // Assign to IOobject
344 void Foam::regIOobject::operator=(const IOobject& io)
352 // Check out of objectRegistry
355 IOobject::operator=(io);
357 if (registerObject())
359 // Re-register object with objectRegistry
365 // ************************************************************************* //