mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: refactored regIOobject searching in object registry
- The findObject() methods are template-typed and used to locate a
particular Type/name combination.
Eg,
volScalarField* ptr = obr.findObject<volScalarField>("xyz");
- The findIOobject() methods are un-typed and use the name only.
Eg,
regIOobject* ptr = obr.findIOobject("xyz");
The typed versions will be most commonly used, but the un-typed lookup
can be useful in a templating.
- Simplified findObject* methods to use findIOobject* as the backend.
This commit is contained in:
committed by
Andrew Heather
parent
1b9576df0a
commit
6d6f43d72e
@ -373,6 +373,67 @@ void Foam::objectRegistry::rename(const word& newName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::objectRegistry::found
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return cfindIOobject(name, recursive);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Foam::regIOobject* Foam::objectRegistry::cfindIOobject
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const_iterator iter = cfind(name);
|
||||||
|
|
||||||
|
if (iter.found())
|
||||||
|
{
|
||||||
|
return iter.val();
|
||||||
|
}
|
||||||
|
else if (recursive && this->parentNotTime())
|
||||||
|
{
|
||||||
|
return parent_.cfindIOobject(name, recursive);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Foam::regIOobject* Foam::objectRegistry::findIOobject
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return cfindIOobject(name, recursive);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::regIOobject* Foam::objectRegistry::findIOobject
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return const_cast<regIOobject*>(cfindIOobject(name, recursive));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::regIOobject* Foam::objectRegistry::getIOobjectPtr
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return const_cast<regIOobject*>(cfindIOobject(name, recursive));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::objectRegistry::modified() const
|
bool Foam::objectRegistry::modified() const
|
||||||
{
|
{
|
||||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||||
|
|||||||
@ -340,6 +340,59 @@ public:
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
HashTable<Type*> lookupClass(const bool strict = false);
|
HashTable<Type*> lookupClass(const bool strict = false);
|
||||||
|
|
||||||
|
|
||||||
|
//- Can the regIOobject object be found (by name).
|
||||||
|
//
|
||||||
|
// \param recursive search parent registries
|
||||||
|
bool found(const word& name, const bool recursive = false) const;
|
||||||
|
|
||||||
|
|
||||||
|
//- Return const pointer to the regIOobject.
|
||||||
|
//
|
||||||
|
// \param recursive search parent registries
|
||||||
|
//
|
||||||
|
// \return nullptr if the object was not found.
|
||||||
|
const regIOobject* cfindIOobject
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive = false
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Return const pointer to the regIOobject.
|
||||||
|
//
|
||||||
|
// \param recursive search parent registries
|
||||||
|
//
|
||||||
|
// \return nullptr if the object was not found.
|
||||||
|
const regIOobject* findIOobject
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive = false
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Return non-const pointer to the regIOobject.
|
||||||
|
//
|
||||||
|
// \param recursive search parent registries
|
||||||
|
//
|
||||||
|
// \return nullptr if the object was not found.
|
||||||
|
regIOobject* findIOobject
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive = false
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Return non-const pointer to the regIOobject,
|
||||||
|
//- using a const-cast to have it behave like a mutable.
|
||||||
|
// Exercise caution when using.
|
||||||
|
//
|
||||||
|
// \param recursive search parent registries.
|
||||||
|
//
|
||||||
|
// \return nullptr if the object was not found.
|
||||||
|
regIOobject* getIOobjectPtr
|
||||||
|
(
|
||||||
|
const word& name,
|
||||||
|
const bool recursive = false
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Is the named Type found?
|
//- Is the named Type found?
|
||||||
//
|
//
|
||||||
// \param recursive search parent registries
|
// \param recursive search parent registries
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2015 OpenFOAM Foundation
|
| Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
@ -391,23 +391,7 @@ const Type* Foam::objectRegistry::cfindObject
|
|||||||
const bool recursive
|
const bool recursive
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const_iterator iter = cfind(name);
|
return dynamic_cast<const Type*>(this->cfindIOobject(name, recursive));
|
||||||
|
|
||||||
if (iter.found())
|
|
||||||
{
|
|
||||||
const Type* ptr = dynamic_cast<const Type*>(iter());
|
|
||||||
|
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (recursive && this->parentNotTime())
|
|
||||||
{
|
|
||||||
return parent_.cfindObject<Type>(name, recursive);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -429,9 +413,7 @@ Type* Foam::objectRegistry::findObject
|
|||||||
const bool recursive
|
const bool recursive
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const Type* ptr = this->cfindObject<Type>(name, recursive);
|
return const_cast<Type*>(this->cfindObject<Type>(name, recursive));
|
||||||
|
|
||||||
return const_cast<Type*>(ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -442,9 +424,7 @@ Type* Foam::objectRegistry::getObjectPtr
|
|||||||
const bool recursive
|
const bool recursive
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const Type* ptr = this->cfindObject<Type>(name, recursive);
|
return const_cast<Type*>(this->cfindObject<Type>(name, recursive));
|
||||||
|
|
||||||
return const_cast<Type*>(ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user