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 "objectRegistry.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 defineTypeNameAndDebug(Foam::objectRegistry, 0);
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 Foam::objectRegistry::objectRegistry
39 const label nIoObjects
46 string::validate<word>(t.caseName()),
51 true // to flag that this is the top-level regIOobject
53 HashTable<regIOobject*>(nIoObjects),
61 Foam::objectRegistry::objectRegistry
64 const label nIoObjects
68 HashTable<regIOobject*>(nIoObjects),
71 dbDir_(parent_.dbDir()/local()/name()),
74 writeOpt() = IOobject::AUTO_WRITE;
78 Foam::objectRegistry::objectRegistry
81 const fileName& dbDir,
82 const label nIoObjects
86 HashTable<regIOobject*>(nIoObjects),
92 writeOpt() = IOobject::AUTO_WRITE;
96 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
98 Foam::objectRegistry::~objectRegistry()
100 List<regIOobject*> myObjects(size());
101 label nMyObjects = 0;
103 for (iterator iter = begin(); iter != end(); ++iter)
105 if (iter()->ownedByRegistry())
107 myObjects[nMyObjects++] = iter();
111 for (label i=0; i<nMyObjects; i++)
113 checkOut(*myObjects[i]);
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 const Foam::Time& Foam::objectRegistry::time() const
126 Foam::wordList Foam::objectRegistry::names() const
128 wordList objectNames(size());
131 for (const_iterator iter = cbegin(); iter != cend(); ++iter)
133 objectNames[count++] = iter()->name();
140 Foam::wordList Foam::objectRegistry::names(const word& ClassName) const
142 wordList objectNames(size());
145 for (const_iterator iter = cbegin(); iter != cend(); ++iter)
147 if (iter()->type() == ClassName)
149 objectNames[count++] = iter()->name();
153 objectNames.setSize(count);
159 Foam::fileName Foam::objectRegistry::mangleFileName
161 const fileName& fName
168 const Foam::objectRegistry& Foam::objectRegistry::subRegistry
173 return lookupObject<objectRegistry>(name);
177 Foam::label Foam::objectRegistry::getEvent() const
179 label curEvent = event_++;
181 if (event_ == labelMax)
183 WarningIn("objectRegistry::getEvent() const")
184 << "Event counter has overflowed. Resetting counter on all"
185 << " dependent objects." << endl
186 << "This might cause extra evaluations." << endl;
188 // Reset event counter
192 for (const_iterator iter = begin(); iter != end(); ++iter)
194 const regIOobject& io = *iter();
196 if (objectRegistry::debug)
198 Pout<< "objectRegistry::getEvent() : "
199 << "resetting count on " << iter.key() << endl;
202 if (io.eventNo() != 0)
204 const_cast<regIOobject&>(io).eventNo() = curEvent;
213 bool Foam::objectRegistry::checkIn(regIOobject& io) const
215 if (objectRegistry::debug)
217 Pout<< "objectRegistry::checkIn(regIOobject&) : "
218 << name() << " : checking in " << io.name()
222 return const_cast<objectRegistry&>(*this).insert(io.name(), &io);
226 bool Foam::objectRegistry::checkOut(regIOobject& io) const
228 iterator iter = const_cast<objectRegistry&>(*this).find(io.name());
232 if (objectRegistry::debug)
234 Pout<< "objectRegistry::checkOut(regIOobject&) : "
235 << name() << " : checking out " << io.name()
241 if (objectRegistry::debug)
243 WarningIn("objectRegistry::checkOut(regIOobject&)")
244 << name() << " : attempt to checkOut copy of " << io.name()
252 regIOobject* object = iter();
254 bool hasErased = const_cast<objectRegistry&>(*this).erase(iter);
256 if (io.ownedByRegistry())
266 if (objectRegistry::debug)
268 Pout<< "objectRegistry::checkOut(regIOobject&) : "
269 << name() << " : could not find " << io.name()
270 << " in registry " << name()
279 void Foam::objectRegistry::rename(const word& newName)
281 regIOobject::rename(newName);
283 // adjust dbDir_ as well
284 string::size_type i = dbDir_.rfind('/');
286 if (i == string::npos)
292 dbDir_.replace(i+1, string::npos, newName);
297 bool Foam::objectRegistry::modified() const
299 for (const_iterator iter = cbegin(); iter != cend(); ++iter)
301 if (iter()->modified())
311 void Foam::objectRegistry::readModifiedObjects()
313 for (iterator iter = begin(); iter != end(); ++iter)
315 if (objectRegistry::debug)
317 Pout<< "objectRegistry::readModifiedObjects() : "
318 << name() << " : Considering reading object "
323 iter()->readIfModified();
328 bool Foam::objectRegistry::readIfModified()
330 readModifiedObjects();
335 bool Foam::objectRegistry::writeObject
337 IOstream::streamFormat fmt,
338 IOstream::versionNumber ver,
339 IOstream::compressionType cmp
344 for (const_iterator iter = cbegin(); iter != cend(); ++iter)
346 if (objectRegistry::debug)
348 Pout<< "objectRegistry::write() : "
349 << name() << " : Considering writing object "
351 << " with writeOpt " << iter()->writeOpt()
352 << " to file " << iter()->objectPath()
356 if (iter()->writeOpt() != NO_WRITE)
358 ok = iter()->writeObject(fmt, ver, cmp) && ok;
366 // ************************************************************************* //