Move boost/intrusive to senf/boost_intrusive
[senf.git] / senf / boost_intrusive / detail / slist_node.hpp
diff --git a/senf/boost_intrusive/detail/slist_node.hpp b/senf/boost_intrusive/detail/slist_node.hpp
new file mode 100644 (file)
index 0000000..f7921ba
--- /dev/null
@@ -0,0 +1,110 @@
+/////////////////////////////////////////////////////////////////////////////\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_SLIST_NODE_HPP\r
+#define BOOST_INTRUSIVE_SLIST_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 "../slist_algorithms.hpp"\r
+#include <boost/get_pointer.hpp>\r
+#include <cstddef>\r
+\r
+namespace boost {\r
+namespace intrusive {\r
+namespace detail {\r
+\r
+// slist_node_traits can be used with slist_algorithms and supplies\r
+// a list_node holding the pointers needed for a double-linked list\r
+// it is used by islist_derived_node and islist_member_node\r
+template<class VoidPointer>\r
+struct slist_node_traits\r
+{\r
+   struct node;\r
+\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 next_;\r
+   };\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
+// slist_iterator provides some basic functions for a \r
+// node oriented forward iterator:\r
+template<class T, class Self, class NodeTraits>\r
+class slist_iterator\r
+   :  public std::iterator<std::forward_iterator_tag, T>\r
+{\r
+   protected:\r
+   typedef typename NodeTraits::node            node;\r
+   typedef typename NodeTraits::node_ptr        node_ptr;\r
+\r
+   slist_iterator ()\r
+      :  node_ (0)\r
+   {}\r
+\r
+   explicit slist_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
+   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_SLIST_NODE_HPP\r