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_SLIST_ITERATOR_HPP
15#define BOOST_INTRUSIVE_SLIST_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/config_begin.hpp>
26#include <boost/intrusive/detail/workaround.hpp>
27#include <boost/intrusive/detail/std_fwd.hpp>
28#include <boost/intrusive/detail/iiterator.hpp>
29#include <boost/intrusive/detail/mpl.hpp>
30
31namespace boost {
32namespace intrusive {
33
34
35// slist_iterator provides some basic functions for a
36// node oriented bidirectional iterator:
37template<class ValueTraits, bool IsConst>
38class slist_iterator
39{
40 private:
41 typedef iiterator
42 <ValueTraits, IsConst, std::forward_iterator_tag> types_t;
43
44 static const bool stateful_value_traits = types_t::stateful_value_traits;
45
46 typedef ValueTraits value_traits;
47 typedef typename types_t::node_traits node_traits;
48
49 typedef typename types_t::node node;
50 typedef typename types_t::node_ptr node_ptr;
51 typedef typename types_t::const_value_traits_ptr const_value_traits_ptr;
52 class nat;
53 typedef typename
54 detail::if_c< IsConst
55 , slist_iterator<value_traits, false>
56 , nat>::type nonconst_iterator;
57
58 public:
59 typedef typename types_t::iterator_type::difference_type difference_type;
60 typedef typename types_t::iterator_type::value_type value_type;
61 typedef typename types_t::iterator_type::pointer pointer;
62 typedef typename types_t::iterator_type::reference reference;
63 typedef typename types_t::iterator_type::iterator_category iterator_category;
64
65 inline slist_iterator()
66 {}
67
68 inline slist_iterator(node_ptr nodeptr, const_value_traits_ptr traits_ptr)
69 : members_(nodeptr, traits_ptr)
70 {}
71
72 inline explicit slist_iterator(node_ptr nodeptr)
73 : members_(nodeptr, const_value_traits_ptr())
74 { BOOST_INTRUSIVE_STATIC_ASSERT((stateful_value_traits == false)); }
75
76 inline slist_iterator(const slist_iterator &other)
77 : members_(other.pointed_node(), other.get_value_traits())
78 {}
79
80 inline slist_iterator(const nonconst_iterator &other)
81 : members_(other.pointed_node(), other.get_value_traits())
82 {}
83
84 inline slist_iterator &operator=(const slist_iterator &other)
85 { members_.nodeptr_ = other.members_.nodeptr_; return *this; }
86
87 inline node_ptr pointed_node() const
88 { return members_.nodeptr_; }
89
90 inline slist_iterator &operator=(node_ptr n)
91 { members_.nodeptr_ = n; return static_cast<slist_iterator&>(*this); }
92
93 inline const_value_traits_ptr get_value_traits() const
94 { return members_.get_ptr(); }
95
96 inline bool operator!() const
97 { return !members_.nodeptr_; }
98
99 public:
100 inline slist_iterator& operator++()
101 {
102 members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
103 return static_cast<slist_iterator&> (*this);
104 }
105
106 inline slist_iterator operator++(int)
107 {
108 slist_iterator result (*this);
109 members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
110 return result;
111 }
112
113 inline friend bool operator== (const slist_iterator& l, const slist_iterator& r)
114 { return l.pointed_node() == r.pointed_node(); }
115
116 inline friend bool operator!= (const slist_iterator& l, const slist_iterator& r)
117 { return l.pointed_node() != r.pointed_node(); }
118
119 inline reference operator*() const
120 { return *operator->(); }
121
122 inline pointer operator->() const
123 { return this->operator_arrow(detail::bool_<stateful_value_traits>()); }
124
125 inline slist_iterator<ValueTraits, false> unconst() const
126 { return slist_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); }
127
128 private:
129
130 inline pointer operator_arrow(detail::false_) const
131 { return ValueTraits::to_value_ptr(members_.nodeptr_); }
132
133 inline pointer operator_arrow(detail::true_) const
134 { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); }
135
136 iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_;
137};
138
139} //namespace intrusive
140} //namespace boost
141
142#include <boost/intrusive/detail/config_end.hpp>
143
144#endif //BOOST_INTRUSIVE_SLIST_ITERATOR_HPP
145

source code of boost/libs/intrusive/include/boost/intrusive/detail/slist_iterator.hpp