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(
const Time& t,
const label nObjects)
105 Foam::objectRegistry::objectRegistry(
const IOobject&
io,
const label nObjects)
130 return (
this == &static_cast<const objectRegistry&>(time_));
143 return count(static_cast<word>(clsName));
183 return names(static_cast<word>(clsName));
190 return sortedNames(static_cast<word>(clsName));
197 const bool forceCreate,
201 if (forceCreate && !foundObject<objectRegistry>(
name, recursive))
217 return lookupObject<objectRegistry>(
name, recursive);
223 label curEvent = event_++;
230 <<
"Event counter has overflowed. " 231 <<
"Resetting counter on all dependent objects." <<
nl 232 <<
"This might cause extra evaluations." <<
endl;
249 if (!
io)
return false;
253 Pout<<
"objectRegistry::checkIn : " 255 <<
" of type " <<
io->type()
259 objectRegistry& obr =
const_cast<objectRegistry&
>(*this);
261 bool ok = obr.insert(
io->
name(),
io);
266 <<
name() <<
" : Attempt to checkIn object with name " 267 <<
io->
name() <<
" which was already checked in" 277 if (!
io)
return false;
279 objectRegistry& obr =
const_cast<objectRegistry&
>(*this);
281 iterator iter = obr.find(
io->
name());
287 Pout<<
"objectRegistry::checkOut : " 289 <<
" of type " <<
io->type()
293 if (iter.val() !=
io)
298 <<
name() <<
" : Attempt to checkOut copy of " 306 return obr.erase(iter);
312 Pout<<
"objectRegistry::checkOut : " 313 <<
name() <<
" : could not find " <<
io->
name() <<
" in registry" 329 return checkOut(&
io);
345 for (iterator iter =
begin(); iter !=
end(); ++iter)
353 Pout<<
"objectRegistry::clear : " << ptr->
name() <<
nl;
378 regIOobject* ptr =
const_cast<iterator&
>(iter).val();
403 return eraseImpl(*
this, keys.begin(), keys.end());
418 const auto i = dbDir_.rfind(
'/');
420 if (i == string::npos)
426 dbDir_.
replace(i+1, string::npos, newName);
437 const_iterator iter = cfind(
name);
443 else if (recursive && this->parentNotTime())
445 return parent_.cfindIOobject(
name, recursive);
458 return cfindIOobject(
name, recursive);
464 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
466 if (iter.val()->modified())
478 for (iterator iter =
begin(); iter !=
end(); ++iter)
482 Pout<<
"objectRegistry::readModifiedObjects() : " 483 <<
name() <<
" : Considering reading object " 484 << iter.key() <<
endl;
487 iter.val()->readIfModified();
494 readModifiedObjects();
507 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
513 Pout<<
"objectRegistry::write() : " 514 <<
name() <<
" : Considering writing object " 515 << iter.key() <<
" of type " 516 << obj.type() <<
" with writeOpt " 523 ok = iter.val()->writeObject(streamOpt, valid) && ok;
bool found(const word &name, const bool recursive=false) const
Can the regIOobject object be found (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.
UPtrList< const regIOobject > csorted() const
Return sorted list of objects.
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.
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write the objects using stream options.
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.
label size() const noexcept
The number of elements in table.
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.
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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 INVALID.
A class for handling words, derived from Foam::string.
void clear()
Clear 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.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
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.
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.
Registry of regIOobjects.
UPtrList< const regIOobject > sorted() const
Return sorted list of objects.
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...
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()
Clear the table entries and the table itself.
HashTable< wordHashSet > classes() const
A summary hash of classes used and their associated object names.