| 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 24 matching lines...) Expand all Loading... |
| 35 using reference = typename Container::reference; | 35 using reference = typename Container::reference; |
| 36 using const_reference = typename Container::const_reference; | 36 using const_reference = typename Container::const_reference; |
| 37 using key_type = typename Container::key_type; | 37 using key_type = typename Container::key_type; |
| 38 using mapped_type = ScopedPtr; | 38 using mapped_type = ScopedPtr; |
| 39 using key_compare = typename Container::key_compare; | 39 using key_compare = typename Container::key_compare; |
| 40 using const_iterator = typename Container::const_iterator; | 40 using const_iterator = typename Container::const_iterator; |
| 41 using const_reverse_iterator = typename Container::const_reverse_iterator; | 41 using const_reverse_iterator = typename Container::const_reverse_iterator; |
| 42 | 42 |
| 43 ScopedPtrMap() {} | 43 ScopedPtrMap() {} |
| 44 ~ScopedPtrMap() { clear(); } | 44 ~ScopedPtrMap() { clear(); } |
| 45 ScopedPtrMap(ScopedPtrMap<Key, ScopedPtr>&& other) { swap(other); } | 45 ScopedPtrMap(ScopedPtrMap&& other) { swap(other); } |
| 46 | 46 |
| 47 ScopedPtrMap& operator=(ScopedPtrMap<Key, ScopedPtr>&& rhs) { | 47 ScopedPtrMap& operator=(ScopedPtrMap&& rhs) { |
| 48 swap(rhs); | 48 swap(rhs); |
| 49 return *this; | 49 return *this; |
| 50 } | 50 } |
| 51 | 51 |
| 52 const_iterator find(const Key& k) const { return data_.find(k); } | 52 const_iterator find(const Key& k) const { return data_.find(k); } |
| 53 size_type count(const Key& k) const { return data_.count(k); } | 53 size_type count(const Key& k) const { return data_.count(k); } |
| 54 | 54 |
| 55 bool empty() const { return data_.empty(); } | 55 bool empty() const { return data_.empty(); } |
| 56 size_t size() const { return data_.size(); } | 56 size_t size() const { return data_.size(); } |
| 57 | 57 |
| 58 const_reverse_iterator rbegin() const { return data_.rbegin(); } | 58 const_reverse_iterator rbegin() const { return data_.rbegin(); } |
| 59 const_reverse_iterator rend() const { return data_.rend(); } | 59 const_reverse_iterator rend() const { return data_.rend(); } |
| 60 | 60 |
| 61 const_iterator begin() const { return data_.begin(); } | 61 const_iterator begin() const { return data_.begin(); } |
| 62 const_iterator end() const { return data_.end(); } | 62 const_iterator end() const { return data_.end(); } |
| 63 | 63 |
| 64 void swap(ScopedPtrMap<Key, ScopedPtr>& 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 } |
| (...skipping 60 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 |