OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "objectRegistry.H"
00028 
00029 
00030 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00031 
00032 template<class Type>
00033 Foam::wordList
00034 Foam::objectRegistry::names() const
00035 {
00036     wordList objectNames(size());
00037 
00038     label count=0;
00039     for (const_iterator iter = begin(); iter != end(); ++iter)
00040     {
00041         if (isA<Type>(*iter()))
00042         {
00043             objectNames[count++] = iter()->name();
00044         }
00045     }
00046 
00047     objectNames.setSize(count);
00048 
00049     return objectNames;
00050 }
00051 
00052 
00053 template<class Type>
00054 Foam::HashTable<const Type*>
00055 Foam::objectRegistry::lookupClass() const
00056 {
00057     HashTable<const Type*> objectsOfClass(size());
00058 
00059     for (const_iterator iter = begin(); iter != end(); ++iter)
00060     {
00061         if (isA<Type>(*iter()))
00062         {
00063             objectsOfClass.insert
00064             (
00065                 iter()->name(),
00066                 dynamic_cast<const Type*>(iter())
00067             );
00068         }
00069     }
00070 
00071     return objectsOfClass;
00072 }
00073 
00074 
00075 template<class Type>
00076 bool Foam::objectRegistry::foundObject(const word& name) const
00077 {
00078     const_iterator iter = find(name);
00079 
00080     if (iter != end())
00081     {
00082         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
00083 
00084         if (vpsiPtr_)
00085         {
00086             return true;
00087         }
00088         else
00089         {
00090             return false;
00091         }
00092     }
00093     else
00094     {
00095         if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
00096         {
00097             return parent_.foundObject<Type>(name);
00098         }
00099         else
00100         {
00101             return false;
00102         }
00103     }
00104 }
00105 
00106 
00107 template<class Type>
00108 const Type& Foam::objectRegistry::lookupObject(const word& name) const
00109 {
00110     const_iterator iter = find(name);
00111 
00112     if (iter != end())
00113     {
00114         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
00115 
00116         if (vpsiPtr_)
00117         {
00118             return *vpsiPtr_;
00119         }
00120 
00121         FatalErrorIn("objectRegistry::lookupObject<Type>(const word&) const")
00122             << nl
00123             << "    lookup of " << name << " from objectRegistry "
00124             << this->name()
00125             << " successful\n    but it is not a " << Type::typeName
00126             << ", it is a " << iter()->type()
00127             << abort(FatalError);
00128     }
00129     else
00130     {
00131         if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
00132         {
00133             return parent_.lookupObject<Type>(name);
00134         }
00135         else
00136         {
00137             FatalErrorIn
00138             (
00139                 "objectRegistry::lookupObject<Type>(const word&) const"
00140             )   << nl
00141                 << "    request for " << Type::typeName
00142                 << " " << name << " from objectRegistry " << this->name()
00143                 << " failed\n    available objects of type " << Type::typeName
00144                 << " are" << nl
00145                 << names<Type>()
00146                 << abort(FatalError);
00147         }
00148     }
00149 
00150     return *reinterpret_cast< const Type* >(0);
00151 }
00152 
00153 
00154 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd