X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2Fboost_intrusive%2Fdetail%2Fslist_node.hpp;fp=senf%2Fboost_intrusive%2Fdetail%2Fslist_node.hpp;h=f7921ba62f790328bc66813976c72b6977ba1ae4;hb=8f1ff66f5b7d10cfc6d35fb72267bc2fb3b588f7;hp=0000000000000000000000000000000000000000;hpb=fbd3d0ff298683f08b59f25288d8c243e03b206c;p=senf.git diff --git a/senf/boost_intrusive/detail/slist_node.hpp b/senf/boost_intrusive/detail/slist_node.hpp new file mode 100644 index 0000000..f7921ba --- /dev/null +++ b/senf/boost_intrusive/detail/slist_node.hpp @@ -0,0 +1,110 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Olaf Krzikalla 2004-2006. +// (C) Copyright Ion GaztaƱaga 2006-2007 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_SLIST_NODE_HPP +#define BOOST_INTRUSIVE_SLIST_NODE_HPP + +#include "config_begin.hpp" +#include +#include +#include "pointer_type.hpp" +#include "pointer_to_other.hpp" +#include "../slist_algorithms.hpp" +#include +#include + +namespace boost { +namespace intrusive { +namespace detail { + +// slist_node_traits can be used with slist_algorithms and supplies +// a list_node holding the pointers needed for a double-linked list +// it is used by islist_derived_node and islist_member_node +template +struct slist_node_traits +{ + struct node; + + typedef typename boost::pointer_to_other + ::type node_ptr; + typedef typename boost::pointer_to_other + ::type const_node_ptr; + + struct node + { + node_ptr next_; + }; + + static node_ptr get_next(const_node_ptr n) + { return n->next_; } + + static void set_next(node_ptr n, node_ptr next) + { n->next_ = next; } +}; + + +// slist_iterator provides some basic functions for a +// node oriented forward iterator: +template +class slist_iterator + : public std::iterator +{ + protected: + typedef typename NodeTraits::node node; + typedef typename NodeTraits::node_ptr node_ptr; + + slist_iterator () + : node_ (0) + {} + + explicit slist_iterator (node_ptr node) + : node_ (node) + {} + + node_ptr list_node() const + { return node_; } + + Self &operator=(const node_ptr &node) + { node_ = node; return static_cast(*this); } + + public: + Self& operator++() + { + node_ = NodeTraits::get_next(node_); + return static_cast (*this); + } + + Self operator++(int) + { + Self result (node_); + node_ = NodeTraits::get_next(node_); + return result; + } + + bool operator== (const Self& i) const + { return node_ == i.list_node(); } + + bool operator!= (const Self& i) const + { return !operator== (i); } + + private: + node_ptr node_; +}; + +} //namespace detail +} //namespace intrusive +} //namespace boost + +#include "config_end.hpp" + +#endif //BOOST_INTRUSIVE_SLIST_NODE_HPP