Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 BASE_MEMORY_SCOPED_VECTOR_H_ | 5 #ifndef BASE_MEMORY_SCOPED_VECTOR_H_ |
| 6 #define BASE_MEMORY_SCOPED_VECTOR_H_ | 6 #define BASE_MEMORY_SCOPED_VECTOR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 66 |
| 67 std::vector<T*>& get() { return v; } | 67 std::vector<T*>& get() { return v; } |
| 68 const std::vector<T*>& get() const { return v; } | 68 const std::vector<T*>& get() const { return v; } |
| 69 void swap(std::vector<T*>& other) { v.swap(other); } | 69 void swap(std::vector<T*>& other) { v.swap(other); } |
| 70 void swap(ScopedVector<T>& other) { v.swap(other.v); } | 70 void swap(ScopedVector<T>& other) { v.swap(other.v); } |
| 71 void release(std::vector<T*>* out) { | 71 void release(std::vector<T*>* out) { |
| 72 out->swap(v); | 72 out->swap(v); |
| 73 v.clear(); | 73 v.clear(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void reset() { STLDeleteElements(&v); } | 76 void reset() { clear(); } |
| 77 void reserve(size_t capacity) { v.reserve(capacity); } | 77 void reserve(size_t capacity) { v.reserve(capacity); } |
| 78 void resize(size_t new_size) { v.resize(new_size); } | 78 void resize(size_t new_size) { v.resize(new_size); } |
| 79 | 79 |
| 80 template<typename InputIterator> | 80 template<typename InputIterator> |
| 81 void assign(InputIterator begin, InputIterator end) { | 81 void assign(InputIterator begin, InputIterator end) { |
| 82 v.assign(begin, end); | 82 v.assign(begin, end); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void clear() { v.clear(); } | 85 void clear() { STLDeleteElements(&v); } |
|
sky
2012/07/18 21:24:38
Any chance we could get rid of one of reset or cle
Peter Kasting
2012/07/18 21:26:32
(I suggest nuking reset())
| |
| 86 | |
| 87 // Like |clear()|, but doesn't delete any elements. | |
| 88 void weak_clear() { v.clear(); } | |
| 86 | 89 |
| 87 // Lets the ScopedVector take ownership of |x|. | 90 // Lets the ScopedVector take ownership of |x|. |
| 88 iterator insert(iterator position, T* x) { | 91 iterator insert(iterator position, T* x) { |
| 89 return v.insert(position, x); | 92 return v.insert(position, x); |
| 90 } | 93 } |
| 91 | 94 |
| 92 // Lets the ScopedVector take ownership of elements in [first,last). | 95 // Lets the ScopedVector take ownership of elements in [first,last). |
| 93 template<typename InputIterator> | 96 template<typename InputIterator> |
| 94 void insert(iterator position, InputIterator first, InputIterator last) { | 97 void insert(iterator position, InputIterator first, InputIterator last) { |
| 95 v.insert(position, first, last); | 98 v.insert(position, first, last); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 113 // Like |erase()|, but doesn't delete the elements in [first, last). | 116 // Like |erase()|, but doesn't delete the elements in [first, last). |
| 114 iterator weak_erase(iterator first, iterator last) { | 117 iterator weak_erase(iterator first, iterator last) { |
| 115 return v.erase(first, last); | 118 return v.erase(first, last); |
| 116 } | 119 } |
| 117 | 120 |
| 118 private: | 121 private: |
| 119 std::vector<T*> v; | 122 std::vector<T*> v; |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 #endif // BASE_MEMORY_SCOPED_VECTOR_H_ | 125 #endif // BASE_MEMORY_SCOPED_VECTOR_H_ |
| OLD | NEW |