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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 template <typename DerivedElementType> | 117 template <typename DerivedElementType> |
118 DerivedElementType* AllocateAndCopyFrom(const DerivedElementType* source) { | 118 DerivedElementType* AllocateAndCopyFrom(const DerivedElementType* source) { |
119 return new (helper_.Allocate(sizeof(DerivedElementType))) | 119 return new (helper_.Allocate(sizeof(DerivedElementType))) |
120 DerivedElementType(*source); | 120 DerivedElementType(*source); |
121 } | 121 } |
122 | 122 |
123 // Construct a new element on top of an existing one. | 123 // Construct a new element on top of an existing one. |
124 template <typename DerivedElementType> | 124 template <typename DerivedElementType> |
125 DerivedElementType* ReplaceExistingElement(Iterator at) { | 125 DerivedElementType* ReplaceExistingElement(Iterator at) { |
126 at->~BaseElementType(); | 126 at->~BaseElementType(); |
127 return new (*at) DerivedElementType(); | 127 return new (*at) DerivedElementType(); |
ccameron
2015/09/21 19:01:39
Could you grab this instance as well? I'm surprise
weiliangc
2015/09/21 19:04:18
This is another case here.
krasin
2015/09/21 20:43:34
Done.
krasin
2015/09/21 20:43:34
Done.
| |
128 } | 128 } |
129 | 129 |
130 // Insert |count| new elements of |DerivedElementType| before |at|. This will | 130 // Insert |count| new elements of |DerivedElementType| before |at|. This will |
131 // invalidate all outstanding pointers and iterators. Return a valid iterator | 131 // invalidate all outstanding pointers and iterators. Return a valid iterator |
132 // for the beginning of the newly inserted segment. | 132 // for the beginning of the newly inserted segment. |
133 template <typename DerivedElementType> | 133 template <typename DerivedElementType> |
134 Iterator InsertBeforeAndInvalidateAllPointers(Iterator at, size_t count) { | 134 Iterator InsertBeforeAndInvalidateAllPointers(Iterator at, size_t count) { |
135 helper_.InsertBeforeAndInvalidateAllPointers(&at, count); | 135 helper_.InsertBeforeAndInvalidateAllPointers(&at, count); |
136 Iterator result = at; | 136 Iterator result = at; |
137 for (size_t i = 0; i < count; ++i) { | 137 for (size_t i = 0; i < count; ++i) { |
138 new (*at) DerivedElementType(); | 138 new (at.item_iterator) DerivedElementType(); |
139 ++at; | 139 ++at; |
140 } | 140 } |
141 return result; | 141 return result; |
142 } | 142 } |
143 | 143 |
144 template <typename DerivedElementType> | 144 template <typename DerivedElementType> |
145 void swap(ListContainer<DerivedElementType>& other) { | 145 void swap(ListContainer<DerivedElementType>& other) { |
146 helper_.data_.swap(other.helper_.data_); | 146 helper_.data_.swap(other.helper_.data_); |
147 } | 147 } |
148 | 148 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 | 335 |
336 private: | 336 private: |
337 ListContainerHelper helper_; | 337 ListContainerHelper helper_; |
338 | 338 |
339 DISALLOW_COPY_AND_ASSIGN(ListContainer); | 339 DISALLOW_COPY_AND_ASSIGN(ListContainer); |
340 }; | 340 }; |
341 | 341 |
342 } // namespace cc | 342 } // namespace cc |
343 | 343 |
344 #endif // CC_BASE_LIST_CONTAINER_H_ | 344 #endif // CC_BASE_LIST_CONTAINER_H_ |
OLD | NEW |