48 template<
class InputIter>
55 const label nTotal = obr.
size();
56 changed < nTotal && first != last;
60 if (obr.
erase(*first))
74 bool Foam::objectRegistry::parentNotTime() const
noexcept 76 return (&parent_ != static_cast<const objectRegistry*>(&time_));
82 Foam::objectRegistry::objectRegistry
85 const label initialCapacity
106 cacheTemporaryObjectsActive_(false),
107 cacheTemporaryObjects_(0),
112 Foam::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));
237 return sortedNames(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_++;
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);
303 Pout<<
"objectRegistry::checkIn : " 305 <<
" of type " <<
io->type()
311 if (!cacheTemporaryObjects_.empty())
313 auto cacheIter = cacheTemporaryObjects_.find(
io->
name());
315 if (cacheIter.good())
317 iterator iter = obr.find(
io->
name());
323 && iter.val()->ownedByRegistry()
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);
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());
366 Pout<<
"objectRegistry::checkOut : " 368 <<
" of type " <<
io->type()
372 if (iter.val() !=
io)
377 <<
name() <<
" : Attempt to checkOut copy of " 385 return obr.erase(iter);
391 Pout<<
"objectRegistry::checkOut : " 392 <<
name() <<
" : could not find " <<
io->
name() <<
" in registry" 408 return checkOut(&
io);
424 for (iterator iter =
begin(); iter !=
end(); ++iter)
432 Pout<<
"objectRegistry::clear : " << ptr->
name() <<
nl;
457 regIOobject* ptr =
const_cast<iterator&
>(iter).val();
482 return eraseImpl(*
this, keys.begin(), keys.end());
497 const auto i = dbDir_.rfind(
'/');
499 if (i == string::npos)
505 dbDir_.
replace(i+1, string::npos, newName);
516 const_iterator iter = cfind(
name);
522 else if (recursive && this->parentNotTime())
524 return parent_.cfindIOobject(
name, recursive);
537 return cfindIOobject(
name, recursive);
543 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
545 if (iter.val()->modified())
557 for (iterator iter =
begin(); iter !=
end(); ++iter)
561 Pout<<
"objectRegistry::readModifiedObjects() : " 562 <<
name() <<
" : Considering reading object " 563 << iter.key() <<
endl;
566 iter.val()->readIfModified();
573 readModifiedObjects();
581 const bool writeOnProc
586 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
592 Pout<<
"objectRegistry::write() : " 593 <<
name() <<
" : Considering writing object " 594 << iter.key() <<
" of type " 595 << obj.type() <<
" with writeOpt " 602 ok = iter.val()->writeObject(streamOpt, writeOnProc) && ok;
bool contains(const word &name, const bool recursive=false) const
Does the registry contain the regIOobject object (by name).
string & replace(const std::string &s1, const std::string &s2, size_type pos=0)
Replace first occurrence of sub-string s1 with s2, beginning at pos.
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
writeOption
Enumeration defining write preferences.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
void release(const bool unregister=false) noexcept
Set object as not ownedByRegistry.
void readModifiedObjects()
Read the objects that have been modified.
const word & name() const noexcept
Return the object name.
bool erase(const iterator &iter)
Erase an entry specified by the given iterator.
constexpr char nl
The newline '\n' character (0x0a)
wordList names() const
The unsorted names of all objects.
virtual bool modified() const
Return true if any of the object's files have been modified.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool store()
Register object with its registry and transfer ownership to the registry.
A simple container for options an IOstream can normally have.
Ignore writing from objectRegistry::writeObject()
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false, const bool recursive=false) const
Lookup and return a const sub-objectRegistry.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
StringType validate(const std::string &str, const UnaryPredicate &accept, const bool invert=false)
Return a copy of the input string with validated characters.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write the objects using stream options.
label size() const noexcept
The number of elements in table.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Unary and binary predicates that always return true, useful for templating.
writeOption writeOpt() const noexcept
Get the write option.
label count(const char *clsName) const
The number of objects of the given class name.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
void clear()
Remove all entries from table.
wordList sortedNames() const
The sorted names of all objects.
virtual ~objectRegistry()
Destructor, with checkOut() for all objects that are ownedByRegistry.
label getEvent() const
Return new event number.
virtual bool readIfModified()
Read object if modified.
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
A HashTable similar to std::unordered_map.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool isTimeDb() const noexcept
True if the registry is Time.
bool checkOut()
Remove object from registry, and remove all file watches.
int debug
Static debugging option.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
virtual void rename(const word &newName)
Rename.
void clearStorage()
Clear all entries from the registry and the table itself.
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true)
#define WarningInFunction
Report a warning using Foam::Warning.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
bool ownedByRegistry() const noexcept
Is this object owned by the registry?
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Automatically write from objectRegistry::writeObject()
void clear()
Clear all entries from the registry.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
fileName objectRelPath() const
The object path relative to the root.
static label eraseImpl(objectRegistry &obr, InputIter first, InputIter last)
List< Key > toc() const
The table of contents (the keys) in unsorted order.
iterator end() noexcept
Return an iterator to end traversing the UList.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
Registry of regIOobjects.
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Request registration (bool: true)
bool checkIn()
Add object to registry, if not already registered.
const regIOobject * cfindIOobject(const word &name, const bool recursive=false) const
Return const pointer to the regIOobject.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
virtual void rename(const word &newName)
Rename.
void clearStorage()
Remove all entries from table and the table itself.
HashTable< wordHashSet > classes() const
A summary hash of classes used and their associated object names.
readOption
Enumeration defining read preferences.