Move boost/intrusive to senf/boost_intrusive
[senf.git] / senf / boost_intrusive / detail / list_node.hpp
diff --git a/senf/boost_intrusive/detail/list_node.hpp b/senf/boost_intrusive/detail/list_node.hpp
new file mode 100644 (file)
index 0000000..6ab4d7f
--- /dev/null
@@ -0,0 +1,128 @@
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// (C) Copyright Olaf Krzikalla 2004-2006.\r
+// (C) Copyright Ion GaztaƱaga  2006-2007\r
+//\r
+// Distributed under the Boost Software License, Version 1.0.\r
+//    (See accompanying file LICENSE_1_0.txt or copy at\r
+//          http://www.boost.org/LICENSE_1_0.txt)\r
+//\r
+// See http://www.boost.org/libs/intrusive for documentation.\r
+//\r
+/////////////////////////////////////////////////////////////////////////////\r
+\r
+#ifndef BOOST_INTRUSIVE_LIST_NODE_HPP\r
+#define BOOST_INTRUSIVE_LIST_NODE_HPP\r
+\r
+#include "config_begin.hpp"\r
+#include <iterator>\r
+#include <boost/assert.hpp>\r
+#include "pointer_type.hpp"\r
+#include "pointer_to_other.hpp"\r
+#include "../list_algorithms.hpp"\r
+#include <boost/get_pointer.hpp>\r
+#include <cstddef>\r
+\r
+namespace boost {\r
+namespace intrusive {\r
+namespace detail {\r
+\r
+// list_node_traits can be used with list_algorithms and supplies\r
+// a list_node holding the pointers needed for a double-linked list\r
+// it is used by ilist_derived_node and ilist_member_node\r
+template<class VoidPointer>\r
+struct list_node_traits\r
+{\r
+   struct node;\r
+   typedef typename boost::pointer_to_other\r
+      <VoidPointer, node>::type          node_ptr;\r
+   typedef typename boost::pointer_to_other\r
+      <VoidPointer, const node>::type    const_node_ptr;\r
+\r
+   struct node\r
+   {\r
+      node_ptr prev_, next_;\r
+   };\r
+\r
+   static node_ptr get_previous(const_node_ptr n)\r
+   {  return n->prev_;  }\r
+\r
+   static void set_previous(node_ptr n, node_ptr prev)\r
+   {  n->prev_ = prev;  }\r
+\r
+   static node_ptr get_next(const_node_ptr n)\r
+   {  return n->next_;  }\r
+\r
+   static void set_next(node_ptr n, node_ptr next)\r
+   {  n->next_ = next;  }\r
+};\r
+\r
+\r
+// list_iterator provides some basic functions for a \r
+// node oriented bidirectional iterator:\r
+template<class T, class Self, class NodeTraits>\r
+class list_iterator\r
+   :  public std::iterator<std::bidirectional_iterator_tag, T>\r
+{\r
+   protected:\r
+   typedef typename NodeTraits::node            node;\r
+   typedef typename NodeTraits::node_ptr        node_ptr;\r
\r
+   list_iterator()\r
+      : node_ (0)\r
+   {}\r
+\r
+   explicit list_iterator(node_ptr node)\r
+      : node_ (node)\r
+   {}\r
+\r
+   node_ptr list_node() const\r
+   { return node_; }\r
+\r
+   Self &operator=(const node_ptr &node)\r
+   {  node_ = node;  return static_cast<Self&>(*this);  }\r
+\r
+   public:\r
+   Self& operator++() \r
+   { \r
+      node_ = NodeTraits::get_next(node_); \r
+      return static_cast<Self&> (*this); \r
+   }\r
+   \r
+   Self operator++(int)\r
+   {\r
+      Self result (node_);\r
+      node_ = NodeTraits::get_next(node_);\r
+      return result;\r
+   }\r
+\r
+   Self& operator--() \r
+   { \r
+      node_ = NodeTraits::get_previous(node_); \r
+      return static_cast<Self&> (*this); \r
+   }\r
+   \r
+   Self operator--(int)\r
+   {\r
+      Self result (node_);\r
+      node_ = NodeTraits::get_previous(node_);\r
+      return result;\r
+   }\r
+\r
+   bool operator== (const Self& i) const\r
+   { return node_ == i.list_node(); }\r
+\r
+   bool operator!= (const Self& i) const\r
+   { return !operator== (i); }\r
+\r
+   private:\r
+   node_ptr node_;\r
+};\r
+\r
+} //namespace detail \r
+} //namespace intrusive \r
+} //namespace boost \r
+\r
+#include "config_end.hpp"\r
+\r
+#endif //BOOST_INTRUSIVE_LIST_NODE_HPP\r