Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 08:13:48

0001 /////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2007-2013
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // See http://www.boost.org/libs/intrusive for documentation.
0010 //
0011 /////////////////////////////////////////////////////////////////////////////
0012 
0013 #ifndef BOOST_INTRUSIVE_GENERIC_HOOK_HPP
0014 #define BOOST_INTRUSIVE_GENERIC_HOOK_HPP
0015 
0016 #ifndef BOOST_CONFIG_HPP
0017 #  include <boost/config.hpp>
0018 #endif
0019 
0020 #if defined(BOOST_HAS_PRAGMA_ONCE)
0021 #  pragma once
0022 #endif
0023 
0024 #include <boost/intrusive/pointer_traits.hpp>
0025 #include <boost/intrusive/link_mode.hpp>
0026 #include <boost/intrusive/detail/mpl.hpp>
0027 #include <boost/intrusive/detail/assert.hpp>
0028 #include <boost/intrusive/detail/node_holder.hpp>
0029 #include <boost/intrusive/detail/algo_type.hpp>
0030 
0031 namespace boost {
0032 namespace intrusive {
0033 
0034 /// @cond
0035 
0036 namespace detail {
0037 
0038 template <link_mode_type LinkMode>
0039 struct link_dispatch
0040 {};
0041 
0042 template<class Hook>
0043 inline void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>)
0044 {  //If this assertion raises, you might have destroyed an object
0045    //while it was still inserted in a container that is alive.
0046    //If so, remove the object from the container before destroying it.
0047    (void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked());
0048 }
0049 
0050 template<class Hook>
0051 inline void destructor_impl(Hook &hook, detail::link_dispatch<auto_unlink>)
0052 {  hook.unlink();  }
0053 
0054 template<class Hook>
0055 inline void destructor_impl(Hook &, detail::link_dispatch<normal_link>)
0056 {}
0057 
0058 }  //namespace detail {
0059 
0060 enum base_hook_type
0061 {  NoBaseHookId
0062 ,  ListBaseHookId
0063 ,  SlistBaseHookId
0064 ,  RbTreeBaseHookId
0065 ,  HashBaseHookId
0066 ,  AvlTreeBaseHookId
0067 ,  BsTreeBaseHookId
0068 ,  TreapTreeBaseHookId
0069 ,  AnyBaseHookId
0070 };
0071 
0072 
0073 template <class HookTags, unsigned int>
0074 struct hook_tags_definer{};
0075 
0076 template <class HookTags>
0077 struct hook_tags_definer<HookTags, ListBaseHookId>
0078 {  typedef HookTags default_list_hook;  };
0079 
0080 template <class HookTags>
0081 struct hook_tags_definer<HookTags, SlistBaseHookId>
0082 {  typedef HookTags default_slist_hook;  };
0083 
0084 template <class HookTags>
0085 struct hook_tags_definer<HookTags, RbTreeBaseHookId>
0086 {  typedef HookTags default_rbtree_hook;  };
0087 
0088 template <class HookTags>
0089 struct hook_tags_definer<HookTags, HashBaseHookId>
0090 {  typedef HookTags default_hashtable_hook;  };
0091 
0092 template <class HookTags>
0093 struct hook_tags_definer<HookTags, AvlTreeBaseHookId>
0094 {  typedef HookTags default_avltree_hook;  };
0095 
0096 template <class HookTags>
0097 struct hook_tags_definer<HookTags, BsTreeBaseHookId>
0098 {  typedef HookTags default_bstree_hook;  };
0099 
0100 template <class HookTags>
0101 struct hook_tags_definer<HookTags, AnyBaseHookId>
0102 {  typedef HookTags default_any_hook;  };
0103 
0104 template
0105    < class NodeTraits
0106    , class Tag
0107    , link_mode_type LinkMode
0108    , base_hook_type BaseHookType
0109    >
0110 struct hooktags_impl
0111 {
0112    static const link_mode_type link_mode = LinkMode;
0113    typedef Tag tag;
0114    typedef NodeTraits node_traits;
0115    static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value;
0116    static const bool safemode_or_autounlink = is_safe_autounlink<link_mode>::value;
0117    static const unsigned int type = BaseHookType;
0118 };
0119 
0120 /// @endcond
0121 
0122 template
0123    < boost::intrusive::algo_types Algo
0124    , class NodeTraits
0125    , class Tag
0126    , link_mode_type LinkMode
0127    , base_hook_type BaseHookType
0128    >
0129 class generic_hook
0130    /// @cond
0131    //If the hook is a base hook, derive generic hook from node_holder
0132    //so that a unique base class is created to convert from the node
0133    //to the type. This mechanism will be used by bhtraits.
0134    //
0135    //If the hook is a member hook, generic hook will directly derive
0136    //from the hook.
0137    : public detail::if_c
0138       < detail::is_same<Tag, member_tag>::value
0139       , typename NodeTraits::node
0140       , node_holder<typename NodeTraits::node, Tag, BaseHookType>
0141       >::type
0142    //If this is the a default-tagged base hook derive from a class that
0143    //will define an special internal typedef. Containers will be able to detect this
0144    //special typedef and obtain generic_hook's internal types in order to deduce
0145    //value_traits for this hook.
0146    , public hook_tags_definer
0147       < generic_hook<Algo, NodeTraits, Tag, LinkMode, BaseHookType>
0148       , detail::is_same<Tag, dft_tag>::value ? BaseHookType : NoBaseHookId>
0149    /// @endcond
0150 {
0151    /// @cond
0152    typedef typename get_algo<Algo, NodeTraits>::type  node_algorithms;
0153    typedef typename node_algorithms::node             node;
0154    typedef typename node_algorithms::node_ptr         node_ptr;
0155    typedef typename node_algorithms::const_node_ptr   const_node_ptr;
0156 
0157    public:
0158 
0159    typedef hooktags_impl
0160       < NodeTraits
0161       , Tag, LinkMode, BaseHookType>                  hooktags;
0162 
0163    inline node_ptr this_ptr() BOOST_NOEXCEPT
0164    {  return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*this)); }
0165 
0166    inline const_node_ptr this_ptr() const BOOST_NOEXCEPT
0167    {  return pointer_traits<const_node_ptr>::pointer_to(static_cast<const node&>(*this)); }
0168 
0169    public:
0170    /// @endcond
0171 
0172    inline generic_hook() BOOST_NOEXCEPT
0173    {
0174       if(hooktags::safemode_or_autounlink){
0175          node_algorithms::init(this->this_ptr());
0176       }
0177    }
0178 
0179    inline generic_hook(const generic_hook& ) BOOST_NOEXCEPT
0180    {
0181       if(hooktags::safemode_or_autounlink){
0182          node_algorithms::init(this->this_ptr());
0183       }
0184    }
0185 
0186    inline generic_hook& operator=(const generic_hook& ) BOOST_NOEXCEPT
0187    {  return *this;  }
0188 
0189    inline ~generic_hook()
0190    {
0191       destructor_impl
0192          (*this, detail::link_dispatch<hooktags::link_mode>());
0193    }
0194 
0195    inline void swap_nodes(generic_hook &other) BOOST_NOEXCEPT
0196    {
0197       node_algorithms::swap_nodes
0198          (this->this_ptr(), other.this_ptr());
0199    }
0200 
0201    inline bool is_linked() const BOOST_NOEXCEPT
0202    {
0203       //is_linked() can be only used in safe-mode or auto-unlink
0204       BOOST_INTRUSIVE_STATIC_ASSERT(( hooktags::safemode_or_autounlink ));
0205       return !node_algorithms::unique(this->this_ptr());
0206    }
0207 
0208    inline void unlink() BOOST_NOEXCEPT
0209    {
0210       BOOST_INTRUSIVE_STATIC_ASSERT(( (int)hooktags::link_mode == (int)auto_unlink ));
0211       node_ptr n(this->this_ptr());
0212       if(!node_algorithms::inited(n)){
0213          node_algorithms::unlink(n);
0214          node_algorithms::init(n);
0215       }
0216    }
0217 };
0218 
0219 } //namespace intrusive
0220 } //namespace boost
0221 
0222 #endif //BOOST_INTRUSIVE_GENERIC_HOOK_HPP