| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CONTENT_BROWSER_INDEXED_DB_LIST_SET_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_LIST_SET_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_LIST_SET_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_LIST_SET_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 DCHECK_EQ(list_.empty(), set_.empty()); | 63 DCHECK_EQ(list_.empty(), set_.empty()); |
| 64 return set_.empty(); | 64 return set_.empty(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 class const_iterator; | 67 class const_iterator; |
| 68 | 68 |
| 69 class iterator { | 69 class iterator { |
| 70 public: | 70 public: |
| 71 typedef iterator self_type; | 71 typedef iterator self_type; |
| 72 typedef T value_type; | 72 typedef T value_type; |
| 73 typedef T& reference; | 73 typedef value_type& reference; |
| 74 typedef T* pointer; | 74 typedef value_type* pointer; |
| 75 typedef std::bidirectional_iterator_tag iterator_category; | 75 typedef std::bidirectional_iterator_tag iterator_category; |
| 76 typedef std::ptrdiff_t difference_type; | 76 typedef std::ptrdiff_t difference_type; |
| 77 | 77 |
| 78 explicit inline iterator(typename std::list<T>::iterator it) : it_(it) {} | 78 explicit iterator(typename std::list<T>::iterator it) : it_(it) {} |
| 79 inline self_type& operator++() { | 79 self_type& operator++() { |
| 80 ++it_; | 80 ++it_; |
| 81 return *this; | 81 return *this; |
| 82 } | 82 } |
| 83 inline self_type operator++(int /*ignored*/) { | 83 self_type operator++(int /*ignored*/) { |
| 84 self_type result(*this); | 84 self_type result(*this); |
| 85 ++(*this); | 85 ++(*this); |
| 86 return result; | 86 return result; |
| 87 } | 87 } |
| 88 inline self_type& operator--() { | 88 self_type& operator--() { |
| 89 --it_; | 89 --it_; |
| 90 return *this; | 90 return *this; |
| 91 } | 91 } |
| 92 inline self_type operator--(int /*ignored*/) { | 92 self_type operator--(int /*ignored*/) { |
| 93 self_type result(*this); | 93 self_type result(*this); |
| 94 --(*this); | 94 --(*this); |
| 95 return result; | 95 return result; |
| 96 } | 96 } |
| 97 inline value_type& operator*() { return *it_; } | 97 reference operator*() const { return *it_; } |
| 98 inline value_type* operator->() { return &(*it_); } | 98 pointer operator->() const { return &(*it_); } |
| 99 inline bool operator==(const iterator& rhs) const { return it_ == rhs.it_; } | 99 bool operator==(const iterator& rhs) const { return it_ == rhs.it_; } |
| 100 inline bool operator!=(const iterator& rhs) const { return it_ != rhs.it_; } | 100 bool operator!=(const iterator& rhs) const { return it_ != rhs.it_; } |
| 101 | 101 |
| 102 inline operator const_iterator() const { return const_iterator(it_); } | 102 inline operator const_iterator() const { return const_iterator(it_); } |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 typename std::list<T>::iterator it_; | 105 typename std::list<T>::iterator it_; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 class const_iterator { | 108 class const_iterator { |
| 109 public: | 109 public: |
| 110 typedef const_iterator self_type; | 110 typedef const_iterator self_type; |
| 111 typedef T value_type; | 111 typedef T value_type; |
| 112 typedef T& reference; | 112 typedef const value_type& reference; |
| 113 typedef T* pointer; | 113 typedef const value_type* pointer; |
| 114 typedef std::bidirectional_iterator_tag iterator_category; | 114 typedef std::bidirectional_iterator_tag iterator_category; |
| 115 typedef std::ptrdiff_t difference_type; | 115 typedef std::ptrdiff_t difference_type; |
| 116 | 116 |
| 117 explicit inline const_iterator(typename std::list<T>::const_iterator it) | 117 explicit inline const_iterator(typename std::list<T>::const_iterator it) |
| 118 : it_(it) {} | 118 : it_(it) {} |
| 119 inline self_type& operator++() { | 119 self_type& operator++() { |
| 120 ++it_; | 120 ++it_; |
| 121 return *this; | 121 return *this; |
| 122 } | 122 } |
| 123 inline self_type operator++(int ignored) { | 123 self_type operator++(int ignored) { |
| 124 self_type result(*this); | 124 self_type result(*this); |
| 125 ++(*this); | 125 ++(*this); |
| 126 return result; | 126 return result; |
| 127 } | 127 } |
| 128 inline self_type& operator--() { | 128 self_type& operator--() { |
| 129 --it_; | 129 --it_; |
| 130 return *this; | 130 return *this; |
| 131 } | 131 } |
| 132 inline self_type operator--(int ignored) { | 132 self_type operator--(int ignored) { |
| 133 self_type result(*this); | 133 self_type result(*this); |
| 134 --(*this); | 134 --(*this); |
| 135 return result; | 135 return result; |
| 136 } | 136 } |
| 137 inline const value_type& operator*() { return *it_; } | 137 reference operator*() const { return *it_; } |
| 138 inline const value_type* operator->() { return &(*it_); } | 138 pointer operator->() const { return &(*it_); } |
| 139 inline bool operator==(const const_iterator& rhs) const { | 139 bool operator==(const const_iterator& rhs) const { return it_ == rhs.it_; } |
| 140 return it_ == rhs.it_; | 140 bool operator!=(const const_iterator& rhs) const { return it_ != rhs.it_; } |
| 141 } | |
| 142 inline bool operator!=(const const_iterator& rhs) const { | |
| 143 return it_ != rhs.it_; | |
| 144 } | |
| 145 | 141 |
| 146 private: | 142 private: |
| 147 typename std::list<T>::const_iterator it_; | 143 typename std::list<T>::const_iterator it_; |
| 148 }; | 144 }; |
| 149 | 145 |
| 150 iterator begin() { return iterator(list_.begin()); } | 146 iterator begin() { return iterator(list_.begin()); } |
| 151 iterator end() { return iterator(list_.end()); } | 147 iterator end() { return iterator(list_.end()); } |
| 152 const_iterator begin() const { return const_iterator(list_.begin()); } | 148 const_iterator begin() const { return const_iterator(list_.begin()); } |
| 153 const_iterator end() const { return const_iterator(list_.end()); } | 149 const_iterator end() const { return const_iterator(list_.end()); } |
| 154 | 150 |
| 155 private: | 151 private: |
| 156 std::list<T> list_; | 152 std::list<T> list_; |
| 157 std::set<T> set_; | 153 std::set<T> set_; |
| 158 }; | 154 }; |
| 159 | 155 |
| 160 // Prevent instantiation of list_set<std::unique_ptr<T>> as the current | 156 // Prevent instantiation of list_set<std::unique_ptr<T>> as the current |
| 161 // implementation would fail. | 157 // implementation would fail. |
| 162 // TODO(jsbell): Support scoped_ptr through specialization. | 158 // TODO(jsbell): Support scoped_ptr through specialization. |
| 163 template <typename T> | 159 template <typename T> |
| 164 class list_set<std::unique_ptr<T>>; | 160 class list_set<std::unique_ptr<T>>; |
| 165 | 161 |
| 166 #endif // CONTENT_BROWSER_INDEXED_DB_LIST_SET_H_ | 162 #endif // CONTENT_BROWSER_INDEXED_DB_LIST_SET_H_ |
| OLD | NEW |