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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 std::pair<Key, const scoped_ptr<Value> > pair) { | 35 std::pair<Key, const scoped_ptr<Value> > pair) { |
36 return data_.insert( | 36 return data_.insert( |
37 std::pair<Key, Value*>(pair.first, pair.second.release())); | 37 std::pair<Key, Value*>(pair.first, pair.second.release())); |
38 } | 38 } |
39 | 39 |
40 // Replaces value but not key if key is already present. | 40 // Replaces value but not key if key is already present. |
41 std::pair<iterator, bool> set(Key key, scoped_ptr<Value> data) { | 41 std::pair<iterator, bool> set(Key key, scoped_ptr<Value> data) { |
42 iterator it = find(key); | 42 iterator it = find(key); |
43 if (it != end()) | 43 if (it != end()) |
44 erase(it); | 44 erase(it); |
45 Value* rawPtr = data.release(); | 45 Value* raw_ptr = data.release(); |
46 return data_.insert(std::pair<Key, Value*>(key, rawPtr)); | 46 return data_.insert(std::pair<Key, Value*>(key, raw_ptr)); |
47 } | 47 } |
48 | 48 |
49 // Does nothing if key is already present | 49 // Does nothing if key is already present |
50 std::pair<iterator, bool> add(Key key, scoped_ptr<Value> data) { | 50 std::pair<iterator, bool> add(Key key, scoped_ptr<Value> data) { |
51 Value* rawPtr = data.release(); | 51 Value* raw_ptr = data.release(); |
52 return data_.insert(std::pair<Key, Value*>(key, rawPtr)); | 52 return data_.insert(std::pair<Key, Value*>(key, raw_ptr)); |
53 } | 53 } |
54 | 54 |
55 void erase(iterator it) { | 55 void erase(iterator it) { |
56 if (it->second) | 56 if (it->second) |
57 delete it->second; | 57 delete it->second; |
58 data_.erase(it); | 58 data_.erase(it); |
59 } | 59 } |
60 | 60 |
61 size_t erase(const Key& k) { | 61 size_t erase(const Key& k) { |
62 iterator it = data_.find(k); | 62 iterator it = data_.find(k); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 private: | 145 private: |
146 Container data_; | 146 Container data_; |
147 | 147 |
148 DISALLOW_COPY_AND_ASSIGN(ScopedPtrHashMap); | 148 DISALLOW_COPY_AND_ASSIGN(ScopedPtrHashMap); |
149 }; | 149 }; |
150 | 150 |
151 } // namespace cc | 151 } // namespace cc |
152 | 152 |
153 #endif // CC_BASE_SCOPED_PTR_HASH_MAP_H_ | 153 #endif // CC_BASE_SCOPED_PTR_HASH_MAP_H_ |
OLD | NEW |