1 /////////////////////////////////////////////////////////////////////////////
\r
3 // (C) Copyright Olaf Krzikalla 2004-2006.
\r
4 // (C) Copyright Ion GaztaƱaga 2006-2007
\r
6 // Distributed under the Boost Software License, Version 1.0.
\r
7 // (See accompanying file LICENSE_1_0.txt or copy at
\r
8 // http://www.boost.org/LICENSE_1_0.txt)
\r
10 // See http://www.boost.org/libs/intrusive for documentation.
\r
12 /////////////////////////////////////////////////////////////////////////////
\r
14 #ifndef BOOST_INTRUSIVE_SLIST_NODE_HPP
\r
15 #define BOOST_INTRUSIVE_SLIST_NODE_HPP
\r
17 #include "config_begin.hpp"
\r
19 #include <boost/assert.hpp>
\r
20 #include "pointer_type.hpp"
\r
21 #include "pointer_to_other.hpp"
\r
22 #include "../slist_algorithms.hpp"
\r
23 #include <boost/get_pointer.hpp>
\r
27 namespace intrusive {
\r
30 // slist_node_traits can be used with slist_algorithms and supplies
\r
31 // a list_node holding the pointers needed for a double-linked list
\r
32 // it is used by islist_derived_node and islist_member_node
\r
33 template<class VoidPointer>
\r
34 struct slist_node_traits
\r
38 typedef typename boost::pointer_to_other
\r
39 <VoidPointer, node>::type node_ptr;
\r
40 typedef typename boost::pointer_to_other
\r
41 <VoidPointer, const node>::type const_node_ptr;
\r
48 static node_ptr get_next(const_node_ptr n)
\r
49 { return n->next_; }
\r
51 static void set_next(node_ptr n, node_ptr next)
\r
52 { n->next_ = next; }
\r
56 // slist_iterator provides some basic functions for a
\r
57 // node oriented forward iterator:
\r
58 template<class T, class Self, class NodeTraits>
\r
59 class slist_iterator
\r
60 : public std::iterator<std::forward_iterator_tag, T>
\r
63 typedef typename NodeTraits::node node;
\r
64 typedef typename NodeTraits::node_ptr node_ptr;
\r
70 explicit slist_iterator (node_ptr node)
\r
74 node_ptr list_node() const
\r
77 Self &operator=(const node_ptr &node)
\r
78 { node_ = node; return static_cast<Self&>(*this); }
\r
83 node_ = NodeTraits::get_next(node_);
\r
84 return static_cast<Self&> (*this);
\r
87 Self operator++(int)
\r
89 Self result (node_);
\r
90 node_ = NodeTraits::get_next(node_);
\r
94 bool operator== (const Self& i) const
\r
95 { return node_ == i.list_node(); }
\r
97 bool operator!= (const Self& i) const
\r
98 { return !operator== (i); }
\r
104 } //namespace detail
\r
105 } //namespace intrusive
\r
106 } //namespace boost
\r
108 #include "config_end.hpp"
\r
110 #endif //BOOST_INTRUSIVE_SLIST_NODE_HPP
\r