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_));
157 return count(static_cast<word>(clsName));
176 return names(static_cast<word>(clsName));
183 return sortedNames(static_cast<word>(clsName));
190 const bool forceCreate,
194 if (forceCreate && !foundObject<objectRegistry>(
name, recursive))
211 return lookupObject<objectRegistry>(
name, recursive);
217 label curEvent = event_++;
224 <<
"Event counter has overflowed. " 225 <<
"Resetting counter on all dependent objects." <<
nl 226 <<
"This might cause extra evaluations." <<
endl;
243 if (!
io)
return false;
245 objectRegistry& obr =
const_cast<objectRegistry&
>(*this);
249 Pout<<
"objectRegistry::checkIn : " 251 <<
" of type " <<
io->type()
257 if (!cacheTemporaryObjects_.empty())
259 auto cacheIter = cacheTemporaryObjects_.find(
io->
name());
261 if (cacheIter.good())
263 iterator iter = obr.find(
io->
name());
269 && iter.val()->ownedByRegistry()
274 Pout<<
"objectRegistry::checkIn : " 275 <<
name() <<
" : deleting cached object " 279 cacheIter.val().first() =
false;
280 deleteCachedObject(iter.val());
286 bool ok = obr.insert(
io->
name(),
io);
291 <<
name() <<
" : Attempt to checkIn object with name " 292 <<
io->
name() <<
" which was already checked in" 302 if (!
io)
return false;
304 objectRegistry& obr =
const_cast<objectRegistry&
>(*this);
306 iterator iter = obr.find(
io->
name());
312 Pout<<
"objectRegistry::checkOut : " 314 <<
" of type " <<
io->type()
318 if (iter.val() !=
io)
323 <<
name() <<
" : Attempt to checkOut copy of " 331 return obr.erase(iter);
337 Pout<<
"objectRegistry::checkOut : " 338 <<
name() <<
" : could not find " <<
io->
name() <<
" in registry" 354 return checkOut(&
io);
370 for (iterator iter =
begin(); iter !=
end(); ++iter)
378 Pout<<
"objectRegistry::clear : " << ptr->
name() <<
nl;
403 regIOobject* ptr =
const_cast<iterator&
>(iter).val();
428 return eraseImpl(*
this, keys.begin(), keys.end());
443 const auto i = dbDir_.rfind(
'/');
445 if (i == string::npos)
451 dbDir_.
replace(i+1, string::npos, newName);
462 const_iterator iter = cfind(
name);
468 else if (recursive && this->parentNotTime())
470 return parent_.cfindIOobject(
name, recursive);
483 return cfindIOobject(
name, recursive);
489 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
491 if (iter.val()->modified())
503 for (iterator iter =
begin(); iter !=
end(); ++iter)
507 Pout<<
"objectRegistry::readModifiedObjects() : " 508 <<
name() <<
" : Considering reading object " 509 << iter.key() <<
endl;
512 iter.val()->readIfModified();
519 readModifiedObjects();
527 const bool writeOnProc
532 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
538 Pout<<
"objectRegistry::write() : " 539 <<
name() <<
" : Considering writing object " 540 << iter.key() <<
" of type " 541 << obj.type() <<
" with writeOpt " 548 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.
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 all file watches and remove object from registry.
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.
#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)
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.