|
||||
File indexing completed on 2025-01-18 09:38:43
0001 ///////////////////////////////////////////////////////////////////////////// 0002 // 0003 // (C) Copyright Olaf Krzikalla 2004-2006. 0004 // (C) Copyright Ion Gaztanaga 2006-2013 0005 // 0006 // Distributed under the Boost Software License, Version 1.0. 0007 // (See accompanying file LICENSE_1_0.txt or copy at 0008 // http://www.boost.org/LICENSE_1_0.txt) 0009 // 0010 // See http://www.boost.org/libs/intrusive for documentation. 0011 // 0012 ///////////////////////////////////////////////////////////////////////////// 0013 0014 #ifndef BOOST_INTRUSIVE_SET_HOOK_HPP 0015 #define BOOST_INTRUSIVE_SET_HOOK_HPP 0016 0017 #include <boost/intrusive/detail/config_begin.hpp> 0018 #include <boost/intrusive/intrusive_fwd.hpp> 0019 0020 #include <boost/intrusive/detail/rbtree_node.hpp> 0021 #include <boost/intrusive/rbtree_algorithms.hpp> 0022 #include <boost/intrusive/options.hpp> 0023 #include <boost/intrusive/detail/generic_hook.hpp> 0024 0025 #if defined(BOOST_HAS_PRAGMA_ONCE) 0026 # pragma once 0027 #endif 0028 0029 namespace boost { 0030 namespace intrusive { 0031 0032 //! Helper metafunction to define a \c set_base_hook that yields to the same 0033 //! type when the same options (either explicitly or implicitly) are used. 0034 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0035 template<class ...Options> 0036 #else 0037 template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> 0038 #endif 0039 struct make_set_base_hook 0040 { 0041 /// @cond 0042 typedef typename pack_options 0043 < hook_defaults, 0044 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0045 O1, O2, O3, O4 0046 #else 0047 Options... 0048 #endif 0049 >::type packed_options; 0050 0051 typedef generic_hook 0052 < RbTreeAlgorithms 0053 , rbtree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> 0054 , typename packed_options::tag 0055 , packed_options::link_mode 0056 , RbTreeBaseHookId 0057 > implementation_defined; 0058 /// @endcond 0059 typedef implementation_defined type; 0060 }; 0061 0062 //! Derive a class from set_base_hook in order to store objects in 0063 //! in a set/multiset. set_base_hook holds the data necessary to maintain 0064 //! the set/multiset and provides an appropriate value_traits class for set/multiset. 0065 //! 0066 //! The hook admits the following options: \c tag<>, \c void_pointer<>, 0067 //! \c link_mode<> and \c optimize_size<>. 0068 //! 0069 //! \c tag<> defines a tag to identify the node. 0070 //! The same tag value can be used in different classes, but if a class is 0071 //! derived from more than one \c list_base_hook, then each \c list_base_hook needs its 0072 //! unique tag. 0073 //! 0074 //! \c void_pointer<> is the pointer type that will be used internally in the hook 0075 //! and the container configured to use this hook. 0076 //! 0077 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, 0078 //! \c auto_unlink or \c safe_link). 0079 //! 0080 //! \c optimize_size<> will tell the hook to optimize the hook for size instead 0081 //! of speed. 0082 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0083 template<class ...Options> 0084 #else 0085 template<class O1, class O2, class O3, class O4> 0086 #endif 0087 class set_base_hook 0088 : public make_set_base_hook< 0089 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0090 O1, O2, O3, O4 0091 #else 0092 Options... 0093 #endif 0094 >::type 0095 { 0096 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) 0097 public: 0098 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link 0099 //! initializes the node to an unlinked state. 0100 //! 0101 //! <b>Throws</b>: Nothing. 0102 set_base_hook() BOOST_NOEXCEPT; 0103 0104 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link 0105 //! initializes the node to an unlinked state. The argument is ignored. 0106 //! 0107 //! <b>Throws</b>: Nothing. 0108 //! 0109 //! <b>Rationale</b>: Providing a copy-constructor 0110 //! makes classes using the hook STL-compliant without forcing the 0111 //! user to do some additional work. \c swap can be used to emulate 0112 //! move-semantics. 0113 set_base_hook(const set_base_hook& ) BOOST_NOEXCEPT; 0114 0115 //! <b>Effects</b>: Empty function. The argument is ignored. 0116 //! 0117 //! <b>Throws</b>: Nothing. 0118 //! 0119 //! <b>Rationale</b>: Providing an assignment operator 0120 //! makes classes using the hook STL-compliant without forcing the 0121 //! user to do some additional work. \c swap can be used to emulate 0122 //! move-semantics. 0123 set_base_hook& operator=(const set_base_hook& ) BOOST_NOEXCEPT; 0124 0125 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does 0126 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the 0127 //! object is stored in a set an assertion is raised. If link_mode is 0128 //! \c auto_unlink and \c is_linked() is true, the node is unlinked. 0129 //! 0130 //! <b>Throws</b>: Nothing. 0131 ~set_base_hook(); 0132 0133 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements 0134 //! related to those nodes in one or two containers. That is, if the node 0135 //! this is part of the element e1, the node x is part of the element e2 0136 //! and both elements are included in the containers s1 and s2, then after 0137 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1 0138 //! at the position of e1. If one element is not in a container, then 0139 //! after the swap-operation the other element is not in a container. 0140 //! Iterators to e1 and e2 related to those nodes are invalidated. 0141 //! 0142 //! <b>Complexity</b>: Constant 0143 //! 0144 //! <b>Throws</b>: Nothing. 0145 void swap_nodes(set_base_hook &other) BOOST_NOEXCEPT; 0146 0147 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink. 0148 //! 0149 //! <b>Returns</b>: true, if the node belongs to a container, false 0150 //! otherwise. This function can be used to test whether \c set::iterator_to 0151 //! will return a valid iterator. 0152 //! 0153 //! <b>Complexity</b>: Constant 0154 bool is_linked() const BOOST_NOEXCEPT; 0155 0156 //! <b>Effects</b>: Removes the node if it's inserted in a container. 0157 //! This function is only allowed if link_mode is \c auto_unlink. 0158 //! 0159 //! <b>Throws</b>: Nothing. 0160 void unlink() BOOST_NOEXCEPT; 0161 #endif 0162 }; 0163 0164 //! Helper metafunction to define a \c set_member_hook that yields to the same 0165 //! type when the same options (either explicitly or implicitly) are used. 0166 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0167 template<class ...Options> 0168 #else 0169 template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> 0170 #endif 0171 struct make_set_member_hook 0172 { 0173 /// @cond 0174 typedef typename pack_options 0175 < hook_defaults, 0176 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0177 O1, O2, O3, O4 0178 #else 0179 Options... 0180 #endif 0181 >::type packed_options; 0182 0183 typedef generic_hook 0184 < RbTreeAlgorithms 0185 , rbtree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> 0186 , member_tag 0187 , packed_options::link_mode 0188 , NoBaseHookId 0189 > implementation_defined; 0190 /// @endcond 0191 typedef implementation_defined type; 0192 }; 0193 0194 //! Put a public data member set_member_hook in order to store objects of this class in 0195 //! a set/multiset. set_member_hook holds the data necessary for maintaining the 0196 //! set/multiset and provides an appropriate value_traits class for set/multiset. 0197 //! 0198 //! The hook admits the following options: \c void_pointer<>, 0199 //! \c link_mode<> and \c optimize_size<>. 0200 //! 0201 //! \c void_pointer<> is the pointer type that will be used internally in the hook 0202 //! and the container configured to use this hook. 0203 //! 0204 //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, 0205 //! \c auto_unlink or \c safe_link). 0206 //! 0207 //! \c optimize_size<> will tell the hook to optimize the hook for size instead 0208 //! of speed. 0209 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0210 template<class ...Options> 0211 #else 0212 template<class O1, class O2, class O3, class O4> 0213 #endif 0214 class set_member_hook 0215 : public make_set_member_hook< 0216 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) 0217 O1, O2, O3, O4 0218 #else 0219 Options... 0220 #endif 0221 >::type 0222 { 0223 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) 0224 public: 0225 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link 0226 //! initializes the node to an unlinked state. 0227 //! 0228 //! <b>Throws</b>: Nothing. 0229 set_member_hook() BOOST_NOEXCEPT; 0230 0231 //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link 0232 //! initializes the node to an unlinked state. The argument is ignored. 0233 //! 0234 //! <b>Throws</b>: Nothing. 0235 //! 0236 //! <b>Rationale</b>: Providing a copy-constructor 0237 //! makes classes using the hook STL-compliant without forcing the 0238 //! user to do some additional work. \c swap can be used to emulate 0239 //! move-semantics. 0240 set_member_hook(const set_member_hook& ) BOOST_NOEXCEPT; 0241 0242 //! <b>Effects</b>: Empty function. The argument is ignored. 0243 //! 0244 //! <b>Throws</b>: Nothing. 0245 //! 0246 //! <b>Rationale</b>: Providing an assignment operator 0247 //! makes classes using the hook STL-compliant without forcing the 0248 //! user to do some additional work. \c swap can be used to emulate 0249 //! move-semantics. 0250 set_member_hook& operator=(const set_member_hook& ) BOOST_NOEXCEPT; 0251 0252 //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does 0253 //! nothing (ie. no code is generated). If link_mode is \c safe_link and the 0254 //! object is stored in a set an assertion is raised. If link_mode is 0255 //! \c auto_unlink and \c is_linked() is true, the node is unlinked. 0256 //! 0257 //! <b>Throws</b>: Nothing. 0258 ~set_member_hook(); 0259 0260 //! <b>Effects</b>: Swapping two nodes swaps the position of the elements 0261 //! related to those nodes in one or two containers. That is, if the node 0262 //! this is part of the element e1, the node x is part of the element e2 0263 //! and both elements are included in the containers s1 and s2, then after 0264 //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1 0265 //! at the position of e1. If one element is not in a container, then 0266 //! after the swap-operation the other element is not in a container. 0267 //! Iterators to e1 and e2 related to those nodes are invalidated. 0268 //! 0269 //! <b>Complexity</b>: Constant 0270 //! 0271 //! <b>Throws</b>: Nothing. 0272 void swap_nodes(set_member_hook &other) BOOST_NOEXCEPT; 0273 0274 //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink. 0275 //! 0276 //! <b>Returns</b>: true, if the node belongs to a container, false 0277 //! otherwise. This function can be used to test whether \c set::iterator_to 0278 //! will return a valid iterator. 0279 //! 0280 //! <b>Complexity</b>: Constant 0281 bool is_linked() const BOOST_NOEXCEPT; 0282 0283 //! <b>Effects</b>: Removes the node if it's inserted in a container. 0284 //! This function is only allowed if link_mode is \c auto_unlink. 0285 //! 0286 //! <b>Throws</b>: Nothing. 0287 void unlink() BOOST_NOEXCEPT; 0288 #endif 0289 }; 0290 0291 } //namespace intrusive 0292 } //namespace boost 0293 0294 #include <boost/intrusive/detail/config_end.hpp> 0295 0296 #endif //BOOST_INTRUSIVE_SET_HOOK_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |