Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 public: | 26 public: |
| 27 // BaseElementType is the type of raw pointers this class hands out; however, | 27 // BaseElementType is the type of raw pointers this class hands out; however, |
| 28 // its derived classes might require different memory sizes. | 28 // its derived classes might require different memory sizes. |
| 29 // max_size_for_derived_class the largest memory size required for all the | 29 // max_size_for_derived_class the largest memory size required for all the |
| 30 // derived classes to use for allocation. | 30 // derived classes to use for allocation. |
| 31 explicit ListContainer(size_t max_size_for_derived_class); | 31 explicit ListContainer(size_t max_size_for_derived_class); |
| 32 // This constructor omits input variable for max_size_for_derived_class. This | 32 // This constructor omits input variable for max_size_for_derived_class. This |
| 33 // is used when there is no derived classes from BaseElementType we need to | 33 // is used when there is no derived classes from BaseElementType we need to |
| 34 // worry about, and allocation size is just sizeof(BaseElementType). | 34 // worry about, and allocation size is just sizeof(BaseElementType). |
| 35 ListContainer(); | 35 ListContainer(); |
| 36 // This constructor reserves the requested memory up front so only a single | 36 // This constructor reserves the requested memory up front so only single |
| 37 // allocation is needed. | 37 // allocation is needed. When num_of_elements_to_reserve_for is zero, use the |
| 38 // default size. | |
| 38 ListContainer(size_t max_size_for_derived_class, | 39 ListContainer(size_t max_size_for_derived_class, |
| 39 size_t num_of_elements_to_reserve_for); | 40 size_t num_of_elements_to_reserve_for); |
| 40 | 41 |
| 41 ~ListContainer(); | 42 ~ListContainer(); |
| 42 | 43 |
| 43 // This class deals only with char* and void*. It does allocation and passing | 44 // This class deals only with char* and void*. It does allocation and passing |
| 44 // out raw pointers, as well as memory deallocation when being destroyed. | 45 // out raw pointers, as well as memory deallocation when being destroyed. |
| 45 class CC_EXPORT ListContainerCharAllocator; | 46 class CC_EXPORT ListContainerCharAllocator; |
| 46 | 47 |
| 47 // This class points to a certain position inside memory of | 48 // This class points to a certain position inside memory of |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 // Iterator classes that can be used to access data. | 69 // Iterator classes that can be used to access data. |
| 69 ///////////////////////////////////////////////////////////////// | 70 ///////////////////////////////////////////////////////////////// |
| 70 class CC_EXPORT Iterator : public PositionInListContainerCharAllocator { | 71 class CC_EXPORT Iterator : public PositionInListContainerCharAllocator { |
| 71 // This class is only defined to forward iterate through | 72 // This class is only defined to forward iterate through |
| 72 // ListContainerCharAllocator. | 73 // ListContainerCharAllocator. |
| 73 public: | 74 public: |
| 74 Iterator(ListContainerCharAllocator* container, | 75 Iterator(ListContainerCharAllocator* container, |
| 75 size_t vector_ind, | 76 size_t vector_ind, |
| 76 char* item_iter); | 77 char* item_iter, |
| 78 size_t index); | |
| 77 ~Iterator(); | 79 ~Iterator(); |
| 78 BaseElementType* operator->() const; | 80 BaseElementType* operator->() const; |
| 79 BaseElementType& operator*() const; | 81 BaseElementType& operator*() const; |
| 80 Iterator operator++(int unused_post_increment); | 82 Iterator operator++(int unused_post_increment); |
| 81 Iterator operator++(); | 83 Iterator operator++(); |
| 84 | |
| 85 size_t index() const; | |
| 86 | |
| 87 private: | |
| 88 // This is used to track how many increment has happened since begin(). It | |
| 89 // is | |
|
danakj
2014/10/02 15:32:48
fix formatting
weiliangc
2014/10/02 22:01:39
Done.
| |
| 90 // used to avoid doulble increment at places an index reference is needed. | |
| 91 // For iterator this means begin() corresponds to index 0 and end() | |
| 92 // corresponds to index |size|. | |
| 93 size_t index_; | |
| 82 }; | 94 }; |
| 83 | 95 |
| 84 class CC_EXPORT ConstIterator : public PositionInListContainerCharAllocator { | 96 class CC_EXPORT ConstIterator : public PositionInListContainerCharAllocator { |
| 85 // This class is only defined to forward iterate through | 97 // This class is only defined to forward iterate through |
| 86 // ListContainerCharAllocator. | 98 // ListContainerCharAllocator. |
| 87 public: | 99 public: |
| 88 ConstIterator(ListContainerCharAllocator* container, | 100 ConstIterator(ListContainerCharAllocator* container, |
| 89 size_t vector_ind, | 101 size_t vector_ind, |
| 90 char* item_iter); | 102 char* item_iter, |
| 103 size_t index); | |
| 91 ConstIterator(const Iterator& other); // NOLINT | 104 ConstIterator(const Iterator& other); // NOLINT |
| 92 ~ConstIterator(); | 105 ~ConstIterator(); |
| 93 const BaseElementType* operator->() const; | 106 const BaseElementType* operator->() const; |
| 94 const BaseElementType& operator*() const; | 107 const BaseElementType& operator*() const; |
| 95 ConstIterator operator++(int unused_post_increment); | 108 ConstIterator operator++(int unused_post_increment); |
| 96 ConstIterator operator++(); | 109 ConstIterator operator++(); |
| 110 | |
| 111 size_t index() const; | |
| 112 | |
| 113 private: | |
| 114 // This is used to track how many increment has happened since begin(). It | |
| 115 // is | |
|
danakj
2014/10/02 15:32:48
formatting
weiliangc
2014/10/02 22:01:40
Done.
| |
| 116 // used to avoid doulble increment at places an index reference is needed. | |
| 117 // For iterator this means begin() corresponds to index 0 and end() | |
| 118 // corresponds to index |size|. | |
| 119 size_t index_; | |
| 97 }; | 120 }; |
| 98 | 121 |
| 99 class CC_EXPORT ReverseIterator | 122 class CC_EXPORT ReverseIterator |
| 100 : public PositionInListContainerCharAllocator { | 123 : public PositionInListContainerCharAllocator { |
| 101 // This class is only defined to reverse iterate through | 124 // This class is only defined to reverse iterate through |
| 102 // ListContainerCharAllocator. | 125 // ListContainerCharAllocator. |
| 103 public: | 126 public: |
| 104 ReverseIterator(ListContainerCharAllocator* container, | 127 ReverseIterator(ListContainerCharAllocator* container, |
| 105 size_t vector_ind, | 128 size_t vector_ind, |
| 106 char* item_iter); | 129 char* item_iter, |
| 130 size_t index); | |
| 107 ~ReverseIterator(); | 131 ~ReverseIterator(); |
| 108 BaseElementType* operator->() const; | 132 BaseElementType* operator->() const; |
| 109 BaseElementType& operator*() const; | 133 BaseElementType& operator*() const; |
| 110 ReverseIterator operator++(int unused_post_increment); | 134 ReverseIterator operator++(int unused_post_increment); |
| 111 ReverseIterator operator++(); | 135 ReverseIterator operator++(); |
| 136 | |
| 137 size_t index() const; | |
| 138 | |
| 139 private: | |
| 140 // This is used to track how many increment has happened since rbegin(). It | |
| 141 // is used to avoid doulble increment at places an index reference is | |
| 142 // needed. | |
| 143 // For reverse iterator this means rbegin() corresponds to index 0 and | |
| 144 // rend() | |
|
danakj
2014/10/02 15:32:48
formatting
weiliangc
2014/10/02 22:01:39
Done.
| |
| 145 // corresponds to index |size|. | |
| 146 size_t index_; | |
| 112 }; | 147 }; |
| 113 | 148 |
| 114 class CC_EXPORT ConstReverseIterator | 149 class CC_EXPORT ConstReverseIterator |
| 115 : public PositionInListContainerCharAllocator { | 150 : public PositionInListContainerCharAllocator { |
| 116 // This class is only defined to reverse iterate through | 151 // This class is only defined to reverse iterate through |
| 117 // ListContainerCharAllocator. | 152 // ListContainerCharAllocator. |
| 118 public: | 153 public: |
| 119 ConstReverseIterator(ListContainerCharAllocator* container, | 154 ConstReverseIterator(ListContainerCharAllocator* container, |
| 120 size_t vector_ind, | 155 size_t vector_ind, |
| 121 char* item_iter); | 156 char* item_iter, |
| 157 size_t index); | |
| 122 ConstReverseIterator(const ReverseIterator& other); // NOLINT | 158 ConstReverseIterator(const ReverseIterator& other); // NOLINT |
| 123 ~ConstReverseIterator(); | 159 ~ConstReverseIterator(); |
| 124 const BaseElementType* operator->() const; | 160 const BaseElementType* operator->() const; |
| 125 const BaseElementType& operator*() const; | 161 const BaseElementType& operator*() const; |
| 126 ConstReverseIterator operator++(int unused_post_increment); | 162 ConstReverseIterator operator++(int unused_post_increment); |
| 127 ConstReverseIterator operator++(); | 163 ConstReverseIterator operator++(); |
| 164 | |
| 165 size_t index() const; | |
| 166 | |
| 167 private: | |
| 168 // This is used to track how many increment has happened since rbegin(). It | |
| 169 // is used to avoid doulble increment at places an index reference is | |
| 170 // needed. | |
| 171 // For reverse iterator this means rbegin() corresponds to index 0 and | |
| 172 // rend() | |
|
danakj
2014/10/02 15:32:48
formattting
weiliangc
2014/10/02 22:01:40
Done.
| |
| 173 // corresponds to index |size|. | |
| 174 size_t index_; | |
| 128 }; | 175 }; |
| 129 | 176 |
| 130 // When called, all raw pointers that have been handed out are no longer | 177 // When called, all raw pointers that have been handed out are no longer |
| 131 // valid. Use with caution. | 178 // valid. Use with caution. |
| 132 // This function does not deallocate memory. | 179 // This function does not deallocate memory. |
| 133 void EraseAndInvalidateAllPointers(Iterator position); | 180 void EraseAndInvalidateAllPointers(Iterator position); |
| 134 | 181 |
| 135 ConstReverseIterator rbegin() const; | 182 ConstReverseIterator rbegin() const; |
| 136 ConstReverseIterator rend() const; | 183 ConstReverseIterator rend() const; |
| 137 ReverseIterator rbegin(); | 184 ReverseIterator rbegin(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 DISALLOW_COPY_AND_ASSIGN(ListContainer); | 225 DISALLOW_COPY_AND_ASSIGN(ListContainer); |
| 179 }; | 226 }; |
| 180 | 227 |
| 181 #if !defined(COMPILER_MSVC) | 228 #if !defined(COMPILER_MSVC) |
| 182 extern template class ListContainer<SharedQuadState>; | 229 extern template class ListContainer<SharedQuadState>; |
| 183 extern template class ListContainer<DrawQuad>; | 230 extern template class ListContainer<DrawQuad>; |
| 184 #endif | 231 #endif |
| 185 } // namespace cc | 232 } // namespace cc |
| 186 | 233 |
| 187 #endif // CC_QUADS_LIST_CONTAINER_H_ | 234 #endif // CC_QUADS_LIST_CONTAINER_H_ |
| OLD | NEW |