OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_LIST_CONTAINER_H_ | 5 #ifndef CC_BASE_LIST_CONTAINER_H_ |
6 #define CC_BASE_LIST_CONTAINER_H_ | 6 #define CC_BASE_LIST_CONTAINER_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 protected: | 137 protected: |
138 // This is used to track how many increment has happened since rbegin(). It | 138 // This is used to track how many increment has happened since rbegin(). It |
139 // is used to avoid double increment at places an index reference is | 139 // is used to avoid double increment at places an index reference is |
140 // needed. For reverse iterator this means rbegin() corresponds to index 0 | 140 // needed. For reverse iterator this means rbegin() corresponds to index 0 |
141 // and rend() corresponds to index |size|. | 141 // and rend() corresponds to index |size|. |
142 size_t index_; | 142 size_t index_; |
143 }; | 143 }; |
144 | 144 |
145 // Unlike the ListContainer methods, these do not invoke element destructors. | 145 // Unlike the ListContainer methods, these do not invoke element destructors. |
146 void RemoveLast(); | 146 void RemoveLast(); |
147 void EraseAndInvalidateAllPointers(Iterator position); | 147 void EraseAndInvalidateAllPointers(Iterator* position); |
148 void InsertBeforeAndInvalidateAllPointers(Iterator* position, | 148 void InsertBeforeAndInvalidateAllPointers(Iterator* position, |
149 size_t number_of_elements); | 149 size_t number_of_elements); |
150 | 150 |
151 ConstReverseIterator crbegin() const; | 151 ConstReverseIterator crbegin() const; |
152 ConstReverseIterator crend() const; | 152 ConstReverseIterator crend() const; |
153 ReverseIterator rbegin(); | 153 ReverseIterator rbegin(); |
154 ReverseIterator rend(); | 154 ReverseIterator rend(); |
155 ConstIterator cbegin() const; | 155 ConstIterator cbegin() const; |
156 ConstIterator cend() const; | 156 ConstIterator cend() const; |
157 Iterator begin(); | 157 Iterator begin(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 // Removes the last element of the list and makes its space available for | 219 // Removes the last element of the list and makes its space available for |
220 // allocation. | 220 // allocation. |
221 void RemoveLast() { | 221 void RemoveLast() { |
222 DCHECK(!empty()); | 222 DCHECK(!empty()); |
223 back()->~BaseElementType(); | 223 back()->~BaseElementType(); |
224 ListContainerBase::RemoveLast(); | 224 ListContainerBase::RemoveLast(); |
225 } | 225 } |
226 | 226 |
227 // When called, all raw pointers that have been handed out are no longer | 227 // When called, all raw pointers that have been handed out are no longer |
228 // valid. Use with caution. | 228 // valid. Use with caution. |
229 // This function does not deallocate memory. | 229 // This function does not deallocate memory. |
ccameron
2015/09/02 21:41:55
I'd pass position by pointer here (to match Insert
Andre
2015/09/02 21:54:51
Hmm, but ListContainer::InsertBefore below returns
Andre
2015/09/02 22:08:52
Also, making it take a pointer would make code lik
ccameron
2015/09/02 22:22:33
Yes, you're right, that was a bad suggestion.
May
Andre
2015/09/03 22:45:59
Done. This was split off into another CL.
| |
230 void EraseAndInvalidateAllPointers(Iterator position) { | 230 Iterator EraseAndInvalidateAllPointers(Iterator position) { |
231 BaseElementType* item = *position; | 231 BaseElementType* item = *position; |
232 item->~BaseElementType(); | 232 item->~BaseElementType(); |
233 ListContainerBase::EraseAndInvalidateAllPointers(position); | 233 ListContainerBase::EraseAndInvalidateAllPointers(&position); |
234 return position; | |
234 } | 235 } |
235 | 236 |
236 ConstReverseIterator crbegin() const { | 237 ConstReverseIterator crbegin() const { |
237 return ConstReverseIterator(ListContainerBase::crbegin()); | 238 return ConstReverseIterator(ListContainerBase::crbegin()); |
238 } | 239 } |
239 ConstReverseIterator crend() const { | 240 ConstReverseIterator crend() const { |
240 return ConstReverseIterator(ListContainerBase::crend()); | 241 return ConstReverseIterator(ListContainerBase::crend()); |
241 } | 242 } |
242 ConstReverseIterator rbegin() const { return crbegin(); } | 243 ConstReverseIterator rbegin() const { return crbegin(); } |
243 ConstReverseIterator rend() const { return crend(); } | 244 ConstReverseIterator rend() const { return crend(); } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 ListContainerBase::ConstReverseIterator base_iterator) | 491 ListContainerBase::ConstReverseIterator base_iterator) |
491 : ListContainerBase::ConstReverseIterator(base_iterator) {} | 492 : ListContainerBase::ConstReverseIterator(base_iterator) {} |
492 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; | 493 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; |
493 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; | 494 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; |
494 }; | 495 }; |
495 }; | 496 }; |
496 | 497 |
497 } // namespace cc | 498 } // namespace cc |
498 | 499 |
499 #endif // CC_BASE_LIST_CONTAINER_H_ | 500 #endif // CC_BASE_LIST_CONTAINER_H_ |
OLD | NEW |