OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 CC_BASE_SCOPED_PTR_HASH_MAP_H_ | 5 #ifndef CC_BASE_SCOPED_PTR_HASH_MAP_H_ |
6 #define CC_BASE_SCOPED_PTR_HASH_MAP_H_ | 6 #define CC_BASE_SCOPED_PTR_HASH_MAP_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 iterator it = data_.find(k); | 66 iterator it = data_.find(k); |
67 if (it == data_.end()) | 67 if (it == data_.end()) |
68 return 0; | 68 return 0; |
69 erase(it); | 69 erase(it); |
70 return 1; | 70 return 1; |
71 } | 71 } |
72 | 72 |
73 scoped_ptr<Value> take(iterator it) { | 73 scoped_ptr<Value> take(iterator it) { |
74 DCHECK(it != data_.end()); | 74 DCHECK(it != data_.end()); |
75 if (it == data_.end()) | 75 if (it == data_.end()) |
76 return scoped_ptr<Value>(NULL); | 76 return scoped_ptr<Value>(); |
77 | 77 |
78 Key key = it->first; | 78 Key key = it->first; |
79 scoped_ptr<Value> ret(it->second); | 79 scoped_ptr<Value> ret(it->second); |
80 data_.erase(it); | 80 data_.erase(it); |
81 data_.insert(std::pair<Key, Value*>(key, static_cast<Value*>(NULL))); | 81 data_.insert(std::pair<Key, Value*>(key, static_cast<Value*>(NULL))); |
82 return ret.Pass(); | 82 return ret.Pass(); |
83 } | 83 } |
84 | 84 |
85 scoped_ptr<Value> take(const Key& k) { | 85 scoped_ptr<Value> take(const Key& k) { |
86 iterator it = find(k); | 86 iterator it = find(k); |
87 if (it == data_.end()) | 87 if (it == data_.end()) |
88 return scoped_ptr<Value>(NULL); | 88 return scoped_ptr<Value>(); |
89 | 89 |
90 return take(it); | 90 return take(it); |
91 } | 91 } |
92 | 92 |
93 scoped_ptr<Value> take_and_erase(iterator it) { | 93 scoped_ptr<Value> take_and_erase(iterator it) { |
94 DCHECK(it != data_.end()); | 94 DCHECK(it != data_.end()); |
95 if (it == data_.end()) | 95 if (it == data_.end()) |
96 return scoped_ptr<Value>(NULL); | 96 return scoped_ptr<Value>(); |
97 | 97 |
98 scoped_ptr<Value> ret(it->second); | 98 scoped_ptr<Value> ret(it->second); |
99 data_.erase(it); | 99 data_.erase(it); |
100 return ret.Pass(); | 100 return ret.Pass(); |
101 } | 101 } |
102 | 102 |
103 scoped_ptr<Value> take_and_erase(const Key& k) { | 103 scoped_ptr<Value> take_and_erase(const Key& k) { |
104 iterator it = find(k); | 104 iterator it = find(k); |
105 if (it == data_.end()) | 105 if (it == data_.end()) |
106 return scoped_ptr<Value>(NULL); | 106 return scoped_ptr<Value>(); |
107 | 107 |
108 return take_and_erase(it); | 108 return take_and_erase(it); |
109 } | 109 } |
110 | 110 |
111 // Returns the first element in the hash_map that matches the given key. | 111 // Returns the first element in the hash_map that matches the given key. |
112 // If no such element exists it returns NULL. | 112 // If no such element exists it returns NULL. |
113 Value* get(const Key& k) const { | 113 Value* get(const Key& k) const { |
114 const_iterator it = find(k); | 114 const_iterator it = find(k); |
115 if (it == end()) | 115 if (it == end()) |
116 return 0; | 116 return 0; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 private: | 149 private: |
150 Container data_; | 150 Container data_; |
151 | 151 |
152 DISALLOW_COPY_AND_ASSIGN(ScopedPtrHashMap); | 152 DISALLOW_COPY_AND_ASSIGN(ScopedPtrHashMap); |
153 }; | 153 }; |
154 | 154 |
155 } // namespace cc | 155 } // namespace cc |
156 | 156 |
157 #endif // CC_BASE_SCOPED_PTR_HASH_MAP_H_ | 157 #endif // CC_BASE_SCOPED_PTR_HASH_MAP_H_ |
OLD | NEW |