| 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_VECTOR_H_ | 5 #ifndef CC_BASE_SCOPED_PTR_VECTOR_H_ |
| 6 #define CC_BASE_SCOPED_PTR_VECTOR_H_ | 6 #define CC_BASE_SCOPED_PTR_VECTOR_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 DCHECK(!empty()); | 65 DCHECK(!empty()); |
| 66 return at(size() - 1); | 66 return at(size() - 1); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool empty() const { | 69 bool empty() const { |
| 70 return data_.empty(); | 70 return data_.empty(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 scoped_ptr<T> take(iterator position) { | 73 scoped_ptr<T> take(iterator position) { |
| 74 if (position == end()) | 74 if (position == end()) |
| 75 return scoped_ptr<T>(); | 75 return nullptr; |
| 76 DCHECK(position < end()); | 76 DCHECK(position < end()); |
| 77 | 77 |
| 78 typename std::vector<T*>::iterator writable_position = position; | 78 typename std::vector<T*>::iterator writable_position = position; |
| 79 scoped_ptr<T> ret(*writable_position); | 79 scoped_ptr<T> ret(*writable_position); |
| 80 *writable_position = NULL; | 80 *writable_position = NULL; |
| 81 return ret.Pass(); | 81 return ret.Pass(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 scoped_ptr<T> take_back() { | 84 scoped_ptr<T> take_back() { |
| 85 DCHECK(!empty()); | 85 DCHECK(!empty()); |
| 86 if (empty()) | 86 if (empty()) |
| 87 return scoped_ptr<T>(NULL); | 87 return nullptr; |
| 88 return take(end() - 1); | 88 return take(end() - 1); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void erase(iterator position) { | 91 void erase(iterator position) { |
| 92 if (position == end()) | 92 if (position == end()) |
| 93 return; | 93 return; |
| 94 typename std::vector<T*>::iterator writable_position = position; | 94 typename std::vector<T*>::iterator writable_position = position; |
| 95 delete *writable_position; | 95 delete *writable_position; |
| 96 data_.erase(position); | 96 data_.erase(position); |
| 97 } | 97 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 private: | 192 private: |
| 193 std::vector<T*> data_; | 193 std::vector<T*> data_; |
| 194 | 194 |
| 195 DISALLOW_COPY_AND_ASSIGN(ScopedPtrVector); | 195 DISALLOW_COPY_AND_ASSIGN(ScopedPtrVector); |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 } // namespace cc | 198 } // namespace cc |
| 199 | 199 |
| 200 #endif // CC_BASE_SCOPED_PTR_VECTOR_H_ | 200 #endif // CC_BASE_SCOPED_PTR_VECTOR_H_ |
| OLD | NEW |