48template<
class InputIter>
55 const label nTotal = obr.
size();
56 changed < nTotal && first != last;
60 if (obr.
erase(*first))
74bool Foam::objectRegistry::parentNotTime() const noexcept
76 return (&parent_ !=
static_cast<const objectRegistry*
>(&time_));
82Foam::objectRegistry::objectRegistry
85 const label initialCapacity
106 cacheTemporaryObjectsActive_(false),
107 cacheTemporaryObjects_(0),
112Foam::objectRegistry::objectRegistry
115 const label initialCapacity
124 cacheTemporaryObjectsActive_(false),
125 cacheTemporaryObjects_(0),
144 return (
this == &
static_cast<const objectRegistry&
>(time_));
211 return count(
static_cast<word>(clsName));
230 return names(
static_cast<word>(clsName));
244 const bool forceCreate,
248 if (forceCreate && !foundObject<objectRegistry>(
name, recursive))
265 return lookupObject<objectRegistry>(
name, recursive);
271 label curEvent = event_++;
275 if (objectRegistry::debug)
278 <<
"Event counter has overflowed. "
279 <<
"Resetting counter on all dependent objects." <<
nl
280 <<
"This might cause extra evaluations." <<
endl;
297 if (!
io)
return false;
299 objectRegistry& obr =
const_cast<objectRegistry&
>(*this);
301 if (objectRegistry::debug)
303 Pout<<
"objectRegistry::checkIn : "
304 <<
name() <<
" : checking in " <<
io->name()
305 <<
" type=" <<
io->type()
311 if (!cacheTemporaryObjects_.empty())
313 auto cacheIter = cacheTemporaryObjects_.find(
io->name());
315 if (cacheIter.good())
323 && iter.val()->ownedByRegistry()
326 if (objectRegistry::debug)
328 Pout<<
"objectRegistry::checkIn : "
329 <<
name() <<
" : deleting cached object "
333 cacheIter.val().first() =
false;
334 deleteCachedObject(iter.val());
340 bool ok = obr.insert(
io->name(),
io);
342 if (!ok && objectRegistry::debug)
345 <<
name() <<
" : Attempt to checkIn object with name "
346 <<
io->name() <<
" which was already checked in"
356 if (!
io)
return false;
358 objectRegistry& obr =
const_cast<objectRegistry&
>(*this);
360 iterator iter = obr.find(
io->name());
364 if (objectRegistry::debug)
366 Pout<<
"objectRegistry::checkOut : "
367 <<
name() <<
" : checking out " <<
io->name()
368 <<
" type=" <<
io->type()
369 <<
" owned=" <<
io->ownedByRegistry()
373 if (iter.val() !=
io)
375 if (objectRegistry::debug)
378 <<
name() <<
" : Attempt to checkOut copy of "
386 return obr.erase(iter);
390 if (objectRegistry::debug)
392 Pout<<
"objectRegistry::checkOut : "
393 <<
name() <<
" : could not find " <<
io->name() <<
" in registry"
415 return const_cast<objectRegistry&
>(*this).erase(key);
425 for (
iterator iter = begin(); iter != end(); ++iter)
431 if (objectRegistry::debug)
433 Pout<<
"objectRegistry::clear : " << ptr->
name() <<
nl;
498 const auto i = dbDir_.rfind(
'/');
500 if (i == string::npos)
506 dbDir_.replace(i+1, string::npos, newName);
521 else if (
auto iter = cfind(
name); iter.good())
525 else if (recursive && !this->isTimeDb())
527 return parent_.cfindIOobject(
name, recursive);
548 if (iter.val()->modified())
560 for (
iterator iter = begin(); iter !=
end(); ++iter)
562 if (objectRegistry::debug)
564 Pout<<
"objectRegistry::readModifiedObjects() : "
565 <<
name() <<
" : Considering reading object "
566 << iter.key() <<
endl;
569 iter.val()->readIfModified();
584 const bool writeOnProc
591 if (objectRegistry::debug)
595 Pout<<
"objectRegistry::write() : "
596 <<
name() <<
" : Considering writing object "
597 << iter.key() <<
" type="
598 << obj.type() <<
" writeOpt="
605 ok = iter.val()->writeObject(streamOpt, writeOnProc) && ok;
A HashTable similar to std::unordered_map.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
const_iterator_pair< const_key_iterator, this_type > keys() const
List< Key > toc() const
The table of contents (the keys) in unsorted order.
const_iterator cbegin() const
const_iterator cfind(const word &key) const
void clearStorage()
Remove all entries from table and the table itself.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
label size() const noexcept
The number of elements in table.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
void clear()
Remove all entries from table.
constexpr const_iterator cend() const noexcept
constexpr HashTable() noexcept
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true).
@ NO_REGISTER
Do not request registration (bool: false).
@ REGISTER
Request registration (bool: true).
writeOption writeOpt() const noexcept
Get the write option.
readOption
Enumeration defining read preferences.
@ NO_READ
Nothing to be read.
writeOption
Enumeration defining write preferences.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
const fileName & local() const noexcept
Read access to local path component.
fileName objectRelPath() const
The object path relative to the case.
fileName path() const
The complete path for the object (with instance, local,...).
const fileName & caseName() const noexcept
Return the Time::caseName().
A simple container for options an IOstream can normally have.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
label find(const T &val) const
Find index of the first occurrence of the value.
Registry of regIOobjects.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write the objects using stream options.
bool contains(const word &name, const bool recursive=false) const
Does the registry contain the regIOobject object (by name).
bool foundObject(const word &name, const bool recursive=false) const
Contains the named Type?
bool checkIn(regIOobject *io) const
Add a regIOobject to registry. A nullptr is ignored.
wordList sortedNames() const
The sorted names of all objects.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
virtual bool modified() const
Return true if any of the object's files have been modified.
bool isTimeDb() const noexcept
True if the registry is Time.
HashTable< wordHashSet > classes() const
A summary hash of classes used and their associated object names.
virtual ~objectRegistry()
Destructor, with checkOut() for all objects that are ownedByRegistry.
const Time & time() const noexcept
Return time registry.
void clearStorage()
Clear all entries from the registry and the table itself.
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
const regIOobject * cfindIOobject(const word &name, const bool recursive=false) const
Return const pointer to the regIOobject.
virtual bool readIfModified()
Read object if modified.
bool checkOut(regIOobject *io) const
Remove a regIOobject from registry and free memory if the object is ownedByRegistry....
bool erase(const iterator &iter)
Erase an entry specified by the given iterator.
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false, const bool recursive=false) const
Lookup and return a const sub-objectRegistry.
void clear()
Clear all entries from the registry.
void readModifiedObjects()
Read the objects that have been modified.
wordList names() const
The unsorted names of all objects.
label count(const char *clsName) const
The number of objects of the given class name.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
virtual void rename(const word &newName)
Rename.
label getEvent() const
Return new event number.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
bool ownedByRegistry() const noexcept
Is this object owned by the registry?
bool store()
Register object with its registry and transfer ownership to the registry.
bool checkOut()
Remove object from registry, and remove all file watches.
void release(const bool unregister=false) noexcept
Set object as not ownedByRegistry.
virtual void rename(const word &newName)
Rename.
bool checkIn()
Add object to registry, if not already registered.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
#define WarningInFunction
Report a warning using Foam::Warning.
Different types of constants.
static label eraseImpl(objectRegistry &obr, InputIter first, InputIter last)
List< word > wordList
List of word.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a).
thermo validate(args.executable(), "h")
Unary and binary predicates that always return true, useful for templating.