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 <OpenFOAM/error.H>
00027 #include "HashPtrTable.H"
00028 
00029 
00030 
00031 
00032 template<class T, class Key, class Hash>
00033 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const label size)
00034 :
00035     HashTable<T*, Key, Hash>(size)
00036 {}
00037 
00038 
00039 
00040 template<class T, class Key, class Hash>
00041 Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
00042 (
00043     const HashPtrTable<T, Key, Hash>& ht
00044 )
00045 :
00046     HashTable<T*, Key, Hash>()
00047 {
00048     for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
00049     {
00050         this->insert(iter.key(), new T(**iter));
00051     }
00052 }
00053 
00054 
00055 
00056 
00057 template<class T, class Key, class Hash>
00058 Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
00059 {
00060     clear();
00061 }
00062 
00063 
00064 
00065 
00066 template<class T, class Key, class Hash>
00067 T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& it)
00068 {
00069     T* elemPtr = *it;
00070     HashTable<T*, Key, Hash>::erase(it);
00071     return elemPtr;
00072 }
00073 
00074 
00075 template<class T, class Key, class Hash>
00076 bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& it)
00077 {
00078     T* elemPtr = *it;
00079 
00080     if (HashTable<T*, Key, Hash>::erase(it))
00081     {
00082         if (elemPtr)
00083         {
00084             delete elemPtr;
00085         }
00086 
00087         return true;
00088     }
00089     else
00090     {
00091         return false;
00092     }
00093 }
00094 
00095 
00096 template<class T, class Key, class Hash>
00097 void Foam::HashPtrTable<T, Key, Hash>::clear()
00098 {
00099     for
00100     (
00101         iterator iter = this->begin();
00102         iter != this->end();
00103         ++iter
00104     )
00105     {
00106         delete *iter;
00107     }
00108 
00109     HashTable<T*, Key, Hash>::clear();
00110 }
00111 
00112 
00113 
00114 
00115 template<class T, class Key, class Hash>
00116 void Foam::HashPtrTable<T, Key, Hash>::operator=
00117 (
00118     const HashPtrTable<T, Key, Hash>& rhs
00119 )
00120 {
00121     
00122     if (this == &rhs)
00123     {
00124         FatalErrorIn
00125         (
00126             "HashPtrTable<T, Key, Hash>::operator="
00127             "(const HashPtrTable<T, Key, Hash>&)"
00128         )   << "attempted assignment to self"
00129             << abort(FatalError);
00130     }
00131 
00132     clear();
00133 
00134     for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
00135     {
00136         this->insert(iter.key(), new T(**iter));
00137     }
00138 }
00139 
00140 
00141 
00142 #include "HashPtrTableIO.C"
00143 
00144