Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / cc / base / list_container_helper.h
blob31b2310d49dd160441d311fab3d048f40e9a3d76
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
3 // found in the LICENSE file.
5 #ifndef CC_BASE_LIST_CONTAINER_HELPER_H_
6 #define CC_BASE_LIST_CONTAINER_HELPER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/base/cc_export.h"
11 namespace cc {
13 // Helper class for ListContainer non-templated logic. All methods are private,
14 // and only exposed to friend classes.
15 // For usage, see comments in ListContainer (list_container.h).
16 class CC_EXPORT ListContainerHelper final {
17 private:
18 template <typename T>
19 friend class ListContainer;
21 template <typename T>
22 friend class RandomAccessListContainer;
24 explicit ListContainerHelper(size_t max_size_for_derived_class);
25 ListContainerHelper(size_t max_size_for_derived_class,
26 size_t num_of_elements_to_reserve_for);
27 ~ListContainerHelper();
29 // This class deals only with char* and void*. It does allocation and passing
30 // out raw pointers, as well as memory deallocation when being destroyed.
31 class CharAllocator;
33 // This class points to a certain position inside memory of
34 // CharAllocator. It is a base class for ListContainer iterators.
35 struct CC_EXPORT PositionInCharAllocator {
36 CharAllocator* ptr_to_container;
37 size_t vector_index;
38 char* item_iterator;
40 PositionInCharAllocator(const PositionInCharAllocator& other);
42 PositionInCharAllocator(CharAllocator* container,
43 size_t vector_ind,
44 char* item_iter);
46 bool operator==(const PositionInCharAllocator& other) const;
47 bool operator!=(const PositionInCharAllocator& other) const;
49 PositionInCharAllocator Increment();
50 PositionInCharAllocator ReverseIncrement();
53 // Iterator classes that can be used to access data.
54 /////////////////////////////////////////////////////////////////
55 class CC_EXPORT Iterator : public PositionInCharAllocator {
56 // This class is only defined to forward iterate through
57 // CharAllocator.
58 public:
59 Iterator(CharAllocator* container,
60 size_t vector_ind,
61 char* item_iter,
62 size_t index);
63 ~Iterator();
65 size_t index() const;
67 protected:
68 // This is used to track how many increment has happened since begin(). It
69 // is used to avoid double increment at places an index reference is
70 // needed. For iterator this means begin() corresponds to index 0 and end()
71 // corresponds to index |size|.
72 size_t index_;
75 class CC_EXPORT ConstIterator : public PositionInCharAllocator {
76 // This class is only defined to forward iterate through
77 // CharAllocator.
78 public:
79 ConstIterator(CharAllocator* container,
80 size_t vector_ind,
81 char* item_iter,
82 size_t index);
83 ConstIterator(const Iterator& other); // NOLINT
84 ~ConstIterator();
86 size_t index() const;
88 protected:
89 // This is used to track how many increment has happened since begin(). It
90 // is used to avoid double increment at places an index reference is
91 // needed. For iterator this means begin() corresponds to index 0 and end()
92 // corresponds to index |size|.
93 size_t index_;
96 class CC_EXPORT ReverseIterator : public PositionInCharAllocator {
97 // This class is only defined to reverse iterate through
98 // CharAllocator.
99 public:
100 ReverseIterator(CharAllocator* container,
101 size_t vector_ind,
102 char* item_iter,
103 size_t index);
104 ~ReverseIterator();
106 size_t index() const;
108 protected:
109 // This is used to track how many increment has happened since rbegin(). It
110 // is used to avoid double increment at places an index reference is
111 // needed. For reverse iterator this means rbegin() corresponds to index 0
112 // and rend() corresponds to index |size|.
113 size_t index_;
116 class CC_EXPORT ConstReverseIterator : public PositionInCharAllocator {
117 // This class is only defined to reverse iterate through
118 // CharAllocator.
119 public:
120 ConstReverseIterator(CharAllocator* container,
121 size_t vector_ind,
122 char* item_iter,
123 size_t index);
124 ConstReverseIterator(const ReverseIterator& other); // NOLINT
125 ~ConstReverseIterator();
127 size_t index() const;
129 protected:
130 // This is used to track how many increment has happened since rbegin(). It
131 // is used to avoid double increment at places an index reference is
132 // needed. For reverse iterator this means rbegin() corresponds to index 0
133 // and rend() corresponds to index |size|.
134 size_t index_;
137 // Unlike the ListContainer methods, these do not invoke element destructors.
138 void RemoveLast();
139 void EraseAndInvalidateAllPointers(Iterator* position);
140 void InsertBeforeAndInvalidateAllPointers(Iterator* position,
141 size_t number_of_elements);
143 ConstReverseIterator crbegin() const;
144 ConstReverseIterator crend() const;
145 ReverseIterator rbegin();
146 ReverseIterator rend();
147 ConstIterator cbegin() const;
148 ConstIterator cend() const;
149 Iterator begin();
150 Iterator end();
152 Iterator IteratorAt(size_t index);
153 ConstIterator IteratorAt(size_t index) const;
155 size_t size() const;
156 bool empty() const;
158 size_t MaxSizeForDerivedClass() const;
160 size_t GetCapacityInBytes() const;
162 // Unlike the ListContainer method, this one does not invoke element
163 // destructors.
164 void clear();
166 size_t AvailableSizeWithoutAnotherAllocationForTesting() const;
168 // Hands out memory location for an element at the end of data structure.
169 void* Allocate(size_t size_of_actual_element_in_bytes);
171 scoped_ptr<CharAllocator> data_;
173 DISALLOW_COPY_AND_ASSIGN(ListContainerHelper);
176 } // namespace cc
178 #endif // CC_BASE_LIST_CONTAINER_HELPER_H_