d3ea2f31bc9eec0f8b1a3ff6ef96f8ab64fce95e
[senf.git] / boost / intrusive / detail / slist_node.hpp
1 /////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 // (C) Copyright Olaf Krzikalla 2004-2006.\r
4 // (C) Copyright Ion GaztaƱaga  2006-2007\r
5 //\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
9 //\r
10 // See http://www.boost.org/libs/intrusive for documentation.\r
11 //\r
12 /////////////////////////////////////////////////////////////////////////////\r
13 \r
14 #ifndef BOOST_INTRUSIVE_SLIST_NODE_HPP\r
15 #define BOOST_INTRUSIVE_SLIST_NODE_HPP\r
16 \r
17 #include <boost/intrusive/detail/config_begin.hpp>\r
18 #include <iterator>\r
19 #include <boost/assert.hpp>\r
20 #include <boost/intrusive/detail/pointer_type.hpp>\r
21 #include <boost/intrusive/detail/pointer_to_other.hpp>\r
22 #include <boost/intrusive/slist_algorithms.hpp>\r
23 #include <boost/get_pointer.hpp>\r
24 #include <cstddef>\r
25 \r
26 namespace boost {\r
27 namespace intrusive {\r
28 namespace detail {\r
29 \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
35 {\r
36    struct node;\r
37 \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
42 \r
43    struct node\r
44    {\r
45       node_ptr next_;\r
46    };\r
47 \r
48    static node_ptr get_next(const_node_ptr n)\r
49    {  return n->next_;  }  \r
50 \r
51    static void set_next(node_ptr n, node_ptr next)\r
52    {  n->next_ = next;  }  \r
53 };\r
54 \r
55 \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
61 {\r
62    protected:\r
63    typedef typename NodeTraits::node            node;\r
64    typedef typename NodeTraits::node_ptr        node_ptr;\r
65 \r
66    slist_iterator ()\r
67       :  node_ (0)\r
68    {}\r
69 \r
70    explicit slist_iterator (node_ptr node)\r
71       :  node_ (node)\r
72    {}\r
73 \r
74    node_ptr list_node() const\r
75    { return node_; }\r
76 \r
77    Self &operator=(const node_ptr &node)\r
78    {  node_ = node;  return static_cast<Self&>(*this);  }\r
79 \r
80    public:\r
81    Self& operator++() \r
82    { \r
83       node_ = NodeTraits::get_next(node_); \r
84       return static_cast<Self&> (*this); \r
85    }\r
86    \r
87    Self operator++(int)\r
88    {\r
89       Self result (node_);\r
90       node_ = NodeTraits::get_next(node_);\r
91       return result;\r
92    }\r
93 \r
94    bool operator== (const Self& i) const\r
95    { return node_ == i.list_node(); }\r
96 \r
97    bool operator!= (const Self& i) const\r
98    { return !operator== (i); }\r
99 \r
100    private:\r
101    node_ptr node_;\r
102 };\r
103 \r
104 } //namespace detail \r
105 } //namespace intrusive \r
106 } //namespace boost \r
107 \r
108 #include <boost/intrusive/detail/config_end.hpp>\r
109 \r
110 #endif //BOOST_INTRUSIVE_SLIST_NODE_HPP\r