diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index f9a51bbc2fb12eb82279671ae18c8a0374a00df8..f93d0c1f7d0867e296db2931f4a7ad6e9a5ed57c 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<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) diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index a606f8049cc3eefd537c329bb6f2f51560bd4631..d3d05761a88c858c1f7d6a4f5bf0a1705485eb74 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -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 diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 4d412332900bfc5546784cf55426a52d18775e65..127786b74ff6531cd2beacd845ed5964a1575d8c 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<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)); }