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
00027 #include "DictionaryBase.H"
00028
00029
00030
00031 template<class IDLListType, class T>
00032 void Foam::DictionaryBase<IDLListType, T>::addEntries()
00033 {
00034 for
00035 (
00036 typename IDLListType::iterator iter = this->begin();
00037 iter != this->end();
00038 ++iter
00039 )
00040 {
00041 this->hashedTs_.insert((*iter).keyword(), &(*iter));
00042 }
00043 }
00044
00045
00046
00047
00048 template<class IDLListType, class T>
00049 Foam::DictionaryBase<IDLListType, T>::DictionaryBase()
00050 {}
00051
00052
00053 template<class IDLListType, class T>
00054 Foam::DictionaryBase<IDLListType, T>::DictionaryBase
00055 (
00056 const DictionaryBase& dict
00057 )
00058 :
00059 IDLListType(dict)
00060 {
00061 addEntries();
00062 }
00063
00064
00065 template<class IDLListType, class T>
00066 template<class INew>
00067 Foam::DictionaryBase<IDLListType, T>::DictionaryBase
00068 (
00069 Istream& is,
00070 const INew& iNew
00071 )
00072 :
00073 IDLListType(is, iNew)
00074 {
00075 addEntries();
00076 }
00077
00078
00079 template<class IDLListType, class T>
00080 Foam::DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is)
00081 :
00082 IDLListType(is)
00083 {
00084 addEntries();
00085 }
00086
00087
00088
00089
00090
00091 template<class IDLListType, class T>
00092 bool Foam::DictionaryBase<IDLListType, T>::found(const word& keyword) const
00093 {
00094 return hashedTs_.found(keyword);
00095 }
00096
00097
00098
00099 template<class IDLListType, class T>
00100 const T* Foam::DictionaryBase<IDLListType, T>::lookupPtr
00101 (
00102 const word& keyword
00103 ) const
00104 {
00105 typename HashTable<T*>::const_iterator iter = hashedTs_.find(keyword);
00106
00107 if (iter != hashedTs_.end())
00108 {
00109 return *iter;
00110 }
00111 else
00112 {
00113 return NULL;
00114 }
00115 }
00116
00117
00118
00119 template<class IDLListType, class T>
00120 T* Foam::DictionaryBase<IDLListType, T>::lookupPtr(const word& keyword)
00121 {
00122 typename HashTable<T*>::iterator iter = hashedTs_.find(keyword);
00123
00124 if (iter != hashedTs_.end())
00125 {
00126 return *iter;
00127 }
00128 else
00129 {
00130 return NULL;
00131 }
00132 }
00133
00134
00135
00136 template<class IDLListType, class T>
00137 const T* Foam::DictionaryBase<IDLListType, T>::lookup(const word& keyword) const
00138 {
00139 typename HashTable<T*>::const_iterator iter = hashedTs_.find(keyword);
00140
00141 if (iter == hashedTs_.end())
00142 {
00143 FatalErrorIn
00144 (
00145 "DictionaryBase<IDLListType, T>::lookup(const word&) const"
00146 ) << keyword << " is undefined"
00147 << exit(FatalError);
00148 }
00149
00150 return *iter;
00151 }
00152
00153
00154
00155 template<class IDLListType, class T>
00156 T* Foam::DictionaryBase<IDLListType, T>::lookup(const word& keyword)
00157 {
00158 typename HashTable<T*>::iterator iter = hashedTs_.find(keyword);
00159
00160 if (iter == hashedTs_.end())
00161 {
00162 FatalErrorIn
00163 (
00164 "DictionaryBase<IDLListType, T>::lookup(const word&)"
00165 ) << keyword << " is undefined"
00166 << exit(FatalError);
00167 }
00168
00169 return *iter;
00170 }
00171
00172
00173
00174 template<class IDLListType, class T>
00175 Foam::wordList Foam::DictionaryBase<IDLListType, T>::toc() const
00176 {
00177 wordList keywords(this->size());
00178
00179 label i = 0;
00180 for
00181 (
00182 typename IDLListType::const_iterator iter = this->begin();
00183 iter != this->end();
00184 ++iter
00185 )
00186 {
00187 keywords[i++] = iter().keyword();
00188 }
00189
00190 return keywords;
00191 }
00192
00193
00194
00195 template<class IDLListType, class T>
00196 void Foam::DictionaryBase<IDLListType, T>::insert(const word& keyword, T* tPtr)
00197 {
00198
00199 hashedTs_.insert(keyword, tPtr);
00200 IDLListType::insert(tPtr);
00201 }
00202
00203
00204
00205 template<class IDLListType, class T>
00206 void Foam::DictionaryBase<IDLListType, T>::append(const word& keyword, T* tPtr)
00207 {
00208
00209 hashedTs_.insert(keyword, tPtr);
00210 IDLListType::append(tPtr);
00211 }
00212
00213
00214 template<class IDLListType, class T>
00215 T* Foam::DictionaryBase<IDLListType, T>::remove(const word& keyword)
00216 {
00217 typename HashTable<T*>::iterator iter = hashedTs_.find(keyword);
00218
00219 if (iter != hashedTs_.end())
00220 {
00221 T* tPtr = IDLListType::remove(iter());
00222 hashedTs_.erase(iter);
00223 return tPtr;
00224 }
00225 else
00226 {
00227 return NULL;
00228 }
00229 }
00230
00231
00232 template<class IDLListType, class T>
00233 void Foam::DictionaryBase<IDLListType, T>::clear()
00234 {
00235 IDLListType::clear();
00236 hashedTs_.clear();
00237 }
00238
00239
00240 template<class IDLListType, class T>
00241 void Foam::DictionaryBase<IDLListType, T>::transfer
00242 (
00243 DictionaryBase<IDLListType, T>& dict
00244 )
00245 {
00246 IDLListType::transfer(dict);
00247 hashedTs_.transfer(dict.hashedTs_);
00248 }
00249
00250
00251
00252
00253 template<class IDLListType, class T>
00254 void Foam::DictionaryBase<IDLListType, T>::operator=
00255 (
00256 const DictionaryBase<IDLListType, T>& dict
00257 )
00258 {
00259
00260 if (this == &dict)
00261 {
00262 FatalErrorIn("DictionaryBase::operator=(const DictionaryBase&)")
00263 << "attempted assignment to self"
00264 << abort(FatalError);
00265 }
00266
00267 IDLListType::operator=(dict);
00268 this->hashedTs_.clear();
00269 this->addEntries();
00270 }
00271
00272
00273
00274
00275 #include "DictionaryBaseIO.C"
00276
00277