1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128

base / value_iterators.cc [blame]

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/value_iterators.h"

#include "base/values.h"

namespace base {

namespace detail {

// ----------------------------------------------------------------------------
// dict_iterator.

dict_iterator::pointer::pointer(const reference& ref) : ref_(ref) {}

dict_iterator::pointer::pointer(const pointer& ptr) = default;

dict_iterator::dict_iterator(DictStorage::iterator dict_iter)
    : dict_iter_(dict_iter) {}

dict_iterator::dict_iterator(const dict_iterator& dict_iter) = default;

dict_iterator& dict_iterator::operator=(const dict_iterator& dict_iter) =
    default;

dict_iterator::~dict_iterator() = default;

dict_iterator::reference dict_iterator::operator*() {
  return {dict_iter_->first, *dict_iter_->second};
}

dict_iterator::pointer dict_iterator::operator->() {
  return pointer(operator*());
}

dict_iterator& dict_iterator::operator++() {
  ++dict_iter_;
  return *this;
}

dict_iterator dict_iterator::operator++(int) {
  dict_iterator tmp(*this);
  ++dict_iter_;
  return tmp;
}

dict_iterator& dict_iterator::operator--() {
  --dict_iter_;
  return *this;
}

dict_iterator dict_iterator::operator--(int) {
  dict_iterator tmp(*this);
  --dict_iter_;
  return tmp;
}

bool operator==(const dict_iterator& lhs, const dict_iterator& rhs) {
  return lhs.dict_iter_ == rhs.dict_iter_;
}

bool operator!=(const dict_iterator& lhs, const dict_iterator& rhs) {
  return !(lhs == rhs);
}

// ----------------------------------------------------------------------------
// const_dict_iterator.

const_dict_iterator::pointer::pointer(const reference& ref) : ref_(ref) {}

const_dict_iterator::pointer::pointer(const pointer& ptr) = default;

const_dict_iterator::const_dict_iterator(DictStorage::const_iterator dict_iter)
    : dict_iter_(dict_iter) {}

const_dict_iterator::const_dict_iterator(const const_dict_iterator& dict_iter) =
    default;

const_dict_iterator& const_dict_iterator::operator=(
    const const_dict_iterator& dict_iter) = default;

const_dict_iterator::~const_dict_iterator() = default;

const_dict_iterator::reference const_dict_iterator::operator*() const {
  return {dict_iter_->first, *dict_iter_->second};
}

const_dict_iterator::pointer const_dict_iterator::operator->() const {
  return pointer(operator*());
}

const_dict_iterator& const_dict_iterator::operator++() {
  ++dict_iter_;
  return *this;
}

const_dict_iterator const_dict_iterator::operator++(int) {
  const_dict_iterator tmp(*this);
  ++dict_iter_;
  return tmp;
}

const_dict_iterator& const_dict_iterator::operator--() {
  --dict_iter_;
  return *this;
}

const_dict_iterator const_dict_iterator::operator--(int) {
  const_dict_iterator tmp(*this);
  --dict_iter_;
  return tmp;
}

bool operator==(const const_dict_iterator& lhs,
                const const_dict_iterator& rhs) {
  return lhs.dict_iter_ == rhs.dict_iter_;
}

bool operator!=(const const_dict_iterator& lhs,
                const const_dict_iterator& rhs) {
  return !(lhs == rhs);
}

}  // namespace detail

}  // namespace base