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 15 matching lines...) Expand all Loading... |
26 const_reverse_iterator; | 26 const_reverse_iterator; |
27 | 27 |
28 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
29 // On Android the iterator is not a class, so we can't block assignment. | 29 // On Android the iterator is not a class, so we can't block assignment. |
30 typedef typename std::vector<T*>::iterator iterator; | 30 typedef typename std::vector<T*>::iterator iterator; |
31 #else | 31 #else |
32 // Ban setting values on the iterator directly. New pointers must be passed | 32 // Ban setting values on the iterator directly. New pointers must be passed |
33 // to methods on the ScopedPtrVector class to appear in the vector. | 33 // to methods on the ScopedPtrVector class to appear in the vector. |
34 class iterator : public std::vector<T*>::iterator { | 34 class iterator : public std::vector<T*>::iterator { |
35 public: | 35 public: |
36 iterator(const typename std::vector<T*>::iterator& other) | 36 iterator(const typename std::vector<T*>::iterator& other) // NOLINT |
37 : std::vector<T*>::iterator(other) {} | 37 : std::vector<T*>::iterator(other) {} |
38 T* const& operator*() { return std::vector<T*>::iterator::operator*(); } | 38 T* const& operator*() { return std::vector<T*>::iterator::operator*(); } |
39 }; | 39 }; |
40 #endif | 40 #endif |
41 | 41 |
42 ScopedPtrVector() {} | 42 ScopedPtrVector() {} |
43 | 43 |
44 ~ScopedPtrVector() { clear(); } | 44 ~ScopedPtrVector() { clear(); } |
45 | 45 |
46 size_t size() const { | 46 size_t size() const { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void pop_back() { | 122 void pop_back() { |
123 delete data_.back(); | 123 delete data_.back(); |
124 data_.pop_back(); | 124 data_.pop_back(); |
125 } | 125 } |
126 | 126 |
127 void insert(iterator position, scoped_ptr<T> item) { | 127 void insert(iterator position, scoped_ptr<T> item) { |
128 DCHECK(position <= end()); | 128 DCHECK(position <= end()); |
129 data_.insert(position, item.release()); | 129 data_.insert(position, item.release()); |
130 } | 130 } |
131 | 131 |
| 132 void insert_and_take(iterator position, |
| 133 ScopedPtrVector<T>& other) { |
| 134 std::vector<T*> tmp_data; |
| 135 for (ScopedPtrVector<T>::iterator it = other.begin(); |
| 136 it != other.end(); |
| 137 ++it) { |
| 138 tmp_data.push_back(other.take(it).release()); |
| 139 } |
| 140 data_.insert(position, tmp_data.begin(), tmp_data.end()); |
| 141 } |
| 142 |
132 void swap(ScopedPtrVector<T>& other) { | 143 void swap(ScopedPtrVector<T>& other) { |
133 data_.swap(other.data_); | 144 data_.swap(other.data_); |
134 } | 145 } |
135 | 146 |
136 void swap(iterator a, iterator b) { | 147 void swap(iterator a, iterator b) { |
137 DCHECK(a < end()); | 148 DCHECK(a < end()); |
138 DCHECK(b < end()); | 149 DCHECK(b < end()); |
139 if (a == end() || b == end() || a == b) | 150 if (a == end() || b == end() || a == b) |
140 return; | 151 return; |
141 typename std::vector<T*>::iterator writable_a = a; | 152 typename std::vector<T*>::iterator writable_a = a; |
(...skipping 18 matching lines...) Expand all Loading... |
160 | 171 |
161 private: | 172 private: |
162 std::vector<T*> data_; | 173 std::vector<T*> data_; |
163 | 174 |
164 DISALLOW_COPY_AND_ASSIGN(ScopedPtrVector); | 175 DISALLOW_COPY_AND_ASSIGN(ScopedPtrVector); |
165 }; | 176 }; |
166 | 177 |
167 } // namespace cc | 178 } // namespace cc |
168 | 179 |
169 #endif // CC_BASE_SCOPED_PTR_VECTOR_H_ | 180 #endif // CC_BASE_SCOPED_PTR_VECTOR_H_ |
OLD | NEW |