OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_HELPER_H_ | 5 #ifndef CC_BASE_LIST_CONTAINER_HELPER_H_ |
6 #define CC_BASE_LIST_CONTAINER_HELPER_H_ | 6 #define CC_BASE_LIST_CONTAINER_HELPER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "cc/base/cc_export.h" | 13 #include "cc/base/base_export.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 | 16 |
17 // Helper class for ListContainer non-templated logic. All methods are private, | 17 // Helper class for ListContainer non-templated logic. All methods are private, |
18 // and only exposed to friend classes. | 18 // and only exposed to friend classes. |
19 // For usage, see comments in ListContainer (list_container.h). | 19 // For usage, see comments in ListContainer (list_container.h). |
20 class CC_EXPORT ListContainerHelper final { | 20 class CC_BASE_EXPORT ListContainerHelper final { |
21 private: | 21 private: |
22 template <typename T> | 22 template <typename T> |
23 friend class ListContainer; | 23 friend class ListContainer; |
24 | 24 |
25 template <typename T> | 25 template <typename T> |
26 friend class RandomAccessListContainer; | 26 friend class RandomAccessListContainer; |
27 | 27 |
28 explicit ListContainerHelper(size_t max_size_for_derived_class); | 28 explicit ListContainerHelper(size_t max_size_for_derived_class); |
29 ListContainerHelper(size_t max_size_for_derived_class, | 29 ListContainerHelper(size_t max_size_for_derived_class, |
30 size_t num_of_elements_to_reserve_for); | 30 size_t num_of_elements_to_reserve_for); |
31 ~ListContainerHelper(); | 31 ~ListContainerHelper(); |
32 | 32 |
33 // This class deals only with char* and void*. It does allocation and passing | 33 // This class deals only with char* and void*. It does allocation and passing |
34 // out raw pointers, as well as memory deallocation when being destroyed. | 34 // out raw pointers, as well as memory deallocation when being destroyed. |
35 class CharAllocator; | 35 class CharAllocator; |
36 | 36 |
37 // This class points to a certain position inside memory of | 37 // This class points to a certain position inside memory of |
38 // CharAllocator. It is a base class for ListContainer iterators. | 38 // CharAllocator. It is a base class for ListContainer iterators. |
39 struct CC_EXPORT PositionInCharAllocator { | 39 struct CC_BASE_EXPORT PositionInCharAllocator { |
40 CharAllocator* ptr_to_container; | 40 CharAllocator* ptr_to_container; |
41 size_t vector_index; | 41 size_t vector_index; |
42 char* item_iterator; | 42 char* item_iterator; |
43 | 43 |
44 PositionInCharAllocator(const PositionInCharAllocator& other); | 44 PositionInCharAllocator(const PositionInCharAllocator& other); |
45 | 45 |
46 PositionInCharAllocator(CharAllocator* container, | 46 PositionInCharAllocator(CharAllocator* container, |
47 size_t vector_ind, | 47 size_t vector_ind, |
48 char* item_iter); | 48 char* item_iter); |
49 | 49 |
50 bool operator==(const PositionInCharAllocator& other) const; | 50 bool operator==(const PositionInCharAllocator& other) const; |
51 bool operator!=(const PositionInCharAllocator& other) const; | 51 bool operator!=(const PositionInCharAllocator& other) const; |
52 | 52 |
53 PositionInCharAllocator Increment(); | 53 PositionInCharAllocator Increment(); |
54 PositionInCharAllocator ReverseIncrement(); | 54 PositionInCharAllocator ReverseIncrement(); |
55 }; | 55 }; |
56 | 56 |
57 // Iterator classes that can be used to access data. | 57 // Iterator classes that can be used to access data. |
58 ///////////////////////////////////////////////////////////////// | 58 ///////////////////////////////////////////////////////////////// |
59 class CC_EXPORT Iterator : public PositionInCharAllocator { | 59 class CC_BASE_EXPORT Iterator : public PositionInCharAllocator { |
60 // This class is only defined to forward iterate through | 60 // This class is only defined to forward iterate through |
61 // CharAllocator. | 61 // CharAllocator. |
62 public: | 62 public: |
63 Iterator(CharAllocator* container, | 63 Iterator(CharAllocator* container, |
64 size_t vector_ind, | 64 size_t vector_ind, |
65 char* item_iter, | 65 char* item_iter, |
66 size_t index); | 66 size_t index); |
67 ~Iterator(); | 67 ~Iterator(); |
68 | 68 |
69 size_t index() const; | 69 size_t index() const; |
70 | 70 |
71 protected: | 71 protected: |
72 // This is used to track how many increment has happened since begin(). It | 72 // This is used to track how many increment has happened since begin(). It |
73 // is used to avoid double increment at places an index reference is | 73 // is used to avoid double increment at places an index reference is |
74 // needed. For iterator this means begin() corresponds to index 0 and end() | 74 // needed. For iterator this means begin() corresponds to index 0 and end() |
75 // corresponds to index |size|. | 75 // corresponds to index |size|. |
76 size_t index_; | 76 size_t index_; |
77 }; | 77 }; |
78 | 78 |
79 class CC_EXPORT ConstIterator : public PositionInCharAllocator { | 79 class CC_BASE_EXPORT ConstIterator : public PositionInCharAllocator { |
80 // This class is only defined to forward iterate through | 80 // This class is only defined to forward iterate through |
81 // CharAllocator. | 81 // CharAllocator. |
82 public: | 82 public: |
83 ConstIterator(CharAllocator* container, | 83 ConstIterator(CharAllocator* container, |
84 size_t vector_ind, | 84 size_t vector_ind, |
85 char* item_iter, | 85 char* item_iter, |
86 size_t index); | 86 size_t index); |
87 ConstIterator(const Iterator& other); // NOLINT | 87 ConstIterator(const Iterator& other); // NOLINT |
88 ~ConstIterator(); | 88 ~ConstIterator(); |
89 | 89 |
90 size_t index() const; | 90 size_t index() const; |
91 | 91 |
92 protected: | 92 protected: |
93 // This is used to track how many increment has happened since begin(). It | 93 // This is used to track how many increment has happened since begin(). It |
94 // is used to avoid double increment at places an index reference is | 94 // is used to avoid double increment at places an index reference is |
95 // needed. For iterator this means begin() corresponds to index 0 and end() | 95 // needed. For iterator this means begin() corresponds to index 0 and end() |
96 // corresponds to index |size|. | 96 // corresponds to index |size|. |
97 size_t index_; | 97 size_t index_; |
98 }; | 98 }; |
99 | 99 |
100 class CC_EXPORT ReverseIterator : public PositionInCharAllocator { | 100 class CC_BASE_EXPORT ReverseIterator : public PositionInCharAllocator { |
101 // This class is only defined to reverse iterate through | 101 // This class is only defined to reverse iterate through |
102 // CharAllocator. | 102 // CharAllocator. |
103 public: | 103 public: |
104 ReverseIterator(CharAllocator* container, | 104 ReverseIterator(CharAllocator* container, |
105 size_t vector_ind, | 105 size_t vector_ind, |
106 char* item_iter, | 106 char* item_iter, |
107 size_t index); | 107 size_t index); |
108 ~ReverseIterator(); | 108 ~ReverseIterator(); |
109 | 109 |
110 size_t index() const; | 110 size_t index() const; |
111 | 111 |
112 protected: | 112 protected: |
113 // This is used to track how many increment has happened since rbegin(). It | 113 // This is used to track how many increment has happened since rbegin(). It |
114 // is used to avoid double increment at places an index reference is | 114 // is used to avoid double increment at places an index reference is |
115 // needed. For reverse iterator this means rbegin() corresponds to index 0 | 115 // needed. For reverse iterator this means rbegin() corresponds to index 0 |
116 // and rend() corresponds to index |size|. | 116 // and rend() corresponds to index |size|. |
117 size_t index_; | 117 size_t index_; |
118 }; | 118 }; |
119 | 119 |
120 class CC_EXPORT ConstReverseIterator : public PositionInCharAllocator { | 120 class CC_BASE_EXPORT ConstReverseIterator : public PositionInCharAllocator { |
121 // This class is only defined to reverse iterate through | 121 // This class is only defined to reverse iterate through |
122 // CharAllocator. | 122 // CharAllocator. |
123 public: | 123 public: |
124 ConstReverseIterator(CharAllocator* container, | 124 ConstReverseIterator(CharAllocator* container, |
125 size_t vector_ind, | 125 size_t vector_ind, |
126 char* item_iter, | 126 char* item_iter, |
127 size_t index); | 127 size_t index); |
128 ConstReverseIterator(const ReverseIterator& other); // NOLINT | 128 ConstReverseIterator(const ReverseIterator& other); // NOLINT |
129 ~ConstReverseIterator(); | 129 ~ConstReverseIterator(); |
130 | 130 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 void* Allocate(size_t size_of_actual_element_in_bytes); | 173 void* Allocate(size_t size_of_actual_element_in_bytes); |
174 | 174 |
175 std::unique_ptr<CharAllocator> data_; | 175 std::unique_ptr<CharAllocator> data_; |
176 | 176 |
177 DISALLOW_COPY_AND_ASSIGN(ListContainerHelper); | 177 DISALLOW_COPY_AND_ASSIGN(ListContainerHelper); |
178 }; | 178 }; |
179 | 179 |
180 } // namespace cc | 180 } // namespace cc |
181 | 181 |
182 #endif // CC_BASE_LIST_CONTAINER_HELPER_H_ | 182 #endif // CC_BASE_LIST_CONTAINER_HELPER_H_ |
OLD | NEW |