FreeFOAM The Cross-Platform CFD Toolkit
objectRegistryTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "objectRegistry.H"
27 
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
34 {
35  wordList objectNames(size());
36 
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  }
45 
46  objectNames.setSize(count);
47 
48  return objectNames;
49 }
50 
51 
52 template<class Type>
55 {
56  HashTable<const Type*> objectsOfClass(size());
57 
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  }
69 
70  return objectsOfClass;
71 }
72 
73 
74 template<class Type>
76 {
77  const_iterator iter = find(name);
78 
79  if (iter != end())
80  {
81  const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
82 
83  if (vpsiPtr_)
84  {
85  return true;
86  }
87  else
88  {
89  return false;
90  }
91  }
92  else
93  {
94  if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
95  {
96  return parent_.foundObject<Type>(name);
97  }
98  else
99  {
100  return false;
101  }
102  }
103 }
104 
105 
106 template<class Type>
108 {
109  const_iterator iter = find(name);
110 
111  if (iter != end())
112  {
113  const Type* vpsiPtr_ = dynamic_cast<const Type*>(iter());
114 
115  if (vpsiPtr_)
116  {
117  return *vpsiPtr_;
118  }
119 
120  FatalErrorIn("objectRegistry::lookupObject<Type>(const word&) const")
121  << nl
122  << " lookup of " << name << " from objectRegistry "
123  << this->name()
124  << " successful\n but it is not a " << Type::typeName
125  << ", it is a " << iter()->type()
126  << abort(FatalError);
127  }
128  else
129  {
130  if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
131  {
132  return parent_.lookupObject<Type>(name);
133  }
134  else
135  {
137  (
138  "objectRegistry::lookupObject<Type>(const word&) const"
139  ) << nl
140  << " request for " << Type::typeName
141  << " " << name << " from objectRegistry " << this->name()
142  << " failed\n available objects of type " << Type::typeName
143  << " are" << nl
144  << names<Type>()
145  << abort(FatalError);
146  }
147  }
148 
149  return *reinterpret_cast< const Type* >(0);
150 }
151 
152 
153 // ************************ vim: set sw=4 sts=4 et: ************************ //