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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 289 } |
290 | 290 |
291 template <typename DerivedElementType> | 291 template <typename DerivedElementType> |
292 void swap(ListContainer<DerivedElementType>& other) { | 292 void swap(ListContainer<DerivedElementType>& other) { |
293 data_.swap(other.data_); | 293 data_.swap(other.data_); |
294 } | 294 } |
295 | 295 |
296 // Appends a new item without copying. The original item will not be | 296 // Appends a new item without copying. The original item will not be |
297 // destructed and will be replaced with a new DerivedElementType. The | 297 // destructed and will be replaced with a new DerivedElementType. The |
298 // DerivedElementType does not have to match the moved type as a full block | 298 // DerivedElementType does not have to match the moved type as a full block |
299 // of memory will be moved (up to MaxSizeForDerivedClass()). | 299 // of memory will be moved (up to MaxSizeForDerivedClass()). A pointer to |
| 300 // the moved element is returned. |
300 template <typename DerivedElementType> | 301 template <typename DerivedElementType> |
301 void AppendByMoving(DerivedElementType* item) { | 302 DerivedElementType* AppendByMoving(DerivedElementType* item) { |
302 size_t max_size_for_derived_class = MaxSizeForDerivedClass(); | 303 size_t max_size_for_derived_class = MaxSizeForDerivedClass(); |
303 void* new_item = Allocate(max_size_for_derived_class); | 304 void* new_item = Allocate(max_size_for_derived_class); |
304 memcpy(new_item, static_cast<void*>(item), max_size_for_derived_class); | 305 memcpy(new_item, static_cast<void*>(item), max_size_for_derived_class); |
305 // Construct a new element in-place so it can be destructed safely. | 306 // Construct a new element in-place so it can be destructed safely. |
306 new (item) DerivedElementType; | 307 new (item) DerivedElementType; |
| 308 return static_cast<DerivedElementType*>(new_item); |
307 } | 309 } |
308 | 310 |
309 using ListContainerBase::size; | 311 using ListContainerBase::size; |
310 using ListContainerBase::empty; | 312 using ListContainerBase::empty; |
311 | 313 |
312 void clear() { | 314 void clear() { |
313 for (Iterator i = begin(); i != end(); ++i) { | 315 for (Iterator i = begin(); i != end(); ++i) { |
314 i->~BaseElementType(); | 316 i->~BaseElementType(); |
315 } | 317 } |
316 ListContainerBase::clear(); | 318 ListContainerBase::clear(); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 ListContainerBase::ConstReverseIterator base_iterator) | 471 ListContainerBase::ConstReverseIterator base_iterator) |
470 : ListContainerBase::ConstReverseIterator(base_iterator) {} | 472 : ListContainerBase::ConstReverseIterator(base_iterator) {} |
471 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; | 473 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; |
472 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; | 474 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; |
473 }; | 475 }; |
474 }; | 476 }; |
475 | 477 |
476 } // namespace cc | 478 } // namespace cc |
477 | 479 |
478 #endif // CC_BASE_LIST_CONTAINER_H_ | 480 #endif // CC_BASE_LIST_CONTAINER_H_ |
OLD | NEW |