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"
27 #include "objectRegistry.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::regIOobject, 0);
34 const Foam::debug::optimisationSwitch
35 Foam::regIOobject::fileModificationSkew
37 "fileModificationSkew",
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 // Construct from IOobject
45 Foam::regIOobject::regIOobject(const IOobject& io, const bool isTime)
49 ownedByRegistry_(false),
51 eventNo_ // Do not get event for top level Time database
59 // Register with objectRegistry if requested
68 Foam::regIOobject::regIOobject(const regIOobject& rio)
72 ownedByRegistry_(false),
73 lastModified_(rio.lastModified_),
74 eventNo_(db().getEvent()),
77 // Do not register copy with objectRegistry
81 // Construct as copy, and transfering objectRegistry registration to copy
82 // if registerCopy is true
83 Foam::regIOobject::regIOobject(const regIOobject& rio, bool registerCopy)
87 ownedByRegistry_(false),
88 lastModified_(rio.lastModified_),
89 eventNo_(db().getEvent()),
92 if (registerCopy && rio.registered_)
94 const_cast<regIOobject&>(rio).checkOut();
100 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
102 // Delete read stream, checkout from objectRegistry and destroy
103 Foam::regIOobject::~regIOobject()
105 if (objectRegistry::debug)
107 Info<< "Destroying regIOobject called " << name()
108 << " of type " << type()
109 << " in directory " << path()
119 // Check out of objectRegistry if not owned by the registry
121 if (!ownedByRegistry_)
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 bool Foam::regIOobject::checkIn()
134 // multiple checkin of same object is disallowed - this would mess up
136 registered_ = db().checkIn(*this);
138 // check-in on defaultRegion is allowed to fail, since subsetted meshes
139 // are created with the same name as their originating mesh
140 if (!registered_ && debug && name() != polyMesh::defaultRegion)
144 // for ease of finding where attempted duplicate check-in
146 FatalErrorIn("regIOobject::checkIn()")
147 << "failed to register object " << objectPath()
148 << " the name already exists in the objectRegistry"
149 << abort(FatalError);
153 WarningIn("regIOobject::checkIn()")
154 << "failed to register object " << objectPath()
155 << " the name already exists in the objectRegistry"
165 bool Foam::regIOobject::checkOut()
170 return db().checkOut(*this);
177 bool Foam::regIOobject::upToDate(const word& a) const
179 if (db().lookupObject<regIOobject>(a).eventNo() >= eventNo_)
190 bool Foam::regIOobject::upToDate(const word& a, const word& b) const
194 db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
195 || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
207 bool Foam::regIOobject::upToDate
216 db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
217 || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
218 || db().lookupObject<regIOobject>(c).eventNo() >= eventNo_
230 bool Foam::regIOobject::upToDate
240 db().lookupObject<regIOobject>(a).eventNo() >= eventNo_
241 || db().lookupObject<regIOobject>(b).eventNo() >= eventNo_
242 || db().lookupObject<regIOobject>(c).eventNo() >= eventNo_
243 || db().lookupObject<regIOobject>(d).eventNo() >= eventNo_
255 //- Flag me as up to date
256 void Foam::regIOobject::setUpToDate()
258 eventNo_ = db().getEvent();
262 // Rename object and re-register with objectRegistry under new name
263 void Foam::regIOobject::rename(const word& newName)
265 // Check out of objectRegistry
268 IOobject::rename(newName);
270 if (registerObject())
272 // Re-register object with objectRegistry
278 // Assign to IOobject
279 void Foam::regIOobject::operator=(const IOobject& io)
287 // Check out of objectRegistry
290 IOobject::operator=(io);
292 if (registerObject())
294 // Re-register object with objectRegistry
300 // ************************************************************************* //