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