Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "objectRegistry.H"
00027
00028
00029
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