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