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 | |
31 | namespace boost { |
32 | namespace intrusive { |
33 | |
34 | |
35 | // slist_iterator provides some basic functions for a |
36 | // node oriented bidirectional iterator: |
37 | template<class ValueTraits, bool IsConst> |
38 | class 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 | |
53 | public: |
54 | typedef typename types_t::iterator_type::difference_type difference_type; |
55 | typedef typename types_t::iterator_type::value_type value_type; |
56 | typedef typename types_t::iterator_type::pointer pointer; |
57 | typedef typename types_t::iterator_type::reference reference; |
58 | typedef typename types_t::iterator_type::iterator_category iterator_category; |
59 | |
60 | BOOST_INTRUSIVE_FORCEINLINE slist_iterator() |
61 | {} |
62 | |
63 | BOOST_INTRUSIVE_FORCEINLINE explicit slist_iterator(const node_ptr & nodeptr, const const_value_traits_ptr &traits_ptr) |
64 | : members_(nodeptr, traits_ptr) |
65 | {} |
66 | |
67 | BOOST_INTRUSIVE_FORCEINLINE slist_iterator(slist_iterator<ValueTraits, false> const& other) |
68 | : members_(other.pointed_node(), other.get_value_traits()) |
69 | {} |
70 | |
71 | BOOST_INTRUSIVE_FORCEINLINE const node_ptr &pointed_node() const |
72 | { return members_.nodeptr_; } |
73 | |
74 | BOOST_INTRUSIVE_FORCEINLINE slist_iterator &operator=(const node_ptr &node) |
75 | { members_.nodeptr_ = node; return static_cast<slist_iterator&>(*this); } |
76 | |
77 | BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr get_value_traits() const |
78 | { return members_.get_ptr(); } |
79 | |
80 | public: |
81 | BOOST_INTRUSIVE_FORCEINLINE slist_iterator& operator++() |
82 | { |
83 | members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); |
84 | return static_cast<slist_iterator&> (*this); |
85 | } |
86 | |
87 | BOOST_INTRUSIVE_FORCEINLINE slist_iterator operator++(int) |
88 | { |
89 | slist_iterator result (*this); |
90 | members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); |
91 | return result; |
92 | } |
93 | |
94 | BOOST_INTRUSIVE_FORCEINLINE friend bool operator== (const slist_iterator& l, const slist_iterator& r) |
95 | { return l.pointed_node() == r.pointed_node(); } |
96 | |
97 | BOOST_INTRUSIVE_FORCEINLINE friend bool operator!= (const slist_iterator& l, const slist_iterator& r) |
98 | { return !(l == r); } |
99 | |
100 | BOOST_INTRUSIVE_FORCEINLINE reference operator*() const |
101 | { return *operator->(); } |
102 | |
103 | BOOST_INTRUSIVE_FORCEINLINE pointer operator->() const |
104 | { return this->operator_arrow(detail::bool_<stateful_value_traits>()); } |
105 | |
106 | BOOST_INTRUSIVE_FORCEINLINE slist_iterator<ValueTraits, false> unconst() const |
107 | { return slist_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); } |
108 | |
109 | private: |
110 | |
111 | BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::false_) const |
112 | { return ValueTraits::to_value_ptr(members_.nodeptr_); } |
113 | |
114 | BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::true_) const |
115 | { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); } |
116 | |
117 | iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_; |
118 | }; |
119 | |
120 | } //namespace intrusive |
121 | } //namespace boost |
122 | |
123 | #include <boost/intrusive/detail/config_end.hpp> |
124 | |
125 | #endif //BOOST_INTRUSIVE_SLIST_ITERATOR_HPP |
126 | |