initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / db / objectRegistry / objectRegistryTemplates.C
blobee4c97d025342b1b766c524e5e8d5ae6b7473d79
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "objectRegistry.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 template<class Type>
37 wordList objectRegistry::names() const
39     wordList objectNames(size());
41     label count=0;
42     for (const_iterator iter = begin(); iter != end(); ++iter)
43     {
44         if (isA<Type>(*iter()))
45         {
46             objectNames[count++] = iter()->name();
47         }
48     }
50     objectNames.setSize(count);
52     return objectNames;
56 template<class Type>
57 HashTable<const Type*> objectRegistry::lookupClass() const
59     HashTable<const Type*> objectsOfClass(size());
61     for (const_iterator iter = begin(); iter != end(); ++iter)
62     {
63         if (isA<Type>(*iter()))
64         {
65             objectsOfClass.insert
66             (
67                 iter()->name(),
68                 dynamic_cast<const Type*>(iter())
69             );
70         }
71     }
73     return objectsOfClass;
77 template<class Type>
78 bool objectRegistry::foundObject(const word& name) const
80     const_iterator iter = find(name);
82     if (iter != end())
83     {
84         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
86         if (vpsiPtr_)
87         {
88             return true;
89         }
90         else
91         {
92             return false;
93         }
94     }
95     else
96     {
97         if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
98         {
99             return parent_.foundObject<Type>(name);
100         }
101         else
102         {
103             return false;
104         }
105     }
109 template<class Type>
110 const Type& objectRegistry::lookupObject(const word& name) const
112     const_iterator iter = find(name);
114     if (iter != end())
115     {
116         const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
118         if (vpsiPtr_)
119         {
120             return *vpsiPtr_;
121         }
123         FatalErrorIn("objectRegistry::lookupObject<Type>(const word&) const")
124             << nl
125             << "    lookup of " << name << " from objectRegistry "
126             << this->name()
127             << " successful\n    but it is not a " << Type::typeName
128             << ", it is a " << iter()->type()
129             << abort(FatalError);
130     }
131     else
132     {
133         if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
134         {
135             return parent_.lookupObject<Type>(name);
136         }
137         else
138         {
139             FatalErrorIn
140             (
141                 "objectRegistry::lookupObject<Type>(const word&) const"
142             )   << nl
143                 << "    request for " << Type::typeName
144                 << " " << name << " from objectRegistry " << this->name()
145                 << " failed\n    available objects of type " << Type::typeName
146                 << " are" << nl
147                 << names<Type>()
148                 << abort(FatalError);
149         }
150     }
152     const Type* dummyPtr_ = NULL;
153     return *dummyPtr_;
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 } // End namespace Foam
161 // ************************************************************************* //