diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index f9a51bbc2f..f93d0c1f7d 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -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(cfindIOobject(name, recursive)); +} + + +Foam::regIOobject* Foam::objectRegistry::getIOobjectPtr +( + const word& name, + const bool recursive +) const +{ + return const_cast(cfindIOobject(name, recursive)); +} + + bool Foam::objectRegistry::modified() const { for (const_iterator iter = cbegin(); iter != cend(); ++iter) diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index a606f8049c..d3d05761a8 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -340,6 +340,59 @@ public: template HashTable 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 diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 4d41233290..127786b74f 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -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(iter()); - - if (ptr) - { - return ptr; - } - } - else if (recursive && this->parentNotTime()) - { - return parent_.cfindObject(name, recursive); - } - - return nullptr; + return dynamic_cast(this->cfindIOobject(name, recursive)); } @@ -429,9 +413,7 @@ Type* Foam::objectRegistry::findObject const bool recursive ) { - const Type* ptr = this->cfindObject(name, recursive); - - return const_cast(ptr); + return const_cast(this->cfindObject(name, recursive)); } @@ -442,9 +424,7 @@ Type* Foam::objectRegistry::getObjectPtr const bool recursive ) const { - const Type* ptr = this->cfindObject(name, recursive); - - return const_cast(ptr); + return const_cast(this->cfindObject(name, recursive)); }