Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // 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_ANY_HOOK_HPP Chris@16: #define BOOST_INTRUSIVE_ANY_HOOK_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@101: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@101: # pragma once Chris@101: #endif Chris@16: Chris@16: namespace boost { Chris@16: namespace intrusive { Chris@16: Chris@16: //! Helper metafunction to define a \c \c any_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_any_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: < any_algorithms Chris@16: , typename packed_options::tag Chris@16: , packed_options::link_mode Chris@16: , AnyBaseHookId Chris@16: > implementation_defined; Chris@16: /// @endcond Chris@16: typedef implementation_defined type; Chris@16: }; Chris@16: Chris@16: //! Derive a class from this hook in order to store objects of that class Chris@16: //! in an intrusive container. 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 any_base_hook, then each \c any_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, \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 any_base_hook Chris@16: : public make_any_base_hook Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: Chris@16: #else Chris@16: 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 or \c safe_link Chris@16: //! initializes the node to an unlinked state. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: any_base_hook(); Chris@16: Chris@16: //! Effects: If link_mode is 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: any_base_hook(const any_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: any_base_hook& operator=(const any_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 a container an assertion is raised. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: ~any_base_hook(); Chris@16: Chris@16: //! Precondition: link_mode must be \c safe_link. 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 container::iterator_to Chris@16: //! will return a valid iterator. Chris@16: //! Chris@16: //! Complexity: Constant Chris@16: bool is_linked() const; Chris@16: #endif Chris@16: }; Chris@16: Chris@16: //! Helper metafunction to define a \c \c any_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_any_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: < any_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: //! Store this hook in a class to be inserted Chris@16: //! in an intrusive container. 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 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 any_member_hook Chris@16: : public make_any_member_hook Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: Chris@16: #else Chris@16: 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 or \c safe_link Chris@16: //! initializes the node to an unlinked state. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: any_member_hook(); Chris@16: Chris@16: //! Effects: If link_mode is 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: any_member_hook(const any_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: any_member_hook& operator=(const any_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 a container an assertion is raised. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: ~any_member_hook(); Chris@16: Chris@16: //! Precondition: link_mode must be \c safe_link. 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 container::iterator_to Chris@16: //! will return a valid iterator. Chris@16: //! Chris@16: //! Complexity: Constant Chris@16: bool is_linked() const; Chris@16: #endif Chris@16: }; Chris@16: Chris@16: /// @cond Chris@16: Chris@16: namespace detail{ Chris@16: Chris@101: BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(old_proto_value_traits_base_hook, hooktags::is_base_hook) Chris@16: Chris@16: //!This option setter specifies that the container Chris@16: //!must use the specified base hook Chris@101: template class NodeTraits> Chris@16: struct any_to_some_hook Chris@16: { Chris@101: typedef typename BasicHook::template pack::proto_value_traits old_proto_value_traits; Chris@16: Chris@16: template Chris@16: struct pack : public Base Chris@16: { Chris@101: struct proto_value_traits Chris@16: { Chris@101: //proto_value_traits::hooktags::is_base_hook is used by get_value_traits Chris@101: //to detect base hooks, so mark it in case BasicHook has it. Chris@101: struct hooktags Chris@101: { Chris@101: static const bool is_base_hook = old_proto_value_traits_base_hook_bool_is_true Chris@101: ::value; Chris@101: }; Chris@101: Chris@101: typedef old_proto_value_traits basic_hook_t; Chris@16: static const bool is_any_hook = true; Chris@101: Chris@101: template Chris@101: struct node_traits_from_voidptr Chris@101: { typedef NodeTraits type; }; Chris@16: }; Chris@16: }; Chris@16: }; Chris@16: Chris@16: } //namespace detail{ Chris@16: Chris@16: /// @endcond Chris@16: Chris@16: //!This option setter specifies that Chris@16: //!any hook should behave as an slist hook Chris@101: template Chris@16: struct any_to_slist_hook Chris@16: /// @cond Chris@101: : public detail::any_to_some_hook Chris@16: /// @endcond Chris@16: {}; Chris@16: Chris@16: //!This option setter specifies that Chris@16: //!any hook should behave as an list hook Chris@101: template Chris@16: struct any_to_list_hook Chris@16: /// @cond Chris@101: : public detail::any_to_some_hook Chris@16: /// @endcond Chris@16: {}; Chris@16: Chris@16: //!This option setter specifies that Chris@16: //!any hook should behave as a set hook Chris@101: template Chris@16: struct any_to_set_hook Chris@16: /// @cond Chris@101: : public detail::any_to_some_hook Chris@16: /// @endcond Chris@16: {}; Chris@16: Chris@16: //!This option setter specifies that Chris@16: //!any hook should behave as an avl_set hook Chris@101: template Chris@16: struct any_to_avl_set_hook Chris@16: /// @cond Chris@101: : public detail::any_to_some_hook Chris@16: /// @endcond Chris@16: {}; Chris@16: Chris@16: //!This option setter specifies that any Chris@16: //!hook should behave as a bs_set hook Chris@101: template Chris@16: struct any_to_bs_set_hook Chris@16: /// @cond Chris@101: : public detail::any_to_some_hook Chris@16: /// @endcond Chris@16: {}; Chris@16: Chris@16: //!This option setter specifies that any hook Chris@16: //!should behave as an unordered set hook Chris@101: template Chris@16: struct any_to_unordered_set_hook Chris@16: /// @cond Chris@101: : public detail::any_to_some_hook Chris@16: /// @endcond Chris@16: {}; Chris@16: Chris@16: Chris@16: } //namespace intrusive Chris@16: } //namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //BOOST_INTRUSIVE_ANY_HOOK_HPP