Skip to content
Snippets Groups Projects
Commit 6d6f43d7 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

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.
parent 1b9576df
No related branches found
No related tags found
No related merge requests found
......@@ -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
{
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
......
......@@ -340,6 +340,59 @@ public:
template<class Type>
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?
//
// \param recursive search parent registries
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
......@@ -391,23 +391,7 @@ const Type* Foam::objectRegistry::cfindObject
const bool recursive
) const
{
const_iterator iter = cfind(name);
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;
return dynamic_cast<const Type*>(this->cfindIOobject(name, recursive));
}
......@@ -429,9 +413,7 @@ Type* Foam::objectRegistry::findObject
const bool recursive
)
{
const Type* ptr = this->cfindObject<Type>(name, recursive);
return const_cast<Type*>(ptr);
return const_cast<Type*>(this->cfindObject<Type>(name, recursive));
}
......@@ -442,9 +424,7 @@ Type* Foam::objectRegistry::getObjectPtr
const bool recursive
) const
{
const Type* ptr = this->cfindObject<Type>(name, recursive);
return const_cast<Type*>(ptr);
return const_cast<Type*>(this->cfindObject<Type>(name, recursive));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment