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
193 const MatchPredicate& matchName
203 const BaseType* ptr = Foam::isA<BaseType>(*iter.val());
205 if (ptr && matchName(ptr->name()))
207 result.set(
count, const_cast<BaseType*>(ptr));
212 result.resize(
count);
222 template<
class MatchPredicate>
226 const MatchPredicate& matchName
229 return classesImpl(*
this, matchName);
233 template<
class MatchPredicate>
236 const MatchPredicate& matchClass
243 template<
class MatchPredicate1,
class MatchPredicate2>
246 const MatchPredicate1& matchClass,
247 const MatchPredicate2& matchName
250 return countImpl(*
this, matchClass, matchName);
254 template<
class Type,
class MatchPredicate>
257 const MatchPredicate& matchName
260 return countTypeImpl<Type>(*
this, matchName);
278 std::is_void<Type>::value
282 ?
bool(Foam::isType<Type>(*obj))
283 :
bool(Foam::isA<Type>(*obj))
321 template<
class Type,
class MatchPredicate>
325 const MatchPredicate& matchName
328 return objectsTypeImpl<const Type>(*
this, matchName);
332 template<
class Type,
class MatchPredicate>
336 const MatchPredicate& matchName
339 return objectsTypeImpl<const Type>(*
this, matchName);
342 template<
class Type,
class MatchPredicate>
346 const MatchPredicate& matchName
349 return objectsTypeImpl<Type>(*
this, matchName);
355 template<
class MatchPredicate>
358 const MatchPredicate& matchClass
365 template<
class MatchPredicate1,
class MatchPredicate2>
368 const MatchPredicate1& matchClass,
369 const MatchPredicate2& matchName
372 return namesImpl(*
this, matchClass, matchName,
false);
383 template<
class Type,
class MatchPredicate>
386 const MatchPredicate& matchName
389 return namesTypeImpl<Type>(*
this, matchName,
false);
393 template<
class MatchPredicate>
396 const MatchPredicate& matchClass
403 template<
class MatchPredicate1,
class MatchPredicate2>
406 const MatchPredicate1& matchClass,
407 const MatchPredicate2& matchName
410 return namesImpl(*
this, matchClass, matchName,
true);
421 template<
class Type,
class MatchPredicate>
424 const MatchPredicate& matchName
427 return namesTypeImpl<Type>(*
this, matchName,
true);
446 ?
bool(Foam::isType<Type>(*obj))
447 :
bool(Foam::isA<Type>(*obj))
450 objectsOfClass.insert(obj->
name(),
dynamic_cast<const Type*
>(obj));
454 return objectsOfClass;
473 ?
bool(Foam::isType<Type>(*obj))
474 :
bool(Foam::isA<Type>(*obj))
477 objectsOfClass.
insert(obj->
name(),
dynamic_cast<Type*
>(obj));
481 return objectsOfClass;
492 return this->cfindObject<Type>(
name, recursive);
503 return dynamic_cast<const Type*
>(this->cfindIOobject(
name, recursive));
514 return this->cfindObject<Type>(
name, recursive);
525 return const_cast<Type*
>(this->cfindObject<Type>(
name, recursive));
536 return const_cast<Type*
>(this->cfindObject<Type>(
name, recursive));
547 const_iterator iter = cfind(
name);
551 const Type* ptr =
dynamic_cast<const Type*
>(iter());
560 <<
" bad lookup of " <<
name <<
" (objectRegistry " 562 <<
")\n expected a " << Type::typeName
563 <<
", found a " << (*iter)->type() <<
nl 566 else if (recursive && this->parentNotTime())
568 return parent_.lookupObject<Type>(
name, recursive);
573 <<
" failed lookup of " <<
name <<
" (objectRegistry " 575 <<
")\n available objects of type " << Type::typeName
577 << names<Type>() <<
nl 580 return NullObjectRef<Type>();
591 const Type&
ref = this->lookupObject<Type>(
name, recursive);
594 return const_cast<Type&
>(
ref);
UPtrList< const regIOobject > csorted() const
Return sorted list of objects.
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.
constexpr char nl
The newline '\n' character (0x0a)
wordList names() const
The unsorted names of all objects.
label size() const noexcept
The number of elements in table.
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.
bool insert(const word &key, const regIOobject * &obj)
Copy insert a new entry, not overwriting existing entries.
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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for 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.
#define forAllIters(container, iter)
Iterate across all elements in the container object.
A HashTable similar to std::unordered_map.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
bool foundObject(const word &name, const bool recursive=false) const
Is the named Type found?
Registry of regIOobjects.
UPtrList< const regIOobject > sorted() const
Return sorted list of objects.
HashTable< const Type * > lookupClass(const bool strict=false) const
Return all objects with a class satisfying isA<Type>
forAllConstIters(mixture.phases(), phase)
HashTable< wordHashSet > classes() const
A summary hash of classes used and their associated object names.