31 #include <type_traits> 36 template<
class MatchPredicate>
40 const MatchPredicate& matchName
50 if (matchName(obj->
name()))
62 template<
class MatchPredicate1,
class MatchPredicate2>
63 Foam::label Foam::objectRegistry::countImpl
66 const MatchPredicate1& matchClass,
67 const MatchPredicate2& matchName
76 if (matchClass(obj->type()) && matchName(obj->
name()))
87 template<
class Type,
class MatchPredicate>
88 Foam::label Foam::objectRegistry::countTypeImpl
91 const MatchPredicate& matchName
102 (std::is_void<Type>::value || Foam::isA<Type>(*obj))
103 && matchName(obj->
name())
115 template<
class MatchPredicate1,
class MatchPredicate2>
119 const MatchPredicate1& matchClass,
120 const MatchPredicate2& matchName,
131 if (matchClass(obj->type()) && matchName(obj->
name()))
138 objNames.resize(
count);
150 template<
class Type,
class MatchPredicate>
154 const MatchPredicate& matchName,
167 (std::is_void<Type>::value || Foam::isA<Type>(*obj))
168 && matchName(obj->
name())
176 objNames.resize(
count);
188 template<
class Type,
class MatchPredicate>
190 Foam::objectRegistry::objectsTypeImpl
194 const MatchPredicate& matchName,
206 const BaseType* ptr =
dynamic_cast<const BaseType*
>(obj);
211 && (!strict || Foam::isType<BaseType>(*obj))
212 && matchName(obj->
name())
215 result.set(
count, const_cast<BaseType*>(ptr));
220 result.resize(
count);
234 Foam::objectRegistry::lookupClassTypeImpl
247 const BaseType* ptr =
dynamic_cast<const BaseType*
>(obj);
252 && (!strict || Foam::isType<BaseType>(*obj))
255 result.insert(obj->
name(),
const_cast<BaseType*
>(ptr));
265 template<
class MatchPredicate>
269 const MatchPredicate& matchName
272 return classesImpl(*
this, matchName);
276 template<
class MatchPredicate>
279 const MatchPredicate& matchClass
286 template<
class MatchPredicate1,
class MatchPredicate2>
289 const MatchPredicate1& matchClass,
290 const MatchPredicate2& matchName
293 return countImpl(*
this, matchClass, matchName);
297 template<
class Type,
class MatchPredicate>
300 const MatchPredicate& matchName
303 return countTypeImpl<Type>(*
this, matchName);
321 std::is_void<Type>::value
325 ?
bool(Foam::isType<Type>(*obj))
326 :
bool(Foam::isA<Type>(*obj))
340 template<
class Type,
bool Strict>
344 return objectsTypeImpl<const Type>
351 template<
class Type,
bool Strict>
355 return objectsTypeImpl<Type>
362 template<
class Type,
bool Strict>
366 return objectsTypeImpl<const Type>
373 template<
class Type,
bool Strict>
377 return objectsTypeImpl<Type>
384 template<
class Type,
class MatchPredicate>
388 const MatchPredicate& matchName
392 return objectsTypeImpl<const Type>(
false, *
this, matchName,
false);
396 template<
class Type,
class MatchPredicate>
400 const MatchPredicate& matchName
404 return objectsTypeImpl<Type>(
false, *
this, matchName,
false);
408 template<
class Type,
class MatchPredicate>
412 const MatchPredicate& matchName
415 return objectsTypeImpl<const Type>(
false, *
this, matchName,
true);
419 template<
class Type,
class MatchPredicate>
423 const MatchPredicate& matchName
426 return objectsTypeImpl<Type>(
false, *
this, matchName,
true);
432 template<
class MatchPredicate>
435 const MatchPredicate& matchClass
442 template<
class MatchPredicate1,
class MatchPredicate2>
445 const MatchPredicate1& matchClass,
446 const MatchPredicate2& matchName
449 return namesImpl(*
this, matchClass, matchName,
false);
460 template<
class Type,
class MatchPredicate>
463 const MatchPredicate& matchName
466 return namesTypeImpl<Type>(*
this, matchName,
false);
470 template<
class MatchPredicate>
473 const MatchPredicate& matchClass
480 template<
class MatchPredicate1,
class MatchPredicate2>
483 const MatchPredicate1& matchClass,
484 const MatchPredicate2& matchName
487 return namesImpl(*
this, matchClass, matchName,
true);
498 template<
class Type,
class MatchPredicate>
501 const MatchPredicate& matchName
504 return namesTypeImpl<Type>(*
this, matchName,
true);
508 template<
class Type,
bool Strict>
511 return lookupClassTypeImpl<const Type>(Strict, *
this);
515 template<
class Type,
bool Strict>
518 return lookupClassTypeImpl<Type>(Strict, *
this);
528 return lookupClassTypeImpl<const Type>(strict, *
this);
538 return lookupClassTypeImpl<Type>(strict, *
this);
549 return this->cfindObject<Type>(
name, recursive);
560 return dynamic_cast<const Type*
>(this->cfindIOobject(
name, recursive));
571 return this->cfindObject<Type>(
name, recursive);
582 return const_cast<Type*
>(this->cfindObject<Type>(
name, recursive));
593 return const_cast<Type*
>(this->cfindObject<Type>(
name, recursive));
604 const_iterator iter = cfind(
name);
608 const Type* ptr =
dynamic_cast<const Type*
>(iter.val());
617 <<
" bad lookup of " <<
name <<
" (objectRegistry " 619 <<
")\n expected a " << Type::typeName
620 <<
", found a " << (*iter)->type() <<
nl 623 else if (recursive && this->parentNotTime())
625 return parent_.lookupObject<Type>(
name, recursive);
630 <<
" failed lookup of " <<
name <<
" (objectRegistry " 632 <<
")\n available objects of type " << Type::typeName
634 << names<Type>() <<
nl 637 return NullObjectRef<Type>();
648 const Type&
ref = this->lookupObject<Type>(
name, recursive);
651 return const_cast<Type&
>(
ref);
660 readCacheTemporaryObjects();
662 if (cacheTemporaryObjects_.size())
664 temporaryObjects_.insert(obj.name());
666 auto iter = cacheTemporaryObjects_.find(obj.name());
670 if (iter.good() && iter.val().first() ==
false)
672 iter.val().first() =
true;
673 iter.val().second() =
true;
675 Type* cachedPtr = obj.db().template getObjectPtr<Type>(obj.name());
678 if (cachedPtr && cachedPtr != &obj && cachedPtr->ownedByRegistry())
680 deleteCachedObject(cachedPtr);
685 Info<<
"Caching " << obj.name()
686 <<
" of type " << obj.type() <<
endl;
bool cacheTemporaryObject(Type &obj) const
Cache the given object. Moves content and stores.
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...
errorManipArg< error, int > exit(error &err, const int errNo=1)
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...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const word & name() const noexcept
Return the object name.
UPtrList< const Type > csorted() const
Return sorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
constexpr char nl
The newline '\n' character (0x0a)
wordList names() const
The unsorted names of all objects.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool store()
Register object with its registry and transfer ownership to the registry.
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
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) ...
bool insert(const word &key, const regIOobject * &obj)
Copy insert a new entry, not overwriting existing entries.
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.
label count(const char *clsName) const
The number of objects of the given class name.
label capacity() const noexcept
The size of the underlying table (the number of buckets)
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.
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...
void sort(UList< T > &list)
Sort the list.
wordList sortedNames() const
The sorted names of all objects.
A HashTable similar to std::unordered_map.
int debug
Static debugging option.
UPtrList< const Type > cobjects() const
Return unsorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
UPtrList< Type > objects()
Return unsorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
messageStream Info
Information stream (stdout output on master, null elsewhere)
bool foundObject(const word &name, const bool recursive=false) const
Is the named Type found?
Registry of regIOobjects.
forAllConstIters(mixture.phases(), phase)
HashTable< wordHashSet > classes() const
A summary hash of classes used and their associated object names.