36template<
class MatchPredicate>
39 const objectRegistry& list,
40 const MatchPredicate& matchName
51 if (matchName(obj->
name()))
63template<
class MatchPredicate1,
class MatchPredicate2>
64Foam::label Foam::objectRegistry::countImpl
67 const MatchPredicate1& matchClass,
68 const MatchPredicate2& matchName
77 if (matchClass(obj->type()) && matchName(obj->
name()))
88template<
class Type,
class MatchPredicate>
89Foam::label Foam::objectRegistry::countTypeImpl
92 const MatchPredicate& matchName
104 && matchName(obj->
name())
116template<
class MatchPredicate1,
class MatchPredicate2>
120 const MatchPredicate1& matchClass,
121 const MatchPredicate2& matchName,
132 if (matchClass(obj->type()) && matchName(obj->
name()))
134 objNames[count] = obj->
name();
151template<
class Type,
class MatchPredicate>
155 const MatchPredicate& matchName,
169 && matchName(obj->
name())
172 objNames[count] = obj->
name();
189template<
class Type,
class MatchPredicate>
191Foam::objectRegistry::objectsTypeImpl
195 const MatchPredicate& matchName,
199 using BaseType = std::remove_cv_t<Type>;
207 const BaseType* ptr =
dynamic_cast<const BaseType*
>(obj);
213 && matchName(obj->
name())
216 result.
set(count,
const_cast<BaseType*
>(ptr));
235Foam::objectRegistry::lookupClassTypeImpl
241 using BaseType = std::remove_cv_t<Type>;
248 const BaseType* ptr =
dynamic_cast<const BaseType*
>(obj);
256 result.
insert(obj->
name(),
const_cast<BaseType*
>(ptr));
266template<
class MatchPredicate>
270 const MatchPredicate& matchName
273 return classesImpl(*
this, matchName);
277template<
class MatchPredicate>
280 const MatchPredicate& matchClass
287template<
class MatchPredicate1,
class MatchPredicate2>
290 const MatchPredicate1& matchClass,
291 const MatchPredicate2& matchName
294 return countImpl(*
this, matchClass, matchName);
298template<
class Type,
class MatchPredicate>
301 const MatchPredicate& matchName
304 return countTypeImpl<Type>(*
this, matchName);
341template<
class Type,
bool Strict>
345 return objectsTypeImpl<const Type>
352template<
class Type,
bool Strict>
356 return objectsTypeImpl<Type>
363template<
class Type,
bool Strict>
367 return objectsTypeImpl<const Type>
374template<
class Type,
bool Strict>
378 return objectsTypeImpl<Type>
385template<
class Type,
class MatchPredicate>
389 const MatchPredicate& matchName
393 return objectsTypeImpl<const Type>(
false, *
this, matchName,
false);
397template<
class Type,
class MatchPredicate>
401 const MatchPredicate& matchName
405 return objectsTypeImpl<Type>(
false, *
this, matchName,
false);
409template<
class Type,
class MatchPredicate>
413 const MatchPredicate& matchName
416 return objectsTypeImpl<const Type>(
false, *
this, matchName,
true);
420template<
class Type,
class MatchPredicate>
424 const MatchPredicate& matchName
427 return objectsTypeImpl<Type>(
false, *
this, matchName,
true);
433template<
class MatchPredicate>
436 const MatchPredicate& matchClass
443template<
class MatchPredicate1,
class MatchPredicate2>
446 const MatchPredicate1& matchClass,
447 const MatchPredicate2& matchName
450 return namesImpl(*
this, matchClass, matchName,
false);
461template<
class Type,
class MatchPredicate>
464 const MatchPredicate& matchName
467 return namesTypeImpl<Type>(*
this, matchName,
false);
471template<
class MatchPredicate>
474 const MatchPredicate& matchClass
481template<
class MatchPredicate1,
class MatchPredicate2>
484 const MatchPredicate1& matchClass,
485 const MatchPredicate2& matchName
488 return namesImpl(*
this, matchClass, matchName,
true);
499template<
class Type,
class MatchPredicate>
502 const MatchPredicate& matchName
505 return namesTypeImpl<Type>(*
this, matchName,
true);
509template<
class Type,
bool Strict>
512 return lookupClassTypeImpl<const Type>(Strict, *
this);
516template<
class Type,
bool Strict>
519 return lookupClassTypeImpl<Type>(Strict, *
this);
529 return lookupClassTypeImpl<const Type>(strict, *
this);
539 return lookupClassTypeImpl<Type>(strict, *
this);
605 if (
auto iter = cfind(
name); iter.good())
607 const Type* ptr =
dynamic_cast<const Type*
>(iter.val());
616 <<
" bad lookup of " <<
name <<
" (objectRegistry "
618 <<
")\n expected a " << Type::typeName
619 <<
", found a " << (*iter)->type() <<
nl
622 else if (recursive && !this->isTimeDb())
624 return parent_.lookupObject<Type>(
name, recursive);
629 <<
" failed lookup of " <<
name <<
" (objectRegistry "
631 <<
")\n available objects of type " << Type::typeName
647 const Type&
ref = this->lookupObject<Type>(
name, recursive);
650 return const_cast<Type&
>(
ref);
659 readCacheTemporaryObjects();
661 if (cacheTemporaryObjects_.size())
663 temporaryObjects_.insert(obj.name());
665 auto iter = cacheTemporaryObjects_.find(obj.name());
669 if (iter.good() && iter.val().first() ==
false)
671 iter.val().first() =
true;
672 iter.val().second() =
true;
674 Type* cachedPtr = obj.db().template getObjectPtr<Type>(obj.name());
677 if (cachedPtr && cachedPtr != &obj && cachedPtr->ownedByRegistry())
679 deleteCachedObject(cachedPtr);
684 Info<<
"Caching " << obj.name()
685 <<
" of type " << obj.type() <<
endl;
A HashTable similar to std::unordered_map.
const_iterator cfind(const word &key) const
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
label capacity() const noexcept
The size of the underlying table (the number of buckets).
label size() const noexcept
The number of elements in table.
constexpr HashTable() noexcept
const word & name() const noexcept
Return the object name.
void resize(const label len)
Adjust allocated size of list.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
void resize(const label newLen)
Change the size of the list. Any new entries are nullptr.
Registry of regIOobjects.
bool foundObject(const word &name, const bool recursive=false) const
Contains the named Type?
wordList sortedNames() const
The sorted names of all objects.
UPtrList< const Type > csorted() const
Return sorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict).
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.
UPtrList< Type > objects()
Return unsorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict).
bool cacheTemporaryObject(Type &obj) const
Cache the given object. Moves content and stores.
const regIOobject * cfindIOobject(const word &name, const bool recursive=false) const
Return const pointer to the regIOobject.
HashTable< const Type * > lookupClass() const
Return all objects with a class satisfying isA<Type> or isType<Type> (with Strict).
UPtrList< Type > sorted()
Return sorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict).
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Type & lookupObjectRef(const word &name, const bool recursive=false) const
Lookup and return non-const reference to the object of the given Type. Fatal if not found or the wron...
wordList names() const
The unsorted names of all objects.
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
UPtrList< const Type > cobjects() const
Return unsorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict).
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...
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
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 store()
Register object with its registry and transfer ownership to the registry.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Namespace for handling debugging switches.
List< word > wordList
List of word.
const T & NullObjectRef() noexcept
Const reference (of type T) to the nullObject.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
void sort(UList< T > &list)
Sort the list.
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Extract name (as a word) from an object, typically using its name() method.
Unary and binary predicates that always return true, useful for templating.