annotate DEPENDENCIES/generic/include/boost/intrusive/detail/generic_hook.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 /////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@16 3 // (C) Copyright Ion Gaztanaga 2007-2013
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0.
Chris@16 6 // (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 //
Chris@16 9 // See http://www.boost.org/libs/intrusive for documentation.
Chris@16 10 //
Chris@16 11 /////////////////////////////////////////////////////////////////////////////
Chris@16 12
Chris@16 13 #ifndef BOOST_INTRUSIVE_GENERIC_HOOK_HPP
Chris@16 14 #define BOOST_INTRUSIVE_GENERIC_HOOK_HPP
Chris@16 15
Chris@16 16 #include <boost/intrusive/detail/config_begin.hpp>
Chris@16 17 #include <boost/intrusive/intrusive_fwd.hpp>
Chris@16 18 #include <boost/intrusive/pointer_traits.hpp>
Chris@16 19 #include <boost/intrusive/link_mode.hpp>
Chris@16 20 #include <boost/intrusive/detail/utilities.hpp>
Chris@16 21 #include <boost/intrusive/detail/mpl.hpp>
Chris@16 22 #include <boost/intrusive/pointer_traits.hpp>
Chris@16 23 #include <boost/static_assert.hpp>
Chris@16 24
Chris@16 25 namespace boost {
Chris@16 26 namespace intrusive {
Chris@16 27
Chris@16 28 /// @cond
Chris@16 29
Chris@16 30 enum base_hook_type
Chris@16 31 { NoBaseHookId
Chris@16 32 , ListBaseHookId
Chris@16 33 , SlistBaseHookId
Chris@16 34 , RbTreeBaseHookId
Chris@16 35 , HashBaseHookId
Chris@16 36 , SplayTreeBaseHookId
Chris@16 37 , AvlTreeBaseHookId
Chris@16 38 , BsTreeBaseHookId
Chris@16 39 , AnyBaseHookId
Chris@16 40 };
Chris@16 41
Chris@16 42
Chris@16 43 template <class HookTags, unsigned int>
Chris@16 44 struct hook_tags_definer{};
Chris@16 45
Chris@16 46 template <class HookTags>
Chris@16 47 struct hook_tags_definer<HookTags, ListBaseHookId>
Chris@16 48 { typedef HookTags default_list_hook; };
Chris@16 49
Chris@16 50 template <class HookTags>
Chris@16 51 struct hook_tags_definer<HookTags, SlistBaseHookId>
Chris@16 52 { typedef HookTags default_slist_hook; };
Chris@16 53
Chris@16 54 template <class HookTags>
Chris@16 55 struct hook_tags_definer<HookTags, RbTreeBaseHookId>
Chris@16 56 { typedef HookTags default_rbtree_hook; };
Chris@16 57
Chris@16 58 template <class HookTags>
Chris@16 59 struct hook_tags_definer<HookTags, HashBaseHookId>
Chris@16 60 { typedef HookTags default_hashtable_hook; };
Chris@16 61
Chris@16 62 template <class HookTags>
Chris@16 63 struct hook_tags_definer<HookTags, SplayTreeBaseHookId>
Chris@16 64 { typedef HookTags default_splaytree_hook; };
Chris@16 65
Chris@16 66 template <class HookTags>
Chris@16 67 struct hook_tags_definer<HookTags, AvlTreeBaseHookId>
Chris@16 68 { typedef HookTags default_avltree_hook; };
Chris@16 69
Chris@16 70 template <class HookTags>
Chris@16 71 struct hook_tags_definer<HookTags, BsTreeBaseHookId>
Chris@16 72 { typedef HookTags default_bstree_hook; };
Chris@16 73
Chris@16 74 template <class HookTags>
Chris@16 75 struct hook_tags_definer<HookTags, AnyBaseHookId>
Chris@16 76 { typedef HookTags default_any_hook; };
Chris@16 77
Chris@16 78 template
Chris@16 79 < class NodeTraits
Chris@16 80 , class Tag
Chris@16 81 , link_mode_type LinkMode
Chris@16 82 , base_hook_type BaseHookType
Chris@16 83 >
Chris@16 84 struct hooktags_impl
Chris@16 85 {
Chris@16 86 static const link_mode_type link_mode = LinkMode;
Chris@16 87 typedef Tag tag;
Chris@16 88 typedef NodeTraits node_traits;
Chris@16 89 static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value;
Chris@16 90 static const bool safemode_or_autounlink = is_safe_autounlink<link_mode>::value;
Chris@16 91 static const unsigned int type = BaseHookType;
Chris@16 92 };
Chris@16 93
Chris@16 94 /// @endcond
Chris@16 95
Chris@16 96 template
Chris@16 97 < class GetNodeAlgorithms
Chris@16 98 , class Tag
Chris@16 99 , link_mode_type LinkMode
Chris@16 100 , base_hook_type BaseHookType
Chris@16 101 >
Chris@16 102 class generic_hook
Chris@16 103 /// @cond
Chris@16 104 //If the hook is a base hook, derive generic hook from node_holder
Chris@16 105 //so that a unique base class is created to convert from the node
Chris@16 106 //to the type. This mechanism will be used by bhtraits.
Chris@16 107 //
Chris@16 108 //If the hook is a member hook, generic hook will directly derive
Chris@16 109 //from the hook.
Chris@16 110 : public detail::if_c
Chris@16 111 < detail::is_same<Tag, member_tag>::value
Chris@16 112 , typename GetNodeAlgorithms::type::node
Chris@16 113 , node_holder<typename GetNodeAlgorithms::type::node, Tag, BaseHookType>
Chris@16 114 >::type
Chris@16 115 //If this is the a default-tagged base hook derive from a class that
Chris@16 116 //will define an special internal typedef. Containers will be able to detect this
Chris@16 117 //special typedef and obtain generic_hook's internal types in order to deduce
Chris@16 118 //value_traits for this hook.
Chris@16 119 , public hook_tags_definer
Chris@16 120 < generic_hook<GetNodeAlgorithms, Tag, LinkMode, BaseHookType>
Chris@16 121 , detail::is_same<Tag, default_tag>::value*BaseHookType>
Chris@16 122 /// @endcond
Chris@16 123 {
Chris@16 124 /// @cond
Chris@16 125 typedef typename GetNodeAlgorithms::type node_algorithms;
Chris@16 126 typedef typename node_algorithms::node node;
Chris@16 127 typedef typename node_algorithms::node_ptr node_ptr;
Chris@16 128 typedef typename node_algorithms::const_node_ptr const_node_ptr;
Chris@16 129
Chris@16 130 public:
Chris@16 131
Chris@16 132 typedef hooktags_impl
Chris@16 133 < typename GetNodeAlgorithms::type::node_traits
Chris@16 134 , Tag, LinkMode, BaseHookType> hooktags;
Chris@16 135
Chris@16 136 node_ptr this_ptr()
Chris@16 137 { return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*this)); }
Chris@16 138
Chris@16 139 const_node_ptr this_ptr() const
Chris@16 140 { return pointer_traits<const_node_ptr>::pointer_to(static_cast<const node&>(*this)); }
Chris@16 141
Chris@16 142 public:
Chris@16 143 /// @endcond
Chris@16 144
Chris@16 145 generic_hook()
Chris@16 146 {
Chris@16 147 if(hooktags::safemode_or_autounlink){
Chris@16 148 node_algorithms::init(this->this_ptr());
Chris@16 149 }
Chris@16 150 }
Chris@16 151
Chris@16 152 generic_hook(const generic_hook& )
Chris@16 153 {
Chris@16 154 if(hooktags::safemode_or_autounlink){
Chris@16 155 node_algorithms::init(this->this_ptr());
Chris@16 156 }
Chris@16 157 }
Chris@16 158
Chris@16 159 generic_hook& operator=(const generic_hook& )
Chris@16 160 { return *this; }
Chris@16 161
Chris@16 162 ~generic_hook()
Chris@16 163 {
Chris@16 164 destructor_impl
Chris@16 165 (*this, detail::link_dispatch<hooktags::link_mode>());
Chris@16 166 }
Chris@16 167
Chris@16 168 void swap_nodes(generic_hook &other)
Chris@16 169 {
Chris@16 170 node_algorithms::swap_nodes
Chris@16 171 (this->this_ptr(), other.this_ptr());
Chris@16 172 }
Chris@16 173
Chris@16 174 bool is_linked() const
Chris@16 175 {
Chris@16 176 //is_linked() can be only used in safe-mode or auto-unlink
Chris@16 177 BOOST_STATIC_ASSERT(( hooktags::safemode_or_autounlink ));
Chris@16 178 return !node_algorithms::unique(this->this_ptr());
Chris@16 179 }
Chris@16 180
Chris@16 181 void unlink()
Chris@16 182 {
Chris@16 183 BOOST_STATIC_ASSERT(( (int)hooktags::link_mode == (int)auto_unlink ));
Chris@16 184 node_algorithms::unlink(this->this_ptr());
Chris@16 185 node_algorithms::init(this->this_ptr());
Chris@16 186 }
Chris@16 187 };
Chris@16 188
Chris@16 189 } //namespace intrusive
Chris@16 190 } //namespace boost
Chris@16 191
Chris@16 192 #include <boost/intrusive/detail/config_end.hpp>
Chris@16 193
Chris@16 194 #endif //BOOST_INTRUSIVE_GENERIC_HOOK_HPP