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