| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_MAP_H_ | 5 #ifndef BASE_CONTAINERS_SCOPED_PTR_MAP_H_ |
| 6 #define BASE_CONTAINERS_SCOPED_PTR_MAP_H_ | 6 #define BASE_CONTAINERS_SCOPED_PTR_MAP_H_ |
| 7 | 7 |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 const_iterator end() const { return data_.end(); } | 62 const_iterator end() const { return data_.end(); } |
| 63 | 63 |
| 64 void swap(ScopedPtrMap& other) { data_.swap(other.data_); } | 64 void swap(ScopedPtrMap& other) { data_.swap(other.data_); } |
| 65 | 65 |
| 66 void clear() { STLDeleteValues(&data_); } | 66 void clear() { STLDeleteValues(&data_); } |
| 67 | 67 |
| 68 // Inserts |val| into the map, associated with |key|. | 68 // Inserts |val| into the map, associated with |key|. |
| 69 std::pair<const_iterator, bool> insert(const Key& key, ScopedPtr val) { | 69 std::pair<const_iterator, bool> insert(const Key& key, ScopedPtr val) { |
| 70 auto result = data_.insert(std::make_pair(key, val.get())); | 70 auto result = data_.insert(std::make_pair(key, val.get())); |
| 71 if (result.second) | 71 if (result.second) |
| 72 ignore_result(val.release()); | 72 ::ignore_result(val.release()); |
| 73 return result; | 73 return result; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Inserts |val| into the map, associated with |key|. Overwrites any existing | 76 // Inserts |val| into the map, associated with |key|. Overwrites any existing |
| 77 // element at |key|. | 77 // element at |key|. |
| 78 void set(const Key& key, ScopedPtr val) { | 78 void set(const Key& key, ScopedPtr val) { |
| 79 typename ScopedPtr::element_type*& val_ref = data_[key]; | 79 typename ScopedPtr::element_type*& val_ref = data_[key]; |
| 80 delete val_ref; | 80 delete val_ref; |
| 81 val_ref = val.release(); | 81 val_ref = val.release(); |
| 82 } | 82 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // in C++03 (get the key and do the lookup again). | 135 // in C++03 (get the key and do the lookup again). |
| 136 if (it == data_.end()) | 136 if (it == data_.end()) |
| 137 return data_.end(); | 137 return data_.end(); |
| 138 return data_.find(it->first); | 138 return data_.find(it->first); |
| 139 }; | 139 }; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace base | 142 } // namespace base |
| 143 | 143 |
| 144 #endif // BASE_CONTAINERS_SCOPED_PTR_MAP_H_ | 144 #endif // BASE_CONTAINERS_SCOPED_PTR_MAP_H_ |
| OLD | NEW |