ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / objectRegistry / objectRegistryTemplates.C
blobeb7b8fab63469b1624bf693cf824b0ae5d4e97a2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "objectRegistry.H"
29 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
31 template<class Type>
32 Foam::wordList
33 Foam::objectRegistry::names() const
35     wordList objectNames(size());
37     label count=0;
38     for (const_iterator iter = begin(); iter != end(); ++iter)
39     {
40         if (isA<Type>(*iter()))
41         {
42             objectNames[count++] = iter()->name();
43         }
44     }
46     objectNames.setSize(count);
48     return objectNames;
52 template<class Type>
53 Foam::HashTable<const Type*>
54 Foam::objectRegistry::lookupClass() const
56     HashTable<const Type*> objectsOfClass(size());
58     for (const_iterator iter = begin(); iter != end(); ++iter)
59     {
60         if (isA<Type>(*iter()))
61         {
62             objectsOfClass.insert
63             (
64                 iter()->name(),
65                 dynamic_cast<const Type*>(iter())
66             );
67         }
68     }
70     return objectsOfClass;
74 template<class Type>
75 bool Foam::objectRegistry::foundObject(const word& name) const
77     const_iterator iter = find(name);
79     if (iter != end())
80     {
81         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
83         if (vpsiPtr_)
84         {
85             return true;
86         }
87     }
88     else if (this->parentNotTime())
89     {
90         return parent_.foundObject<Type>(name);
91     }
93     return false;
97 template<class Type>
98 const Type& Foam::objectRegistry::lookupObject(const word& name) const
100     const_iterator iter = find(name);
102     if (iter != end())
103     {
104         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
106         if (vpsiPtr_)
107         {
108             return *vpsiPtr_;
109         }
111         FatalErrorIn
112         (
113             "objectRegistry::lookupObject<Type>(const word&) const"
114         )   << nl
115             << "    lookup of " << name << " from objectRegistry "
116             << this->name()
117             << " successful\n    but it is not a " << Type::typeName
118             << ", it is a " << iter()->type()
119             << abort(FatalError);
120     }
121     else
122     {
123         if (this->parentNotTime())
124         {
125             return parent_.lookupObject<Type>(name);
126         }
128         FatalErrorIn
129         (
130             "objectRegistry::lookupObject<Type>(const word&) const"
131         )   << nl
132             << "    request for " << Type::typeName
133             << " " << name << " from objectRegistry " << this->name()
134             << " failed\n    available objects of type " << Type::typeName
135             << " are" << nl
136             << names<Type>()
137             << abort(FatalError);
138     }
140     return *reinterpret_cast< const Type* >(0);
144 // ************************************************************************* //