• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    class nat;
51    typedef typename
52       detail::if_c< IsConst
53                   , list_iterator<value_traits, false>
54                   , nat>::type                              nonconst_iterator;
55 
56    public:
57    typedef typename types_t::iterator_type::difference_type    difference_type;
58    typedef typename types_t::iterator_type::value_type         value_type;
59    typedef typename types_t::iterator_type::pointer            pointer;
60    typedef typename types_t::iterator_type::reference          reference;
61    typedef typename types_t::iterator_type::iterator_category  iterator_category;
62 
list_iterator()63    BOOST_INTRUSIVE_FORCEINLINE list_iterator()
64    {}
65 
list_iterator(const node_ptr & nodeptr,const const_value_traits_ptr & traits_ptr)66    BOOST_INTRUSIVE_FORCEINLINE explicit list_iterator(const node_ptr & nodeptr, const const_value_traits_ptr &traits_ptr)
67       : members_(nodeptr, traits_ptr)
68    {}
69 
list_iterator(const list_iterator & other)70    BOOST_INTRUSIVE_FORCEINLINE list_iterator(const list_iterator &other)
71       :  members_(other.pointed_node(), other.get_value_traits())
72    {}
73 
list_iterator(const nonconst_iterator & other)74    BOOST_INTRUSIVE_FORCEINLINE list_iterator(const nonconst_iterator &other)
75       :  members_(other.pointed_node(), other.get_value_traits())
76    {}
77 
operator =(const list_iterator & other)78    BOOST_INTRUSIVE_FORCEINLINE list_iterator &operator=(const list_iterator &other)
79    {  members_.nodeptr_ = other.members_.nodeptr_;  return *this;  }
80 
pointed_node() const81    BOOST_INTRUSIVE_FORCEINLINE node_ptr pointed_node() const
82    { return members_.nodeptr_; }
83 
operator =(const node_ptr & node)84    BOOST_INTRUSIVE_FORCEINLINE list_iterator &operator=(const node_ptr &node)
85    {  members_.nodeptr_ = node;  return *this;  }
86 
get_value_traits() const87    BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr get_value_traits() const
88    {  return members_.get_ptr(); }
89 
90    public:
operator ++()91    BOOST_INTRUSIVE_FORCEINLINE list_iterator& operator++()
92    {
93       node_ptr p = node_traits::get_next(members_.nodeptr_);
94       members_.nodeptr_ = p;
95       return static_cast<list_iterator&> (*this);
96    }
97 
operator ++(int)98    BOOST_INTRUSIVE_FORCEINLINE list_iterator operator++(int)
99    {
100       list_iterator result (*this);
101       members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
102       return result;
103    }
104 
operator --()105    BOOST_INTRUSIVE_FORCEINLINE list_iterator& operator--()
106    {
107       members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
108       return static_cast<list_iterator&> (*this);
109    }
110 
operator --(int)111    BOOST_INTRUSIVE_FORCEINLINE list_iterator operator--(int)
112    {
113       list_iterator result (*this);
114       members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
115       return result;
116    }
117 
operator ==(const list_iterator & l,const list_iterator & r)118    BOOST_INTRUSIVE_FORCEINLINE friend bool operator== (const list_iterator& l, const list_iterator& r)
119    {  return l.pointed_node() == r.pointed_node();   }
120 
operator !=(const list_iterator & l,const list_iterator & r)121    BOOST_INTRUSIVE_FORCEINLINE friend bool operator!= (const list_iterator& l, const list_iterator& r)
122    {  return !(l == r); }
123 
operator *() const124    BOOST_INTRUSIVE_FORCEINLINE reference operator*() const
125    {  return *operator->();   }
126 
operator ->() const127    BOOST_INTRUSIVE_FORCEINLINE pointer operator->() const
128    { return this->operator_arrow(detail::bool_<stateful_value_traits>()); }
129 
unconst() const130    BOOST_INTRUSIVE_FORCEINLINE list_iterator<ValueTraits, false> unconst() const
131    {  return list_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits());   }
132 
133    private:
operator_arrow(detail::false_) const134    BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::false_) const
135    { return ValueTraits::to_value_ptr(members_.nodeptr_); }
136 
operator_arrow(detail::true_) const137    BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::true_) const
138    { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); }
139 
140    iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_;
141 };
142 
143 } //namespace intrusive
144 } //namespace boost
145 
146 #endif //BOOST_INTRUSIVE_LIST_ITERATOR_HPP
147