rippled
aged_container_iterator.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of Beast: https://github.com/vinniefalco/Beast
4  Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef BEAST_CONTAINER_DETAIL_AGED_CONTAINER_ITERATOR_H_INCLUDED
21 #define BEAST_CONTAINER_DETAIL_AGED_CONTAINER_ITERATOR_H_INCLUDED
22 
23 #include <iterator>
24 #include <type_traits>
25 
26 namespace beast {
27 
28 template <bool, bool, class, class, class, class, class>
30 
31 namespace detail {
32 
33 // If Iterator is SCARY then this iterator will be as well.
34 template <bool is_const, class Iterator>
36 {
37 public:
38  using iterator_category =
40  using value_type = typename std::conditional<
41  is_const,
42  typename Iterator::value_type::stashed::value_type const,
43  typename Iterator::value_type::stashed::value_type>::type;
44  using difference_type =
46  using pointer = value_type*;
48  using time_point = typename Iterator::value_type::stashed::time_point;
49 
50  aged_container_iterator() = default;
51 
52  // Disable constructing a const_iterator from a non-const_iterator.
53  // Converting between reverse and non-reverse iterators should be explicit.
54  template <
55  bool other_is_const,
56  class OtherIterator,
57  class = typename std::enable_if<
58  (other_is_const == false || is_const == true) &&
62  : m_iter(other.m_iter)
63  {
64  }
65 
66  // Disable constructing a const_iterator from a non-const_iterator.
67  template <
68  bool other_is_const,
69  class = typename std::enable_if<
70  other_is_const == false || is_const == true>::type>
73  : m_iter(other.m_iter)
74  {
75  }
76 
77  // Disable assigning a const_iterator to a non-const iterator
78  template <bool other_is_const, class OtherIterator>
79  auto
82  typename std::enable_if<
83  other_is_const == false || is_const == true,
85  {
86  m_iter = other.m_iter;
87  return *this;
88  }
89 
90  template <bool other_is_const, class OtherIterator>
91  bool
93  other) const
94  {
95  return m_iter == other.m_iter;
96  }
97 
98  template <bool other_is_const, class OtherIterator>
99  bool
101  other) const
102  {
103  return m_iter != other.m_iter;
104  }
105 
108  {
109  ++m_iter;
110  return *this;
111  }
112 
115  {
116  aged_container_iterator const prev(*this);
117  ++m_iter;
118  return prev;
119  }
120 
123  {
124  --m_iter;
125  return *this;
126  }
127 
130  {
131  aged_container_iterator const prev(*this);
132  --m_iter;
133  return prev;
134  }
135 
136  reference
137  operator*() const
138  {
139  return m_iter->value;
140  }
141 
142  pointer
143  operator->() const
144  {
145  return &m_iter->value;
146  }
147 
148  time_point const&
149  when() const
150  {
151  return m_iter->when;
152  }
153 
154 private:
155  template <bool, bool, class, class, class, class, class>
157 
158  template <bool, bool, class, class, class, class, class, class>
160 
161  template <bool, class>
163 
164  template <class OtherIterator>
165  aged_container_iterator(OtherIterator const& iter) : m_iter(iter)
166  {
167  }
168 
169  Iterator const&
170  iterator() const
171  {
172  return m_iter;
173  }
174 
175  Iterator m_iter;
176 };
177 
178 } // namespace detail
179 
180 } // namespace beast
181 
182 #endif
beast::detail::aged_container_iterator::operator--
aged_container_iterator & operator--()
Definition: aged_container_iterator.h:122
std::is_same
beast::detail::aged_container_iterator::m_iter
Iterator m_iter
Definition: aged_container_iterator.h:175
beast::detail::aged_container_iterator::operator--
aged_container_iterator operator--(int)
Definition: aged_container_iterator.h:129
beast::detail::aged_container_iterator::when
time_point const & when() const
Definition: aged_container_iterator.h:149
beast::detail::aged_container_iterator::operator==
bool operator==(aged_container_iterator< other_is_const, OtherIterator > const &other) const
Definition: aged_container_iterator.h:92
beast::detail::aged_container_iterator::pointer
value_type * pointer
Definition: aged_container_iterator.h:46
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(aged_container_iterator< other_is_const, Iterator > const &other)
Definition: aged_container_iterator.h:71
iterator
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(aged_container_iterator< other_is_const, OtherIterator > const &other)
Definition: aged_container_iterator.h:60
beast::detail::aged_container_iterator::operator++
aged_container_iterator operator++(int)
Definition: aged_container_iterator.h:114
beast::detail::aged_container_iterator::operator->
pointer operator->() const
Definition: aged_container_iterator.h:143
beast::detail::aged_container_iterator::operator!=
bool operator!=(aged_container_iterator< other_is_const, OtherIterator > const &other) const
Definition: aged_container_iterator.h:100
std::enable_if
beast::detail::aged_container_iterator::operator++
aged_container_iterator & operator++()
Definition: aged_container_iterator.h:107
std::iterator_traits
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(OtherIterator const &iter)
Definition: aged_container_iterator.h:165
beast::detail::aged_container_iterator::difference_type
typename std::iterator_traits< Iterator >::difference_type difference_type
Definition: aged_container_iterator.h:45
beast::aged_ordered_container
Definition: aged_container_iterator.h:29
beast::detail::aged_container_iterator::iterator
Iterator const & iterator() const
Definition: aged_container_iterator.h:170
beast::detail::aged_container_iterator::iterator_category
typename std::iterator_traits< Iterator >::iterator_category iterator_category
Definition: aged_container_iterator.h:39
beast::detail::aged_unordered_container
Associative container where each element is also indexed by time.
Definition: aged_unordered_container.h:85
beast::detail::aged_ordered_container
Associative container where each element is also indexed by time.
Definition: aged_ordered_container.h:82
beast::detail::aged_container_iterator::operator*
reference operator*() const
Definition: aged_container_iterator.h:137
beast::detail::aged_container_iterator::operator=
auto operator=(aged_container_iterator< other_is_const, OtherIterator > const &other) -> typename std::enable_if< other_is_const==false||is_const==true, aged_container_iterator & >::type
Definition: aged_container_iterator.h:80
beast::detail::aged_container_iterator::time_point
typename Iterator::value_type::stashed::time_point time_point
Definition: aged_container_iterator.h:48
std::conditional
type_traits
beast::detail::aged_container_iterator
Definition: aged_container_iterator.h:35
beast::detail::aged_container_iterator::value_type
typename std::conditional< is_const, typename Iterator::value_type::stashed::value_type const, typename Iterator::value_type::stashed::value_type >::type value_type
Definition: aged_container_iterator.h:43
beast::detail::aged_container_iterator::aged_container_iterator
friend class aged_container_iterator
Definition: aged_container_iterator.h:162
beast::detail::aged_container_iterator::reference
value_type & reference
Definition: aged_container_iterator.h:47
beast
Definition: base_uint.h:641