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 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 slist_iterator()65 BOOST_INTRUSIVE_FORCEINLINE slist_iterator() 66 {} 67 slist_iterator(const node_ptr & nodeptr,const const_value_traits_ptr & traits_ptr)68 BOOST_INTRUSIVE_FORCEINLINE explicit slist_iterator(const node_ptr & nodeptr, const const_value_traits_ptr &traits_ptr) 69 : members_(nodeptr, traits_ptr) 70 {} 71 slist_iterator(const slist_iterator & other)72 BOOST_INTRUSIVE_FORCEINLINE slist_iterator(const slist_iterator &other) 73 : members_(other.pointed_node(), other.get_value_traits()) 74 {} 75 slist_iterator(const nonconst_iterator & other)76 BOOST_INTRUSIVE_FORCEINLINE slist_iterator(const nonconst_iterator &other) 77 : members_(other.pointed_node(), other.get_value_traits()) 78 {} 79 operator =(const slist_iterator & other)80 BOOST_INTRUSIVE_FORCEINLINE slist_iterator &operator=(const slist_iterator &other) 81 { members_.nodeptr_ = other.members_.nodeptr_; return *this; } 82 pointed_node() const83 BOOST_INTRUSIVE_FORCEINLINE node_ptr pointed_node() const 84 { return members_.nodeptr_; } 85 operator =(const node_ptr & node)86 BOOST_INTRUSIVE_FORCEINLINE slist_iterator &operator=(const node_ptr &node) 87 { members_.nodeptr_ = node; return static_cast<slist_iterator&>(*this); } 88 get_value_traits() const89 BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr get_value_traits() const 90 { return members_.get_ptr(); } 91 92 public: operator ++()93 BOOST_INTRUSIVE_FORCEINLINE slist_iterator& operator++() 94 { 95 members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); 96 return static_cast<slist_iterator&> (*this); 97 } 98 operator ++(int)99 BOOST_INTRUSIVE_FORCEINLINE slist_iterator operator++(int) 100 { 101 slist_iterator result (*this); 102 members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); 103 return result; 104 } 105 operator ==(const slist_iterator & l,const slist_iterator & r)106 BOOST_INTRUSIVE_FORCEINLINE friend bool operator== (const slist_iterator& l, const slist_iterator& r) 107 { return l.pointed_node() == r.pointed_node(); } 108 operator !=(const slist_iterator & l,const slist_iterator & r)109 BOOST_INTRUSIVE_FORCEINLINE friend bool operator!= (const slist_iterator& l, const slist_iterator& r) 110 { return !(l == r); } 111 operator *() const112 BOOST_INTRUSIVE_FORCEINLINE reference operator*() const 113 { return *operator->(); } 114 operator ->() const115 BOOST_INTRUSIVE_FORCEINLINE pointer operator->() const 116 { return this->operator_arrow(detail::bool_<stateful_value_traits>()); } 117 unconst() const118 BOOST_INTRUSIVE_FORCEINLINE slist_iterator<ValueTraits, false> unconst() const 119 { return slist_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); } 120 121 private: 122 operator_arrow(detail::false_) const123 BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::false_) const 124 { return ValueTraits::to_value_ptr(members_.nodeptr_); } 125 operator_arrow(detail::true_) const126 BOOST_INTRUSIVE_FORCEINLINE pointer operator_arrow(detail::true_) const 127 { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); } 128 129 iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_; 130 }; 131 132 } //namespace intrusive 133 } //namespace boost 134 135 #include <boost/intrusive/detail/config_end.hpp> 136 137 #endif //BOOST_INTRUSIVE_SLIST_ITERATOR_HPP 138