splay_set_hook.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Olaf Krzikalla 2004-2006.
  4. // (C) Copyright Ion Gaztanaga 2006-2013
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/intrusive for documentation.
  11. //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP
  14. #define BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP
  15. #include <boost/intrusive/detail/config_begin.hpp>
  16. #include <boost/intrusive/bs_set_hook.hpp>
  17. namespace boost {
  18. namespace intrusive {
  19. //! Helper metafunction to define a \c splay_set_base_hook that yields to the same
  20. //! type when the same options (either explicitly or implicitly) are used.
  21. //! <b>WARNING: </b> Deprecated class, use `make_bs_set_base_hook` instead.
  22. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  23. template<class ...Options>
  24. #else
  25. template<class O1 = void, class O2 = void, class O3 = void>
  26. #endif
  27. struct make_splay_set_base_hook
  28. #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  29. #if defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  30. : public make_bs_set_base_hook<Options...>
  31. #else
  32. : public make_bs_set_base_hook<O1, O2, O3>
  33. #endif
  34. #endif
  35. {
  36. /// @cond
  37. typedef typename make_bs_set_base_hook
  38. <
  39. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  40. O1, O2, O3
  41. #else
  42. Options...
  43. #endif
  44. >::type implementation_defined;
  45. /// @endcond
  46. typedef implementation_defined type;
  47. };
  48. //! Derive a class from splay_set_base_hook in order to store objects in
  49. //! in a splay_set/splay_multiset. splay_set_base_hook holds the data necessary to maintain
  50. //! the splay_set/splay_multiset and provides an appropriate value_traits class for splay_set/splay_multiset.
  51. //!
  52. //! The hook admits the following options: \c tag<>, \c void_pointer<>,
  53. //! \c link_mode<> and \c optimize_size<>.
  54. //!
  55. //! \c tag<> defines a tag to identify the node.
  56. //! The same tag value can be used in different classes, but if a class is
  57. //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
  58. //! unique tag.
  59. //!
  60. //! \c void_pointer<> is the pointer type that will be used internally in the hook
  61. //! and the the container configured to use this hook.
  62. //!
  63. //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
  64. //! \c auto_unlink or \c safe_link).
  65. //!
  66. //! <b>WARNING: </b> Deprecated class, use `bs_set_base_hook` instead.
  67. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  68. template<class ...Options>
  69. #else
  70. template<class O1, class O2, class O3>
  71. #endif
  72. class splay_set_base_hook
  73. : public make_splay_set_base_hook<
  74. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  75. O1, O2, O3
  76. #else
  77. Options...
  78. #endif
  79. >::type
  80. {
  81. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  82. public:
  83. //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
  84. //! initializes the node to an unlinked state.
  85. //!
  86. //! <b>Throws</b>: Nothing.
  87. splay_set_base_hook();
  88. //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
  89. //! initializes the node to an unlinked state. The argument is ignored.
  90. //!
  91. //! <b>Throws</b>: Nothing.
  92. //!
  93. //! <b>Rationale</b>: Providing a copy-constructor
  94. //! makes classes using the hook STL-compliant without forcing the
  95. //! user to do some additional work. \c swap can be used to emulate
  96. //! move-semantics.
  97. splay_set_base_hook(const splay_set_base_hook& );
  98. //! <b>Effects</b>: Empty function. The argument is ignored.
  99. //!
  100. //! <b>Throws</b>: Nothing.
  101. //!
  102. //! <b>Rationale</b>: Providing an assignment operator
  103. //! makes classes using the hook STL-compliant without forcing the
  104. //! user to do some additional work. \c swap can be used to emulate
  105. //! move-semantics.
  106. splay_set_base_hook& operator=(const splay_set_base_hook& );
  107. //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
  108. //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
  109. //! object is stored in a set an assertion is raised. If link_mode is
  110. //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
  111. //!
  112. //! <b>Throws</b>: Nothing.
  113. ~splay_set_base_hook();
  114. //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
  115. //! related to those nodes in one or two containers. That is, if the node
  116. //! this is part of the element e1, the node x is part of the element e2
  117. //! and both elements are included in the containers s1 and s2, then after
  118. //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
  119. //! at the position of e1. If one element is not in a container, then
  120. //! after the swap-operation the other element is not in a container.
  121. //! Iterators to e1 and e2 related to those nodes are invalidated.
  122. //!
  123. //! <b>Complexity</b>: Constant
  124. //!
  125. //! <b>Throws</b>: Nothing.
  126. void swap_nodes(splay_set_base_hook &other);
  127. //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
  128. //!
  129. //! <b>Returns</b>: true, if the node belongs to a container, false
  130. //! otherwise. This function can be used to test whether \c set::iterator_to
  131. //! will return a valid iterator.
  132. //!
  133. //! <b>Complexity</b>: Constant
  134. bool is_linked() const;
  135. //! <b>Effects</b>: Removes the node if it's inserted in a container.
  136. //! This function is only allowed if link_mode is \c auto_unlink.
  137. //!
  138. //! <b>Throws</b>: Nothing.
  139. void unlink();
  140. #endif
  141. };
  142. //! Helper metafunction to define a \c splay_set_member_hook that yields to the same
  143. //! type when the same options (either explicitly or implicitly) are used.
  144. //!
  145. //! <b>WARNING: </b> Deprecated class, use `make_bs_set_member_hook` instead.
  146. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  147. template<class ...Options>
  148. #else
  149. template<class O1 = void, class O2 = void, class O3 = void>
  150. #endif
  151. struct make_splay_set_member_hook
  152. #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  153. #if defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  154. : public make_bs_set_member_hook<Options...>
  155. #else
  156. : public make_bs_set_member_hook<O1, O2, O3>
  157. #endif
  158. #endif
  159. {
  160. /// @cond
  161. typedef typename make_bs_set_member_hook
  162. <
  163. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  164. O1, O2, O3
  165. #else
  166. Options...
  167. #endif
  168. >::type implementation_defined;
  169. /// @endcond
  170. typedef implementation_defined type;
  171. };
  172. //! Put a public data member splay_set_member_hook in order to store objects of this
  173. //! class in a splay_set/splay_multiset. splay_set_member_hook holds the data
  174. //! necessary for maintaining the splay_set/splay_multiset and provides an appropriate
  175. //! value_traits class for splay_set/splay_multiset.
  176. //!
  177. //! The hook admits the following options: \c void_pointer<>,
  178. //! \c link_mode<> and \c optimize_size<>.
  179. //!
  180. //! \c void_pointer<> is the pointer type that will be used internally in the hook
  181. //! and the the container configured to use this hook.
  182. //!
  183. //! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
  184. //! \c auto_unlink or \c safe_link).
  185. //!
  186. //! <b>WARNING: </b> Deprecated class, use `bs_set_member_hook` instead.
  187. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  188. template<class ...Options>
  189. #else
  190. template<class O1, class O2, class O3>
  191. #endif
  192. class splay_set_member_hook
  193. : public make_splay_set_member_hook<
  194. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  195. O1, O2, O3
  196. #else
  197. Options...
  198. #endif
  199. >::type
  200. {
  201. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  202. public:
  203. //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
  204. //! initializes the node to an unlinked state.
  205. //!
  206. //! <b>Throws</b>: Nothing.
  207. splay_set_member_hook();
  208. //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
  209. //! initializes the node to an unlinked state. The argument is ignored.
  210. //!
  211. //! <b>Throws</b>: Nothing.
  212. //!
  213. //! <b>Rationale</b>: Providing a copy-constructor
  214. //! makes classes using the hook STL-compliant without forcing the
  215. //! user to do some additional work. \c swap can be used to emulate
  216. //! move-semantics.
  217. splay_set_member_hook(const splay_set_member_hook& );
  218. //! <b>Effects</b>: Empty function. The argument is ignored.
  219. //!
  220. //! <b>Throws</b>: Nothing.
  221. //!
  222. //! <b>Rationale</b>: Providing an assignment operator
  223. //! makes classes using the hook STL-compliant without forcing the
  224. //! user to do some additional work. \c swap can be used to emulate
  225. //! move-semantics.
  226. splay_set_member_hook& operator=(const splay_set_member_hook& );
  227. //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
  228. //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
  229. //! object is stored in a set an assertion is raised. If link_mode is
  230. //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
  231. //!
  232. //! <b>Throws</b>: Nothing.
  233. ~splay_set_member_hook();
  234. //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
  235. //! related to those nodes in one or two containers. That is, if the node
  236. //! this is part of the element e1, the node x is part of the element e2
  237. //! and both elements are included in the containers s1 and s2, then after
  238. //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
  239. //! at the position of e1. If one element is not in a container, then
  240. //! after the swap-operation the other element is not in a container.
  241. //! Iterators to e1 and e2 related to those nodes are invalidated.
  242. //!
  243. //! <b>Complexity</b>: Constant
  244. //!
  245. //! <b>Throws</b>: Nothing.
  246. void swap_nodes(splay_set_member_hook &other);
  247. //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
  248. //!
  249. //! <b>Returns</b>: true, if the node belongs to a container, false
  250. //! otherwise. This function can be used to test whether \c set::iterator_to
  251. //! will return a valid iterator.
  252. //!
  253. //! <b>Complexity</b>: Constant
  254. bool is_linked() const;
  255. //! <b>Effects</b>: Removes the node if it's inserted in a container.
  256. //! This function is only allowed if link_mode is \c auto_unlink.
  257. //!
  258. //! <b>Throws</b>: Nothing.
  259. void unlink();
  260. #endif
  261. };
  262. } //namespace intrusive
  263. } //namespace boost
  264. #include <boost/intrusive/detail/config_end.hpp>
  265. #endif //BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP