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_LIST_NODE_HPP
\r
15 #define BOOST_INTRUSIVE_LIST_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 "../list_algorithms.hpp"
\r
23 #include <boost/get_pointer.hpp>
\r
27 namespace intrusive {
\r
30 // list_node_traits can be used with list_algorithms and supplies
\r
31 // a list_node holding the pointers needed for a double-linked list
\r
32 // it is used by ilist_derived_node and ilist_member_node
\r
33 template<class VoidPointer>
\r
34 struct list_node_traits
\r
37 typedef typename boost::pointer_to_other
\r
38 <VoidPointer, node>::type node_ptr;
\r
39 typedef typename boost::pointer_to_other
\r
40 <VoidPointer, const node>::type const_node_ptr;
\r
44 node_ptr prev_, next_;
\r
47 static node_ptr get_previous(const_node_ptr n)
\r
48 { return n->prev_; }
\r
50 static void set_previous(node_ptr n, node_ptr prev)
\r
51 { n->prev_ = prev; }
\r
53 static node_ptr get_next(const_node_ptr n)
\r
54 { return n->next_; }
\r
56 static void set_next(node_ptr n, node_ptr next)
\r
57 { n->next_ = next; }
\r
61 // list_iterator provides some basic functions for a
\r
62 // node oriented bidirectional iterator:
\r
63 template<class T, class Self, class NodeTraits>
\r
65 : public std::iterator<std::bidirectional_iterator_tag, T>
\r
68 typedef typename NodeTraits::node node;
\r
69 typedef typename NodeTraits::node_ptr node_ptr;
\r
75 explicit list_iterator(node_ptr node)
\r
79 node_ptr list_node() const
\r
82 Self &operator=(const node_ptr &node)
\r
83 { node_ = node; return static_cast<Self&>(*this); }
\r
88 node_ = NodeTraits::get_next(node_);
\r
89 return static_cast<Self&> (*this);
\r
92 Self operator++(int)
\r
94 Self result (node_);
\r
95 node_ = NodeTraits::get_next(node_);
\r
101 node_ = NodeTraits::get_previous(node_);
\r
102 return static_cast<Self&> (*this);
\r
105 Self operator--(int)
\r
107 Self result (node_);
\r
108 node_ = NodeTraits::get_previous(node_);
\r
112 bool operator== (const Self& i) const
\r
113 { return node_ == i.list_node(); }
\r
115 bool operator!= (const Self& i) const
\r
116 { return !operator== (i); }
\r
122 } //namespace detail
\r
123 } //namespace intrusive
\r
124 } //namespace boost
\r
126 #include "config_end.hpp"
\r
128 #endif //BOOST_INTRUSIVE_LIST_NODE_HPP
\r