OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_CONTAINERS_SCOPED_PTR_HASH_MAP_H_ | 5 #ifndef BASE_CONTAINERS_SCOPED_PTR_HASH_MAP_H_ |
6 #define BASE_CONTAINERS_SCOPED_PTR_HASH_MAP_H_ | 6 #define BASE_CONTAINERS_SCOPED_PTR_HASH_MAP_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if (it == end()) | 121 if (it == end()) |
122 return NULL; | 122 return NULL; |
123 return it->second; | 123 return it->second; |
124 } | 124 } |
125 | 125 |
126 inline bool contains(const Key& k) const { return data_.count(k) > 0; } | 126 inline bool contains(const Key& k) const { return data_.count(k) > 0; } |
127 | 127 |
128 inline void clear() { | 128 inline void clear() { |
129 auto it = data_.begin(); | 129 auto it = data_.begin(); |
130 while (it != data_.end()) { | 130 while (it != data_.end()) { |
131 // NOTE: Like STLDeleteContainerPointers, deleting behind the iterator. | 131 // NOTE: Deleting behind the iterator. Deleting the value does not always |
132 // Deleting the value does not always invalidate the iterator, but it may | 132 // invalidate the iterator, but it may do so if the key is a pointer into |
133 // do so if the key is a pointer into the value object. | 133 // the value object. |
134 auto temp = it; | 134 auto temp = it; |
135 ++it; | 135 ++it; |
136 // Let ScopedPtr decide how to delete. | 136 // Let ScopedPtr decide how to delete. |
137 ScopedPtr(temp->second).reset(); | 137 ScopedPtr(temp->second).reset(); |
138 } | 138 } |
139 data_.clear(); | 139 data_.clear(); |
140 } | 140 } |
141 | 141 |
142 inline const_iterator find(const Key& k) const { return data_.find(k); } | 142 inline const_iterator find(const Key& k) const { return data_.find(k); } |
143 inline iterator find(const Key& k) { return data_.find(k); } | 143 inline iterator find(const Key& k) { return data_.find(k); } |
(...skipping 22 matching lines...) Expand all Loading... |
166 | 166 |
167 private: | 167 private: |
168 Container data_; | 168 Container data_; |
169 | 169 |
170 DISALLOW_COPY_AND_ASSIGN(ScopedPtrHashMap); | 170 DISALLOW_COPY_AND_ASSIGN(ScopedPtrHashMap); |
171 }; | 171 }; |
172 | 172 |
173 } // namespace base | 173 } // namespace base |
174 | 174 |
175 #endif // BASE_CONTAINERS_SCOPED_PTR_HASH_MAP_H_ | 175 #endif // BASE_CONTAINERS_SCOPED_PTR_HASH_MAP_H_ |
OLD | NEW |