1 // Copyright 2017 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.
4
5 #include "base/value_iterators.h"
6
7 namespace base {
8
9 namespace detail {
10
11 // ----------------------------------------------------------------------------
12 // dict_iterator.
13
pointer(const reference & ref)14 dict_iterator::pointer::pointer(const reference& ref) : ref_(ref) {}
15
16 dict_iterator::pointer::pointer(const pointer& ptr) = default;
17
dict_iterator(DictStorage::iterator dict_iter)18 dict_iterator::dict_iterator(DictStorage::iterator dict_iter)
19 : dict_iter_(dict_iter) {}
20
21 dict_iterator::dict_iterator(const dict_iterator& dict_iter) = default;
22
23 dict_iterator& dict_iterator::operator=(const dict_iterator& dict_iter) =
24 default;
25
26 dict_iterator::~dict_iterator() = default;
27
operator *()28 dict_iterator::reference dict_iterator::operator*() {
29 return {dict_iter_->first, *dict_iter_->second};
30 }
31
operator ->()32 dict_iterator::pointer dict_iterator::operator->() {
33 return pointer(operator*());
34 }
35
operator ++()36 dict_iterator& dict_iterator::operator++() {
37 ++dict_iter_;
38 return *this;
39 }
40
operator ++(int)41 dict_iterator dict_iterator::operator++(int) {
42 dict_iterator tmp(*this);
43 ++dict_iter_;
44 return tmp;
45 }
46
operator --()47 dict_iterator& dict_iterator::operator--() {
48 --dict_iter_;
49 return *this;
50 }
51
operator --(int)52 dict_iterator dict_iterator::operator--(int) {
53 dict_iterator tmp(*this);
54 --dict_iter_;
55 return tmp;
56 }
57
operator ==(const dict_iterator & lhs,const dict_iterator & rhs)58 bool operator==(const dict_iterator& lhs, const dict_iterator& rhs) {
59 return lhs.dict_iter_ == rhs.dict_iter_;
60 }
61
operator !=(const dict_iterator & lhs,const dict_iterator & rhs)62 bool operator!=(const dict_iterator& lhs, const dict_iterator& rhs) {
63 return !(lhs == rhs);
64 }
65
66 // ----------------------------------------------------------------------------
67 // const_dict_iterator.
68
pointer(const reference & ref)69 const_dict_iterator::pointer::pointer(const reference& ref) : ref_(ref) {}
70
71 const_dict_iterator::pointer::pointer(const pointer& ptr) = default;
72
const_dict_iterator(DictStorage::const_iterator dict_iter)73 const_dict_iterator::const_dict_iterator(DictStorage::const_iterator dict_iter)
74 : dict_iter_(dict_iter) {}
75
76 const_dict_iterator::const_dict_iterator(const const_dict_iterator& dict_iter) =
77 default;
78
79 const_dict_iterator& const_dict_iterator::operator=(
80 const const_dict_iterator& dict_iter) = default;
81
82 const_dict_iterator::~const_dict_iterator() = default;
83
operator *() const84 const_dict_iterator::reference const_dict_iterator::operator*() const {
85 return {dict_iter_->first, *dict_iter_->second};
86 }
87
operator ->() const88 const_dict_iterator::pointer const_dict_iterator::operator->() const {
89 return pointer(operator*());
90 }
91
operator ++()92 const_dict_iterator& const_dict_iterator::operator++() {
93 ++dict_iter_;
94 return *this;
95 }
96
operator ++(int)97 const_dict_iterator const_dict_iterator::operator++(int) {
98 const_dict_iterator tmp(*this);
99 ++dict_iter_;
100 return tmp;
101 }
102
operator --()103 const_dict_iterator& const_dict_iterator::operator--() {
104 --dict_iter_;
105 return *this;
106 }
107
operator --(int)108 const_dict_iterator const_dict_iterator::operator--(int) {
109 const_dict_iterator tmp(*this);
110 --dict_iter_;
111 return tmp;
112 }
113
operator ==(const const_dict_iterator & lhs,const const_dict_iterator & rhs)114 bool operator==(const const_dict_iterator& lhs,
115 const const_dict_iterator& rhs) {
116 return lhs.dict_iter_ == rhs.dict_iter_;
117 }
118
operator !=(const const_dict_iterator & lhs,const const_dict_iterator & rhs)119 bool operator!=(const const_dict_iterator& lhs,
120 const const_dict_iterator& rhs) {
121 return !(lhs == rhs);
122 }
123
124 // ----------------------------------------------------------------------------
125 // dict_iterator_proxy.
126
dict_iterator_proxy(DictStorage * storage)127 dict_iterator_proxy::dict_iterator_proxy(DictStorage* storage)
128 : storage_(storage) {}
129
begin()130 dict_iterator_proxy::iterator dict_iterator_proxy::begin() {
131 return iterator(storage_->begin());
132 }
133
begin() const134 dict_iterator_proxy::const_iterator dict_iterator_proxy::begin() const {
135 return const_iterator(storage_->begin());
136 }
137
end()138 dict_iterator_proxy::iterator dict_iterator_proxy::end() {
139 return iterator(storage_->end());
140 }
141
end() const142 dict_iterator_proxy::const_iterator dict_iterator_proxy::end() const {
143 return const_iterator(storage_->end());
144 }
145
rbegin()146 dict_iterator_proxy::reverse_iterator dict_iterator_proxy::rbegin() {
147 return reverse_iterator(end());
148 }
149
rbegin() const150 dict_iterator_proxy::const_reverse_iterator dict_iterator_proxy::rbegin()
151 const {
152 return const_reverse_iterator(end());
153 }
154
rend()155 dict_iterator_proxy::reverse_iterator dict_iterator_proxy::rend() {
156 return reverse_iterator(begin());
157 }
158
rend() const159 dict_iterator_proxy::const_reverse_iterator dict_iterator_proxy::rend() const {
160 return const_reverse_iterator(begin());
161 }
162
cbegin() const163 dict_iterator_proxy::const_iterator dict_iterator_proxy::cbegin() const {
164 return const_iterator(begin());
165 }
166
cend() const167 dict_iterator_proxy::const_iterator dict_iterator_proxy::cend() const {
168 return const_iterator(end());
169 }
170
crbegin() const171 dict_iterator_proxy::const_reverse_iterator dict_iterator_proxy::crbegin()
172 const {
173 return const_reverse_iterator(rbegin());
174 }
175
crend() const176 dict_iterator_proxy::const_reverse_iterator dict_iterator_proxy::crend() const {
177 return const_reverse_iterator(rend());
178 }
179
180 // ----------------------------------------------------------------------------
181 // const_dict_iterator_proxy.
182
const_dict_iterator_proxy(const DictStorage * storage)183 const_dict_iterator_proxy::const_dict_iterator_proxy(const DictStorage* storage)
184 : storage_(storage) {}
185
begin() const186 const_dict_iterator_proxy::const_iterator const_dict_iterator_proxy::begin()
187 const {
188 return const_iterator(storage_->begin());
189 }
190
end() const191 const_dict_iterator_proxy::const_iterator const_dict_iterator_proxy::end()
192 const {
193 return const_iterator(storage_->end());
194 }
195
196 const_dict_iterator_proxy::const_reverse_iterator
rbegin() const197 const_dict_iterator_proxy::rbegin() const {
198 return const_reverse_iterator(end());
199 }
200
201 const_dict_iterator_proxy::const_reverse_iterator
rend() const202 const_dict_iterator_proxy::rend() const {
203 return const_reverse_iterator(begin());
204 }
205
cbegin() const206 const_dict_iterator_proxy::const_iterator const_dict_iterator_proxy::cbegin()
207 const {
208 return const_iterator(begin());
209 }
210
cend() const211 const_dict_iterator_proxy::const_iterator const_dict_iterator_proxy::cend()
212 const {
213 return const_iterator(end());
214 }
215
216 const_dict_iterator_proxy::const_reverse_iterator
crbegin() const217 const_dict_iterator_proxy::crbegin() const {
218 return const_reverse_iterator(rbegin());
219 }
220
221 const_dict_iterator_proxy::const_reverse_iterator
crend() const222 const_dict_iterator_proxy::crend() const {
223 return const_reverse_iterator(rend());
224 }
225
226 } // namespace detail
227
228 } // namespace base
229