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_QUADS_LIST_CONTAINER_H_ | 5 #ifndef CC_QUADS_LIST_CONTAINER_H_ |
6 #define CC_QUADS_LIST_CONTAINER_H_ | 6 #define CC_QUADS_LIST_CONTAINER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "cc/base/cc_export.h" | 10 #include "cc/base/cc_export.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 ConstIterator begin() const; | 139 ConstIterator begin() const; |
140 ConstIterator end() const; | 140 ConstIterator end() const; |
141 Iterator begin(); | 141 Iterator begin(); |
142 Iterator end(); | 142 Iterator end(); |
143 | 143 |
144 BaseElementType* front(); | 144 BaseElementType* front(); |
145 BaseElementType* back(); | 145 BaseElementType* back(); |
146 const BaseElementType* front() const; | 146 const BaseElementType* front() const; |
147 const BaseElementType* back() const; | 147 const BaseElementType* back() const; |
148 | 148 |
| 149 BaseElementType* ElementAt(size_t index); |
| 150 const BaseElementType* ElementAt(size_t index) const; |
| 151 |
149 // Take in derived element type and construct it at location generated by | 152 // Take in derived element type and construct it at location generated by |
150 // Allocate(). | 153 // Allocate(). |
151 template <typename DerivedElementType> | 154 template <typename DerivedElementType> |
152 DerivedElementType* AllocateAndConstruct() { | 155 DerivedElementType* AllocateAndConstruct() { |
153 DerivedElementType* result = | 156 return new (Allocate(sizeof(DerivedElementType))) DerivedElementType; |
154 new (Allocate(sizeof(DerivedElementType))) DerivedElementType; | 157 } |
155 return result; | 158 // Take in derived element type and copy construct it at location generated by |
| 159 // Allocate(). |
| 160 template <typename DerivedElementType> |
| 161 DerivedElementType* AllocateAndCopyFrom(const DerivedElementType* source) { |
| 162 return new (Allocate(sizeof(DerivedElementType))) |
| 163 DerivedElementType(*source); |
156 } | 164 } |
157 | 165 |
158 size_t size() const; | 166 size_t size() const; |
159 bool empty() const; | 167 bool empty() const; |
160 void clear(); | 168 void clear(); |
161 | 169 |
162 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; | 170 size_t AvailableSizeWithoutAnotherAllocationForTesting() const; |
163 | 171 |
164 private: | 172 private: |
165 // Hands out memory location for an element at the end of data structure. | 173 // Hands out memory location for an element at the end of data structure. |
166 BaseElementType* Allocate(size_t size_of_actual_element_in_bytes); | 174 BaseElementType* Allocate(size_t size_of_actual_element_in_bytes); |
167 | 175 |
168 scoped_ptr<ListContainerCharAllocator> data_; | 176 scoped_ptr<ListContainerCharAllocator> data_; |
169 | 177 |
170 DISALLOW_COPY_AND_ASSIGN(ListContainer); | 178 DISALLOW_COPY_AND_ASSIGN(ListContainer); |
171 }; | 179 }; |
172 | 180 |
173 #if !defined(COMPILER_MSVC) | 181 #if !defined(COMPILER_MSVC) |
174 extern template class ListContainer<SharedQuadState>; | 182 extern template class ListContainer<SharedQuadState>; |
175 extern template class ListContainer<DrawQuad>; | 183 extern template class ListContainer<DrawQuad>; |
176 #endif | 184 #endif |
177 } // namespace cc | 185 } // namespace cc |
178 | 186 |
179 #endif // CC_QUADS_LIST_CONTAINER_H_ | 187 #endif // CC_QUADS_LIST_CONTAINER_H_ |
OLD | NEW |