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