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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 Iterator end(); | 156 Iterator end(); |
157 | 157 |
158 Iterator IteratorAt(size_t index); | 158 Iterator IteratorAt(size_t index); |
159 ConstIterator IteratorAt(size_t index) const; | 159 ConstIterator IteratorAt(size_t index) const; |
160 | 160 |
161 size_t size() const; | 161 size_t size() const; |
162 bool empty() const; | 162 bool empty() const; |
163 | 163 |
164 size_t MaxSizeForDerivedClass() const; | 164 size_t MaxSizeForDerivedClass() const; |
165 | 165 |
| 166 size_t GetCapacityInBytes() const; |
| 167 |
166 // Unlike the ListContainer method, this one does not invoke element | 168 // Unlike the ListContainer method, this one does not invoke element |
167 // destructors. | 169 // destructors. |
168 void clear(); | 170 void clear(); |
169 | 171 |
170 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; | 172 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; |
171 | 173 |
172 // Hands out memory location for an element at the end of data structure. | 174 // Hands out memory location for an element at the end of data structure. |
173 void* Allocate(size_t size_of_actual_element_in_bytes); | 175 void* Allocate(size_t size_of_actual_element_in_bytes); |
174 | 176 |
175 scoped_ptr<ListContainerCharAllocator> data_; | 177 scoped_ptr<ListContainerCharAllocator> data_; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 size_t max_size_for_derived_class = MaxSizeForDerivedClass(); | 305 size_t max_size_for_derived_class = MaxSizeForDerivedClass(); |
304 void* new_item = Allocate(max_size_for_derived_class); | 306 void* new_item = Allocate(max_size_for_derived_class); |
305 memcpy(new_item, static_cast<void*>(item), max_size_for_derived_class); | 307 memcpy(new_item, static_cast<void*>(item), max_size_for_derived_class); |
306 // Construct a new element in-place so it can be destructed safely. | 308 // Construct a new element in-place so it can be destructed safely. |
307 new (item) DerivedElementType; | 309 new (item) DerivedElementType; |
308 return static_cast<DerivedElementType*>(new_item); | 310 return static_cast<DerivedElementType*>(new_item); |
309 } | 311 } |
310 | 312 |
311 using ListContainerBase::size; | 313 using ListContainerBase::size; |
312 using ListContainerBase::empty; | 314 using ListContainerBase::empty; |
| 315 using ListContainerBase::GetCapacityInBytes; |
313 | 316 |
314 void clear() { | 317 void clear() { |
315 for (Iterator i = begin(); i != end(); ++i) { | 318 for (Iterator i = begin(); i != end(); ++i) { |
316 i->~BaseElementType(); | 319 i->~BaseElementType(); |
317 } | 320 } |
318 ListContainerBase::clear(); | 321 ListContainerBase::clear(); |
319 } | 322 } |
320 | 323 |
321 using ListContainerBase::AvailableSizeWithoutAnotherAllocationForTesting; | 324 using ListContainerBase::AvailableSizeWithoutAnotherAllocationForTesting; |
322 | 325 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 ListContainerBase::ConstReverseIterator base_iterator) | 474 ListContainerBase::ConstReverseIterator base_iterator) |
472 : ListContainerBase::ConstReverseIterator(base_iterator) {} | 475 : ListContainerBase::ConstReverseIterator(base_iterator) {} |
473 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; | 476 friend ConstReverseIterator ListContainer<BaseElementType>::crbegin() const; |
474 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; | 477 friend ConstReverseIterator ListContainer<BaseElementType>::crend() const; |
475 }; | 478 }; |
476 }; | 479 }; |
477 | 480 |
478 } // namespace cc | 481 } // namespace cc |
479 | 482 |
480 #endif // CC_BASE_LIST_CONTAINER_H_ | 483 #endif // CC_BASE_LIST_CONTAINER_H_ |
OLD | NEW |