FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

objectRegistryTemplates.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "objectRegistry.H"
00027 
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 template<class Type>
00032 Foam::wordList
00033 Foam::objectRegistry::names() const
00034 {
00035     wordList objectNames(size());
00036 
00037     label count=0;
00038     for (const_iterator iter = begin(); iter != end(); ++iter)
00039     {
00040         if (isA<Type>(*iter()))
00041         {
00042             objectNames[count++] = iter()->name();
00043         }
00044     }
00045 
00046     objectNames.setSize(count);
00047 
00048     return objectNames;
00049 }
00050 
00051 
00052 template<class Type>
00053 Foam::HashTable<const Type*>
00054 Foam::objectRegistry::lookupClass() const
00055 {
00056     HashTable<const Type*> objectsOfClass(size());
00057 
00058     for (const_iterator iter = begin(); iter != end(); ++iter)
00059     {
00060         if (isA<Type>(*iter()))
00061         {
00062             objectsOfClass.insert
00063             (
00064                 iter()->name(),
00065                 dynamic_cast<const Type*>(iter())
00066             );
00067         }
00068     }
00069 
00070     return objectsOfClass;
00071 }
00072 
00073 
00074 template<class Type>
00075 bool Foam::objectRegistry::foundObject(const word& name) const
00076 {
00077     const_iterator iter = find(name);
00078 
00079     if (iter != end())
00080     {
00081         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
00082 
00083         if (vpsiPtr_)
00084         {
00085             return true;
00086         }
00087         else
00088         {
00089             return false;
00090         }
00091     }
00092     else
00093     {
00094         if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
00095         {
00096             return parent_.foundObject<Type>(name);
00097         }
00098         else
00099         {
00100             return false;
00101         }
00102     }
00103 }
00104 
00105 
00106 template<class Type>
00107 const Type& Foam::objectRegistry::lookupObject(const word& name) const
00108 {
00109     const_iterator iter = find(name);
00110 
00111     if (iter != end())
00112     {
00113         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
00114 
00115         if (vpsiPtr_)
00116         {
00117             return *vpsiPtr_;
00118         }
00119 
00120         FatalErrorIn("objectRegistry::lookupObject<Type>(const word&) const")
00121             << nl
00122             << "    lookup of " << name << " from objectRegistry "
00123             << this->name()
00124             << " successful\n    but it is not a " << Type::typeName
00125             << ", it is a " << iter()->type()
00126             << abort(FatalError);
00127     }
00128     else
00129     {
00130         if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
00131         {
00132             return parent_.lookupObject<Type>(name);
00133         }
00134         else
00135         {
00136             FatalErrorIn
00137             (
00138                 "objectRegistry::lookupObject<Type>(const word&) const"
00139             )   << nl
00140                 << "    request for " << Type::typeName
00141                 << " " << name << " from objectRegistry " << this->name()
00142                 << " failed\n    available objects of type " << Type::typeName
00143                 << " are" << nl
00144                 << names<Type>()
00145                 << abort(FatalError);
00146         }
00147     }
00148 
00149     return *reinterpret_cast< const Type* >(0);
00150 }
00151 
00152 
00153 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines