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 // Idea for Base template argument to prevent having to repeat
34 // the base class declaration comes from newbiz on ##c++/Freenode
35 //
36 // If Iterator is SCARY then this iterator will be as well.
37 template <
38  bool is_const,
39  class Iterator,
40  class Base =
43  typename std::conditional <is_const,
44  typename Iterator::value_type::stashed::value_type const,
45  typename Iterator::value_type::stashed::value_type>::type,
47 >
49  : public Base
50 {
51 public:
52  using time_point = typename Iterator::value_type::stashed::time_point;
53 
54  aged_container_iterator() = default;
55 
56  // Disable constructing a const_iterator from a non-const_iterator.
57  // Converting between reverse and non-reverse iterators should be explicit.
58  template <bool other_is_const, class OtherIterator, class OtherBase,
59  class = typename std::enable_if <
60  (other_is_const == false || is_const == true) &&
63  other_is_const, OtherIterator, OtherBase> const& other)
64  : m_iter (other.m_iter)
65  {
66  }
67 
68  // Disable constructing a const_iterator from a non-const_iterator.
69  template <bool other_is_const, class OtherBase,
70  class = typename std::enable_if <
71  other_is_const == false || is_const == true>::type>
73  other_is_const, Iterator, OtherBase> const& other)
74  : m_iter (other.m_iter)
75  {
76  }
77 
78  // Disable assigning a const_iterator to a non-const iterator
79  template <bool other_is_const, class OtherIterator, class OtherBase>
80  auto
82  other_is_const, OtherIterator, OtherBase> const& other) ->
83  typename std::enable_if <
84  other_is_const == false || is_const == true,
86  {
87  m_iter = other.m_iter;
88  return *this;
89  }
90 
91  template <bool other_is_const, class OtherIterator, class OtherBase>
93  other_is_const, OtherIterator, OtherBase> const& other) const
94  {
95  return m_iter == other.m_iter;
96  }
97 
98  template <bool other_is_const, class OtherIterator, class OtherBase>
100  other_is_const, OtherIterator, OtherBase> const& other) const
101  {
102  return m_iter != other.m_iter;
103  }
104 
106  {
107  ++m_iter;
108  return *this;
109  }
110 
112  {
113  aged_container_iterator const prev (*this);
114  ++m_iter;
115  return prev;
116  }
117 
119  {
120  --m_iter;
121  return *this;
122  }
123 
125  {
126  aged_container_iterator const prev (*this);
127  --m_iter;
128  return prev;
129  }
130 
131  typename Base::reference operator* () const
132  {
133  return m_iter->value;
134  }
135 
136  typename Base::pointer operator-> () const
137  {
138  return &m_iter->value;
139  }
140 
141  time_point const& when () const
142  {
143  return m_iter->when;
144  }
145 
146 private:
147  template <bool, bool, class, class, class, class, class>
149 
150  template <bool, bool, class, class, class, class, class, class>
152 
153  template <bool, class, class>
155 
156  template <class OtherIterator>
157  aged_container_iterator (OtherIterator const& iter)
158  : m_iter (iter)
159  {
160  }
161 
162  Iterator const& iterator() const
163  {
164  return m_iter;
165  }
166 
167  Iterator m_iter;
168 };
169 
170 }
171 
172 }
173 
174 #endif
beast::detail::aged_container_iterator::operator=
auto operator=(aged_container_iterator< other_is_const, OtherIterator, OtherBase > const &other) -> typename std::enable_if< other_is_const==false||is_const==true, aged_container_iterator & >::type
Definition: aged_container_iterator.h:81
std::is_same
beast::detail::aged_container_iterator::operator++
aged_container_iterator & operator++()
Definition: aged_container_iterator.h:105
beast::detail::aged_container_iterator::operator==
bool operator==(aged_container_iterator< other_is_const, OtherIterator, OtherBase > const &other) const
Definition: aged_container_iterator.h:92
beast::detail::aged_container_iterator::when
time_point const & when() const
Definition: aged_container_iterator.h:141
beast::detail::aged_container_iterator::m_iter
Iterator m_iter
Definition: aged_container_iterator.h:167
iterator
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(aged_container_iterator< other_is_const, Iterator, OtherBase > const &other)
Definition: aged_container_iterator.h:72
beast::detail::aged_container_iterator::operator!=
bool operator!=(aged_container_iterator< other_is_const, OtherIterator, OtherBase > const &other) const
Definition: aged_container_iterator.h:99
beast::detail::aged_container_iterator::operator*
Base::reference operator*() const
Definition: aged_container_iterator.h:131
std::enable_if
std::iterator_traits
beast::detail::aged_container_iterator::operator--
aged_container_iterator & operator--()
Definition: aged_container_iterator.h:118
beast::aged_ordered_container
Definition: aged_container_iterator.h:29
beast::detail::aged_container_iterator::time_point
typename Iterator::value_type::stashed::time_point time_point
Definition: aged_container_iterator.h:52
beast::detail::aged_container_iterator::aged_container_iterator
friend class aged_container_iterator
Definition: aged_container_iterator.h:154
beast::detail::aged_unordered_container
Associative container where each element is also indexed by time.
Definition: aged_unordered_container.h:88
beast::detail::aged_ordered_container
Associative container where each element is also indexed by time.
Definition: aged_ordered_container.h:86
beast::detail::aged_container_iterator::iterator
Iterator const & iterator() const
Definition: aged_container_iterator.h:162
std::conditional
beast::detail::aged_container_iterator::aged_container_iterator
aged_container_iterator(OtherIterator const &iter)
Definition: aged_container_iterator.h:157
type_traits
beast::detail::aged_container_iterator::operator->
Base::pointer operator->() const
Definition: aged_container_iterator.h:136
beast::detail::aged_container_iterator
Definition: aged_container_iterator.h:48
beast
Definition: base_uint.h:582