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 #ifndef WTF_HashIterators_h
00028 #define WTF_HashIterators_h
00029
00030 namespace WTF {
00031
00032 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableConstKeysIterator;
00033 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableConstValuesIterator;
00034 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableKeysIterator;
00035 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableValuesIterator;
00036
00037 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableConstIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > {
00038 private:
00039 typedef std::pair<KeyType, MappedType> ValueType;
00040 public:
00041 typedef HashTableConstKeysIterator<HashTableType, KeyType, MappedType> Keys;
00042 typedef HashTableConstValuesIterator<HashTableType, KeyType, MappedType> Values;
00043
00044 HashTableConstIteratorAdapter(const typename HashTableType::const_iterator& impl) : m_impl(impl) {}
00045
00046 const ValueType* get() const { return (const ValueType*)m_impl.get(); }
00047 const ValueType& operator*() const { return *get(); }
00048 const ValueType* operator->() const { return get(); }
00049
00050 HashTableConstIteratorAdapter& operator++() { ++m_impl; return *this; }
00051
00052
00053 Keys keys() { return Keys(*this); }
00054 Values values() { return Values(*this); }
00055
00056 typename HashTableType::const_iterator m_impl;
00057 };
00058
00059 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > {
00060 private:
00061 typedef std::pair<KeyType, MappedType> ValueType;
00062 public:
00063 typedef HashTableKeysIterator<HashTableType, KeyType, MappedType> Keys;
00064 typedef HashTableValuesIterator<HashTableType, KeyType, MappedType> Values;
00065
00066 HashTableIteratorAdapter(const typename HashTableType::iterator& impl) : m_impl(impl) {}
00067
00068 ValueType* get() const { return (ValueType*)m_impl.get(); }
00069 ValueType& operator*() const { return *get(); }
00070 ValueType* operator->() const { return get(); }
00071
00072 HashTableIteratorAdapter& operator++() { ++m_impl; return *this; }
00073
00074
00075 operator HashTableConstIteratorAdapter<HashTableType, ValueType>() {
00076 typename HashTableType::const_iterator i = m_impl;
00077 return i;
00078 }
00079
00080 Keys keys() { return Keys(*this); }
00081 Values values() { return Values(*this); }
00082
00083 typename HashTableType::iterator m_impl;
00084 };
00085
00086 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableConstKeysIterator {
00087 private:
00088 typedef HashTableConstIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > ConstIterator;
00089
00090 public:
00091 HashTableConstKeysIterator(const ConstIterator& impl) : m_impl(impl) {}
00092
00093 const KeyType* get() const { return &(m_impl.get()->first); }
00094 const KeyType& operator*() const { return *get(); }
00095 const KeyType* operator->() const { return get(); }
00096
00097 HashTableConstKeysIterator& operator++() { ++m_impl; return *this; }
00098
00099
00100 ConstIterator m_impl;
00101 };
00102
00103 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableConstValuesIterator {
00104 private:
00105 typedef HashTableConstIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > ConstIterator;
00106
00107 public:
00108 HashTableConstValuesIterator(const ConstIterator& impl) : m_impl(impl) {}
00109
00110 const MappedType* get() const { return &(m_impl.get()->second); }
00111 const MappedType& operator*() const { return *get(); }
00112 const MappedType* operator->() const { return get(); }
00113
00114 HashTableConstValuesIterator& operator++() { ++m_impl; return *this; }
00115
00116
00117 ConstIterator m_impl;
00118 };
00119
00120 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableKeysIterator {
00121 private:
00122 typedef HashTableIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > Iterator;
00123 typedef HashTableConstIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > ConstIterator;
00124
00125 public:
00126 HashTableKeysIterator(const Iterator& impl) : m_impl(impl) {}
00127
00128 KeyType* get() const { return &(m_impl.get()->first); }
00129 KeyType& operator*() const { return *get(); }
00130 KeyType* operator->() const { return get(); }
00131
00132 HashTableKeysIterator& operator++() { ++m_impl; return *this; }
00133
00134
00135 operator HashTableConstKeysIterator<HashTableType, KeyType, MappedType>() {
00136 ConstIterator i = m_impl;
00137 return i;
00138 }
00139
00140 Iterator m_impl;
00141 };
00142
00143 template<typename HashTableType, typename KeyType, typename MappedType> struct HashTableValuesIterator {
00144 private:
00145 typedef HashTableIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > Iterator;
00146 typedef HashTableConstIteratorAdapter<HashTableType, std::pair<KeyType, MappedType> > ConstIterator;
00147
00148 public:
00149 HashTableValuesIterator(const Iterator& impl) : m_impl(impl) {}
00150
00151 MappedType* get() const { return &(m_impl.get()->second); }
00152 MappedType& operator*() const { return *get(); }
00153 MappedType* operator->() const { return get(); }
00154
00155 HashTableValuesIterator& operator++() { ++m_impl; return *this; }
00156
00157
00158 operator HashTableConstValuesIterator<HashTableType, KeyType, MappedType>() {
00159 ConstIterator i = m_impl;
00160 return i;
00161 }
00162
00163 Iterator m_impl;
00164 };
00165
00166 template<typename T, typename U, typename V>
00167 inline bool operator==(const HashTableConstKeysIterator<T, U, V>& a, const HashTableConstKeysIterator<T, U, V>& b)
00168 {
00169 return a.m_impl == b.m_impl;
00170 }
00171
00172 template<typename T, typename U, typename V>
00173 inline bool operator!=(const HashTableConstKeysIterator<T, U, V>& a, const HashTableConstKeysIterator<T, U, V>& b)
00174 {
00175 return a.m_impl != b.m_impl;
00176 }
00177
00178 template<typename T, typename U, typename V>
00179 inline bool operator==(const HashTableConstValuesIterator<T, U, V>& a, const HashTableConstValuesIterator<T, U, V>& b)
00180 {
00181 return a.m_impl == b.m_impl;
00182 }
00183
00184 template<typename T, typename U, typename V>
00185 inline bool operator!=(const HashTableConstValuesIterator<T, U, V>& a, const HashTableConstValuesIterator<T, U, V>& b)
00186 {
00187 return a.m_impl != b.m_impl;
00188 }
00189
00190 template<typename T, typename U, typename V>
00191 inline bool operator==(const HashTableKeysIterator<T, U, V>& a, const HashTableKeysIterator<T, U, V>& b)
00192 {
00193 return a.m_impl == b.m_impl;
00194 }
00195
00196 template<typename T, typename U, typename V>
00197 inline bool operator!=(const HashTableKeysIterator<T, U, V>& a, const HashTableKeysIterator<T, U, V>& b)
00198 {
00199 return a.m_impl != b.m_impl;
00200 }
00201
00202 template<typename T, typename U, typename V>
00203 inline bool operator==(const HashTableValuesIterator<T, U, V>& a, const HashTableValuesIterator<T, U, V>& b)
00204 {
00205 return a.m_impl == b.m_impl;
00206 }
00207
00208 template<typename T, typename U, typename V>
00209 inline bool operator!=(const HashTableValuesIterator<T, U, V>& a, const HashTableValuesIterator<T, U, V>& b)
00210 {
00211 return a.m_impl != b.m_impl;
00212 }
00213
00214
00215 }
00216
00217 #endif // WTF_HashIterators_h