1/////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Olaf Krzikalla 2004-2006.
4// (C) Copyright Ion Gaztanaga 2006-2013
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10// See http://www.boost.org/libs/intrusive for documentation.
11//
12/////////////////////////////////////////////////////////////////////////////
13
14#ifndef BOOST_INTRUSIVE_LIST_ITERATOR_HPP
15#define BOOST_INTRUSIVE_LIST_ITERATOR_HPP
16
17#ifndef BOOST_CONFIG_HPP
18# include <boost/config.hpp>
19#endif
20
21#if defined(BOOST_HAS_PRAGMA_ONCE)
22# pragma once
23#endif
24
25#include <boost/intrusive/detail/std_fwd.hpp>
26#include <boost/intrusive/detail/iiterator.hpp>
27#include <boost/intrusive/detail/mpl.hpp>
28
29namespace boost {
30namespace intrusive {
31
32// list_iterator provides some basic functions for a
33// node oriented bidirectional iterator:
34template<class ValueTraits, bool IsConst>
35class list_iterator
36{
37 protected:
38 typedef iiterator
39 <ValueTraits, IsConst, std::bidirectional_iterator_tag> types_t;
40
41 static const bool stateful_value_traits = types_t::stateful_value_traits;
42
43 typedef ValueTraits value_traits;
44 typedef typename types_t::node_traits node_traits;
45
46 typedef typename types_t::node node;
47 typedef typename types_t::node_ptr node_ptr;
48 typedef typename types_t::const_value_traits_ptr const_value_traits_ptr;
49
50 public:
51 typedef typename types_t::iterator_traits::difference_type difference_type;
52 typedef typename types_t::iterator_traits::value_type value_type;
53 typedef typename types_t::iterator_traits::pointer pointer;
54 typedef typename types_t::iterator_traits::reference reference;
55 typedef typename types_t::iterator_traits::iterator_category iterator_category;
56
57 list_iterator()
58 {}
59
60 explicit list_iterator(const node_ptr & nodeptr, const const_value_traits_ptr &traits_ptr)
61 : members_(nodeptr, traits_ptr)
62 {}
63
64 list_iterator(list_iterator<ValueTraits, false> const& other)
65 : members_(other.pointed_node(), other.get_value_traits())
66 {}
67
68 const node_ptr &pointed_node() const
69 { return members_.nodeptr_; }
70
71 list_iterator &operator=(const node_ptr &node)
72 { members_.nodeptr_ = node; return static_cast<list_iterator&>(*this); }
73
74 const_value_traits_ptr get_value_traits() const
75 { return members_.get_ptr(); }
76
77 public:
78 list_iterator& operator++()
79 {
80 node_ptr p = node_traits::get_next(members_.nodeptr_);
81 members_.nodeptr_ = p;
82 return static_cast<list_iterator&> (*this);
83 }
84
85 list_iterator operator++(int)
86 {
87 list_iterator result (*this);
88 members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
89 return result;
90 }
91
92 list_iterator& operator--()
93 {
94 members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
95 return static_cast<list_iterator&> (*this);
96 }
97
98 list_iterator operator--(int)
99 {
100 list_iterator result (*this);
101 members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
102 return result;
103 }
104
105 friend bool operator== (const list_iterator& l, const list_iterator& r)
106 { return l.pointed_node() == r.pointed_node(); }
107
108 friend bool operator!= (const list_iterator& l, const list_iterator& r)
109 { return !(l == r); }
110
111 reference operator*() const
112 { return *operator->(); }
113
114 pointer operator->() const
115 { return this->operator_arrow(detail::bool_<stateful_value_traits>()); }
116
117 list_iterator<ValueTraits, false> unconst() const
118 { return list_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); }
119
120 private:
121 pointer operator_arrow(detail::false_) const
122 { return ValueTraits::to_value_ptr(members_.nodeptr_); }
123
124 pointer operator_arrow(detail::true_) const
125 { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); }
126
127 iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_;
128};
129
130} //namespace intrusive
131} //namespace boost
132
133#endif //BOOST_INTRUSIVE_LIST_ITERATOR_HPP
134