/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "objectRegistry.H" #include "stringListOps.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template Foam::wordList Foam::objectRegistry::toc() const { wordList objectNames(size()); label count=0; forAllConstIter(HashTable, *this, iter) { if (isA(*iter())) { objectNames[count++] = iter()->name(); } } objectNames.setSize(count); return objectNames; } template Foam::wordList Foam::objectRegistry::toc(const wordRe& name) const { wordList objectNames(size()); label count = 0; forAllConstIter(HashTable, *this, iter) { if (isA(*iter())) { const word& objectName = iter()->name(); if (name.match(objectName)) { objectNames[count++] = objectName; } } } objectNames.setSize(count); return objectNames; } template Foam::wordList Foam::objectRegistry::toc(const wordReList& patterns) const { wordList names(this->toc()); return wordList(names, findStrings(patterns, names)); } template Foam::HashTable Foam::objectRegistry::lookupClass ( const bool strict ) const { HashTable objectsOfClass(size()); forAllConstIter(HashTable, *this, iter) { if ( (strict && isType(*iter())) || (!strict && isA(*iter())) ) { objectsOfClass.insert ( iter()->name(), dynamic_cast(iter()) ); } } return objectsOfClass; } template Foam::HashTable Foam::objectRegistry::lookupClass ( const bool strict ) { HashTable objectsOfClass(size()); forAllIter(HashTable, *this, iter) { if ( (strict && isType(*iter())) || (!strict && isA(*iter())) ) { objectsOfClass.insert ( iter()->name(), dynamic_cast(iter()) ); } } return objectsOfClass; } template bool Foam::objectRegistry::foundObject(const word& name) const { const_iterator iter = find(name); if (iter != end()) { const Type* vpsiPtr_ = dynamic_cast(iter()); if (vpsiPtr_) { return true; } } else if (this->parentNotTime()) { return parent_.foundObject(name); } return false; } template const Type& Foam::objectRegistry::lookupObject(const word& name) const { const_iterator iter = find(name); if (iter != end()) { const Type* vpsiPtr_ = dynamic_cast(iter()); if (vpsiPtr_) { return *vpsiPtr_; } FatalErrorInFunction << nl << " lookup of " << name << " from objectRegistry " << this->name() << " successful\n but it is not a " << Type::typeName << ", it is a " << iter()->type() << abort(FatalError); } else { if (this->parentNotTime()) { return parent_.lookupObject(name); } FatalErrorInFunction << nl << " request for " << Type::typeName << " " << name << " from objectRegistry " << this->name() << " failed\n available objects of type " << Type::typeName << " are" << nl << toc(); if (temporaryObjectCached(name)) { FatalErrorInFunction << nl << " request for " << name << " from objectRegistry " << this->name() << " to be cached failed" << nl << " available temporary objects are" << nl << temporaryObjects_; } FatalErrorInFunction << abort(FatalError); } return NullObjectRef(); } template Type& Foam::objectRegistry::lookupObjectRef(const word& name) const { return const_cast(lookupObject(name)); } template bool Foam::objectRegistry::foundType(const word& group) const { return foundObject(IOobject::groupName(Type::typeName, group)); } template const Type& Foam::objectRegistry::lookupType(const word& group) const { return lookupObject(IOobject::groupName(Type::typeName, group)); } template Type& Foam::objectRegistry::lookupTypeRef(const word& group) const { return const_cast(lookupType(group)); } template bool Foam::objectRegistry::cacheTemporaryObject(Object& ob) const { if (cacheTemporaryObjectsState_ == -1) return false; const objectRegistry& root = time_; root.readCacheTemporaryObjects(); if (root.cacheTemporaryObjects_.empty()) return false; temporaryObjects_.insert(ob.name()); HashTable>::iterator rootIter = root.cacheTemporaryObjects_.find(ob.name()); if (rootIter == root.cacheTemporaryObjects_.end()) return false; HashTable>::iterator iter = cacheTemporaryObjects_.find(ob.name()); if (iter == cacheTemporaryObjects_.end()) { cacheTemporaryObjects_.insert(rootIter.key(), rootIter()); iter = cacheTemporaryObjects_.find(ob.name()); } // Cache object ob if it hasn't been cached yet if (iter().first() == false) { rootIter().first() = true; rootIter().second() = true; iter().first() = true; iter().second() = true; if (ob.db().template foundObject(ob.name())) { Object& cachedOb = ob.db().template lookupObjectRef(ob.name()); // If the object is already cached in the database delete it if (&cachedOb != &ob && cachedOb.ownedByRegistry()) { deleteCachedObject(cachedOb); } } if (debug) { Info<< "Caching " << ob.name() << " of type " << ob.type() << endl; } ob.release(); ob.checkOut(); store(new Object(move(ob))); return true; } return false; } // ************************************************************************* //