Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Olaf Krzikalla 2004-2006. Chris@16: // (C) Copyright Ion Gaztanaga 2006-2013 Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/intrusive for documentation. Chris@16: // Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #ifndef BOOST_INTRUSIVE_SLIST_HOOK_HPP Chris@16: #define BOOST_INTRUSIVE_SLIST_HOOK_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@101: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@101: # pragma once Chris@101: #endif Chris@101: Chris@16: namespace boost { Chris@16: namespace intrusive { Chris@16: Chris@16: //! Helper metafunction to define a \c slist_base_hook that yields to the same Chris@16: //! type when the same options (either explicitly or implicitly) are used. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: struct make_slist_base_hook Chris@16: { Chris@16: /// @cond Chris@16: typedef typename pack_options Chris@16: < hook_defaults, Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: O1, O2, O3 Chris@16: #else Chris@16: Options... Chris@16: #endif Chris@16: >::type packed_options; Chris@16: Chris@16: typedef generic_hook Chris@101: < circular_slist_algorithms > Chris@16: , typename packed_options::tag Chris@16: , packed_options::link_mode Chris@16: , SlistBaseHookId Chris@16: > implementation_defined; Chris@16: /// @endcond Chris@16: typedef implementation_defined type; Chris@16: }; Chris@16: Chris@16: //! Derive a class from slist_base_hook in order to store objects in Chris@16: //! in an list. slist_base_hook holds the data necessary to maintain the Chris@16: //! list and provides an appropriate value_traits class for list. Chris@16: //! Chris@16: //! The hook admits the following options: \c tag<>, \c void_pointer<> and Chris@16: //! \c link_mode<>. Chris@16: //! Chris@16: //! \c tag<> defines a tag to identify the node. Chris@16: //! The same tag value can be used in different classes, but if a class is Chris@16: //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its Chris@16: //! unique tag. Chris@16: //! Chris@16: //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, Chris@16: //! \c auto_unlink or \c safe_link). Chris@16: //! Chris@16: //! \c void_pointer<> is the pointer type that will be used internally in the hook Chris@101: //! and the container configured to use this hook. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class slist_base_hook Chris@16: : public make_slist_base_hook< Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: O1, O2, O3 Chris@16: #else Chris@16: Options... Chris@16: #endif Chris@16: >::type Chris@16: { Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: public: Chris@16: //! Effects: If link_mode is \c auto_unlink or \c safe_link Chris@16: //! initializes the node to an unlinked state. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: slist_base_hook(); Chris@16: Chris@16: //! Effects: If link_mode is \c auto_unlink or \c safe_link Chris@16: //! initializes the node to an unlinked state. The argument is ignored. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Rationale: Providing a copy-constructor Chris@16: //! makes classes using the hook STL-compliant without forcing the Chris@16: //! user to do some additional work. \c swap can be used to emulate Chris@16: //! move-semantics. Chris@16: slist_base_hook(const slist_base_hook& ); Chris@16: Chris@16: //! Effects: Empty function. The argument is ignored. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Rationale: Providing an assignment operator Chris@16: //! makes classes using the hook STL-compliant without forcing the Chris@16: //! user to do some additional work. \c swap can be used to emulate Chris@16: //! move-semantics. Chris@16: slist_base_hook& operator=(const slist_base_hook& ); Chris@16: Chris@16: //! Effects: If link_mode is \c normal_link, the destructor does Chris@16: //! nothing (ie. no code is generated). If link_mode is \c safe_link and the Chris@16: //! object is stored in an slist an assertion is raised. If link_mode is Chris@16: //! \c auto_unlink and \c is_linked() is true, the node is unlinked. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: ~slist_base_hook(); Chris@16: Chris@16: //! Effects: Swapping two nodes swaps the position of the elements Chris@16: //! related to those nodes in one or two containers. That is, if the node Chris@16: //! this is part of the element e1, the node x is part of the element e2 Chris@16: //! and both elements are included in the containers s1 and s2, then after Chris@16: //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1 Chris@16: //! at the position of e1. If one element is not in a container, then Chris@16: //! after the swap-operation the other element is not in a container. Chris@16: //! Iterators to e1 and e2 related to those nodes are invalidated. Chris@16: //! Chris@16: //! Complexity: Constant Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: void swap_nodes(slist_base_hook &other); Chris@16: Chris@16: //! Precondition: link_mode must be \c safe_link or \c auto_unlink. Chris@16: //! Chris@16: //! Returns: true, if the node belongs to a container, false Chris@16: //! otherwise. This function can be used to test whether \c slist::iterator_to Chris@16: //! will return a valid iterator. Chris@16: //! Chris@16: //! Complexity: Constant Chris@16: bool is_linked() const; Chris@16: Chris@16: //! Effects: Removes the node if it's inserted in a container. Chris@16: //! This function is only allowed if link_mode is \c auto_unlink. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: void unlink(); Chris@16: #endif Chris@16: }; Chris@16: Chris@16: //! Helper metafunction to define a \c slist_member_hook that yields to the same Chris@16: //! type when the same options (either explicitly or implicitly) are used. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: struct make_slist_member_hook Chris@16: { Chris@16: /// @cond Chris@16: typedef typename pack_options Chris@16: < hook_defaults, Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: O1, O2, O3 Chris@16: #else Chris@16: Options... Chris@16: #endif Chris@16: >::type packed_options; Chris@16: Chris@16: typedef generic_hook Chris@101: < circular_slist_algorithms > Chris@16: , member_tag Chris@16: , packed_options::link_mode Chris@16: , NoBaseHookId Chris@16: > implementation_defined; Chris@16: /// @endcond Chris@16: typedef implementation_defined type; Chris@16: }; Chris@16: Chris@16: //! Put a public data member slist_member_hook in order to store objects of this class in Chris@16: //! an list. slist_member_hook holds the data necessary for maintaining the list and Chris@16: //! provides an appropriate value_traits class for list. Chris@16: //! Chris@16: //! The hook admits the following options: \c void_pointer<> and Chris@16: //! \c link_mode<>. Chris@16: //! Chris@16: //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, Chris@16: //! \c auto_unlink or \c safe_link). Chris@16: //! Chris@16: //! \c void_pointer<> is the pointer type that will be used internally in the hook Chris@101: //! and the container configured to use this hook. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class slist_member_hook Chris@16: : public make_slist_member_hook< Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: O1, O2, O3 Chris@16: #else Chris@16: Options... Chris@16: #endif Chris@16: >::type Chris@16: { Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: public: Chris@16: //! Effects: If link_mode is \c auto_unlink or \c safe_link Chris@16: //! initializes the node to an unlinked state. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: slist_member_hook(); Chris@16: Chris@16: //! Effects: If link_mode is \c auto_unlink or \c safe_link Chris@16: //! initializes the node to an unlinked state. The argument is ignored. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Rationale: Providing a copy-constructor Chris@16: //! makes classes using the hook STL-compliant without forcing the Chris@16: //! user to do some additional work. \c swap can be used to emulate Chris@16: //! move-semantics. Chris@16: slist_member_hook(const slist_member_hook& ); Chris@16: Chris@16: //! Effects: Empty function. The argument is ignored. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Rationale: Providing an assignment operator Chris@16: //! makes classes using the hook STL-compliant without forcing the Chris@16: //! user to do some additional work. \c swap can be used to emulate Chris@16: //! move-semantics. Chris@16: slist_member_hook& operator=(const slist_member_hook& ); Chris@16: Chris@16: //! Effects: If link_mode is \c normal_link, the destructor does Chris@16: //! nothing (ie. no code is generated). If link_mode is \c safe_link and the Chris@16: //! object is stored in an slist an assertion is raised. If link_mode is Chris@16: //! \c auto_unlink and \c is_linked() is true, the node is unlinked. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: ~slist_member_hook(); Chris@16: Chris@16: //! Effects: Swapping two nodes swaps the position of the elements Chris@16: //! related to those nodes in one or two containers. That is, if the node Chris@16: //! this is part of the element e1, the node x is part of the element e2 Chris@16: //! and both elements are included in the containers s1 and s2, then after Chris@16: //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1 Chris@16: //! at the position of e1. If one element is not in a container, then Chris@16: //! after the swap-operation the other element is not in a container. Chris@16: //! Iterators to e1 and e2 related to those nodes are invalidated. Chris@16: //! Chris@16: //! Complexity: Constant Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: void swap_nodes(slist_member_hook &other); Chris@16: Chris@16: //! Precondition: link_mode must be \c safe_link or \c auto_unlink. Chris@16: //! Chris@16: //! Returns: true, if the node belongs to a container, false Chris@16: //! otherwise. This function can be used to test whether \c slist::iterator_to Chris@16: //! will return a valid iterator. Chris@16: //! Chris@16: //! Complexity: Constant Chris@16: bool is_linked() const; Chris@16: Chris@16: //! Effects: Removes the node if it's inserted in a container. Chris@16: //! This function is only allowed if link_mode is \c auto_unlink. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: void unlink(); Chris@16: #endif Chris@16: }; Chris@16: Chris@16: } //namespace intrusive Chris@16: } //namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //BOOST_INTRUSIVE_SLIST_HOOK_HPP