jdoerrie | 44efa9d | 2017-07-14 14:47:20 | [diff] [blame] | 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 | |
| 14 | dict_iterator::pointer::pointer(const reference& ref) : ref_(ref) {} |
| 15 | |
| 16 | dict_iterator::pointer::pointer(const pointer& ptr) = default; |
| 17 | |
| 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 | |
| 28 | dict_iterator::reference dict_iterator::operator*() { |
| 29 | return {dict_iter_->first, *dict_iter_->second}; |
| 30 | } |
| 31 | |
| 32 | dict_iterator::pointer dict_iterator::operator->() { |
| 33 | return pointer(operator*()); |
| 34 | } |
| 35 | |
| 36 | dict_iterator& dict_iterator::operator++() { |
| 37 | ++dict_iter_; |
| 38 | return *this; |
| 39 | } |
| 40 | |
| 41 | dict_iterator dict_iterator::operator++(int) { |
| 42 | dict_iterator tmp(*this); |
| 43 | ++dict_iter_; |
| 44 | return tmp; |
| 45 | } |
| 46 | |
| 47 | dict_iterator& dict_iterator::operator--() { |
| 48 | --dict_iter_; |
| 49 | return *this; |
| 50 | } |
| 51 | |
| 52 | dict_iterator dict_iterator::operator--(int) { |
| 53 | dict_iterator tmp(*this); |
| 54 | --dict_iter_; |
| 55 | return tmp; |
| 56 | } |
| 57 | |
| 58 | bool operator==(const dict_iterator& lhs, const dict_iterator& rhs) { |
| 59 | return lhs.dict_iter_ == rhs.dict_iter_; |
| 60 | } |
| 61 | |
| 62 | bool operator!=(const dict_iterator& lhs, const dict_iterator& rhs) { |
| 63 | return !(lhs == rhs); |
| 64 | } |
| 65 | |
| 66 | // ---------------------------------------------------------------------------- |
| 67 | // const_dict_iterator. |
| 68 | |
| 69 | const_dict_iterator::pointer::pointer(const reference& ref) : ref_(ref) {} |
| 70 | |
| 71 | const_dict_iterator::pointer::pointer(const pointer& ptr) = default; |
| 72 | |
| 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 | |
| 84 | const_dict_iterator::reference const_dict_iterator::operator*() const { |
| 85 | return {dict_iter_->first, *dict_iter_->second}; |
| 86 | } |
| 87 | |
| 88 | const_dict_iterator::pointer const_dict_iterator::operator->() const { |
| 89 | return pointer(operator*()); |
| 90 | } |
| 91 | |
| 92 | const_dict_iterator& const_dict_iterator::operator++() { |
| 93 | ++dict_iter_; |
| 94 | return *this; |
| 95 | } |
| 96 | |
| 97 | const_dict_iterator const_dict_iterator::operator++(int) { |
| 98 | const_dict_iterator tmp(*this); |
| 99 | ++dict_iter_; |
| 100 | return tmp; |
| 101 | } |
| 102 | |
| 103 | const_dict_iterator& const_dict_iterator::operator--() { |
| 104 | --dict_iter_; |
| 105 | return *this; |
| 106 | } |
| 107 | |
| 108 | const_dict_iterator const_dict_iterator::operator--(int) { |
| 109 | const_dict_iterator tmp(*this); |
| 110 | --dict_iter_; |
| 111 | return tmp; |
| 112 | } |
| 113 | |
| 114 | bool operator==(const const_dict_iterator& lhs, |
| 115 | const const_dict_iterator& rhs) { |
| 116 | return lhs.dict_iter_ == rhs.dict_iter_; |
| 117 | } |
| 118 | |
| 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 | |
| 127 | dict_iterator_proxy::dict_iterator_proxy(DictStorage* storage) |
| 128 | : storage_(storage) {} |
| 129 | |
| 130 | dict_iterator_proxy::iterator dict_iterator_proxy::begin() { |
| 131 | return iterator(storage_->begin()); |
| 132 | } |
| 133 | |
| 134 | dict_iterator_proxy::const_iterator dict_iterator_proxy::begin() const { |
| 135 | return const_iterator(storage_->begin()); |
| 136 | } |
| 137 | |
| 138 | dict_iterator_proxy::iterator dict_iterator_proxy::end() { |
| 139 | return iterator(storage_->end()); |
| 140 | } |
| 141 | |
| 142 | dict_iterator_proxy::const_iterator dict_iterator_proxy::end() const { |
| 143 | return const_iterator(storage_->end()); |
| 144 | } |
| 145 | |
| 146 | dict_iterator_proxy::reverse_iterator dict_iterator_proxy::rbegin() { |
| 147 | return reverse_iterator(end()); |
| 148 | } |
| 149 | |
| 150 | dict_iterator_proxy::const_reverse_iterator dict_iterator_proxy::rbegin() |
| 151 | const { |
| 152 | return const_reverse_iterator(end()); |
| 153 | } |
| 154 | |
| 155 | dict_iterator_proxy::reverse_iterator dict_iterator_proxy::rend() { |
| 156 | return reverse_iterator(begin()); |
| 157 | } |
| 158 | |
| 159 | dict_iterator_proxy::const_reverse_iterator dict_iterator_proxy::rend() const { |
| 160 | return const_reverse_iterator(begin()); |
| 161 | } |
| 162 | |
| 163 | dict_iterator_proxy::const_iterator dict_iterator_proxy::cbegin() const { |
| 164 | return const_iterator(begin()); |
| 165 | } |
| 166 | |
| 167 | dict_iterator_proxy::const_iterator dict_iterator_proxy::cend() const { |
| 168 | return const_iterator(end()); |
| 169 | } |
| 170 | |
| 171 | dict_iterator_proxy::const_reverse_iterator dict_iterator_proxy::crbegin() |
| 172 | const { |
| 173 | return const_reverse_iterator(rbegin()); |
| 174 | } |
| 175 | |
| 176 | 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 | |
| 183 | const_dict_iterator_proxy::const_dict_iterator_proxy(const DictStorage* storage) |
| 184 | : storage_(storage) {} |
| 185 | |
| 186 | const_dict_iterator_proxy::const_iterator const_dict_iterator_proxy::begin() |
| 187 | const { |
| 188 | return const_iterator(storage_->begin()); |
| 189 | } |
| 190 | |
| 191 | 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 |
| 197 | const_dict_iterator_proxy::rbegin() const { |
| 198 | return const_reverse_iterator(end()); |
| 199 | } |
| 200 | |
| 201 | const_dict_iterator_proxy::const_reverse_iterator |
| 202 | const_dict_iterator_proxy::rend() const { |
| 203 | return const_reverse_iterator(begin()); |
| 204 | } |
| 205 | |
| 206 | const_dict_iterator_proxy::const_iterator const_dict_iterator_proxy::cbegin() |
| 207 | const { |
| 208 | return const_iterator(begin()); |
| 209 | } |
| 210 | |
| 211 | 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 |
| 217 | const_dict_iterator_proxy::crbegin() const { |
| 218 | return const_reverse_iterator(rbegin()); |
| 219 | } |
| 220 | |
| 221 | const_dict_iterator_proxy::const_reverse_iterator |
| 222 | const_dict_iterator_proxy::crend() const { |
| 223 | return const_reverse_iterator(rend()); |
| 224 | } |
| 225 | |
| 226 | } // namespace detail |
| 227 | |
| 228 | } // namespace base |