///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2007-2012 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTRUSIVE_OPTIONS_HPP #define BOOST_INTRUSIVE_OPTIONS_HPP #include #include #include #include #include #include namespace boost { namespace intrusive { /// @cond struct default_tag; struct member_tag; namespace detail{ struct default_hook_tag{}; #define BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER) \ struct BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER : public default_hook_tag\ {\ template \ struct apply\ { typedef typename T::BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER type; };\ }\ BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_list_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_slist_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_set_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_uset_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_avl_set_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_splay_set_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_bs_set_hook); #undef BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION template struct eval_value_traits { typedef typename ValueTraits::value_traits type; }; template struct eval_bucket_traits { typedef typename BucketTraits::bucket_traits type; }; template struct concrete_hook_base_value_traits { typedef typename BaseHook::boost_intrusive_tags tags; typedef detail::base_hook_traits < T , typename tags::node_traits , tags::link_mode , typename tags::tag , tags::hook_type> type; }; template struct concrete_hook_base_node_traits { typedef typename BaseHook::boost_intrusive_tags::node_traits type; }; template struct any_hook_base_value_traits { typedef typename BaseHook::boost_intrusive_tags tags; typedef detail::base_hook_traits < T , typename BaseHook::node_traits , tags::link_mode , typename tags::tag , tags::hook_type> type; }; template struct any_hook_base_node_traits { typedef typename BaseHook::node_traits type; }; template struct get_base_value_traits { typedef typename detail::eval_if_c < internal_any_hook_bool_is_true::value , any_hook_base_value_traits , concrete_hook_base_value_traits >::type type; }; template struct get_base_node_traits { typedef typename detail::eval_if_c < internal_any_hook_bool_is_true::value , any_hook_base_node_traits , concrete_hook_base_node_traits >::type type; }; template struct get_member_value_traits { typedef typename MemberHook::member_value_traits type; }; template struct get_member_node_traits { typedef typename MemberHook::member_value_traits::node_traits type; }; template struct get_value_traits { typedef typename detail::eval_if_c ::value ,detail::apply ,detail::identity >::type supposed_value_traits; //...if it's a default hook typedef typename detail::eval_if_c < internal_base_hook_bool_is_true::value //...get it's internal value traits using //the provided T value type. , get_base_value_traits //...else use it's internal value traits tag //(member hooks and custom value traits are in this group) , detail::eval_if_c < internal_member_value_traits::value , get_member_value_traits , detail::identity > >::type type; }; template struct get_explicit_node_traits { typedef typename ValueTraits::node_traits type; }; template struct get_node_traits { typedef SupposedValueTraits supposed_value_traits; //...if it's a base hook typedef typename detail::eval_if_c < internal_base_hook_bool_is_true::value //...get it's internal value traits using //the provided T value type. , get_base_node_traits //...else use it's internal value traits tag //(member hooks and custom value traits are in this group) , detail::eval_if_c < internal_member_value_traits::value , get_member_node_traits , get_explicit_node_traits > >::type type; }; } //namespace detail{ //!This type indicates that no option is being used //!and that the default options should be used struct none { template struct pack : Base { }; }; /// @endcond //!This option setter specifies if the intrusive //!container stores its size as a member to //!obtain constant-time size() member. template struct constant_time_size { /// @cond template struct pack : Base { static const bool constant_time_size = Enabled; }; /// @endcond }; //!This option setter specifies the type that //!the container will use to store its size. template struct size_type { /// @cond template struct pack : Base { typedef SizeType size_type; }; /// @endcond }; //!This option setter specifies the strict weak ordering //!comparison functor for the value type template struct compare { /// @cond template struct pack : Base { typedef Compare compare; }; /// @endcond }; //!This option setter for scapegoat containers specifies if //!the intrusive scapegoat container should use a non-variable //!alpha value that does not need floating-point operations. //! //!If activated, the fixed alpha value is 1/sqrt(2). This //!option also saves some space in the container since //!the alpha value and some additional data does not need //!to be stored in the container. //! //!If the user only needs an alpha value near 1/sqrt(2), this //!option also improves performance since avoids logarithm //!and division operations when rebalancing the tree. template struct floating_point { /// @cond template struct pack : Base { static const bool floating_point = Enabled; }; /// @endcond }; //!This option setter specifies the equality //!functor for the value type template struct equal { /// @cond template struct pack : Base { typedef Equal equal; }; /// @endcond }; //!This option setter specifies the equality //!functor for the value type template struct priority { /// @cond template struct pack : Base { typedef Priority priority; }; /// @endcond }; //!This option setter specifies the hash //!functor for the value type template struct hash { /// @cond template struct pack : Base { typedef Hash hash; }; /// @endcond }; //!This option setter specifies the relationship between the type //!to be managed by the container (the value type) and the node to be //!used in the node algorithms. It also specifies the linking policy. template struct value_traits { /// @cond template struct pack : Base { typedef ValueTraits value_traits; }; /// @endcond }; //!This option setter specifies the member hook the //!container must use. template< typename Parent , typename MemberHook , MemberHook Parent::* PtrToMember> struct member_hook { /// @cond typedef detail::member_hook_traits < Parent , MemberHook , PtrToMember > member_value_traits; template struct pack : Base { typedef member_value_traits value_traits; }; /// @endcond }; //!This option setter specifies the function object that will //!be used to convert between values to be inserted in a container //!and the hook to be used for that purpose. template< typename Functor> struct function_hook { /// @cond typedef detail::function_hook_traits function_value_traits; template struct pack : Base { typedef function_value_traits value_traits; }; /// @endcond }; //!This option setter specifies that the container //!must use the specified base hook template struct base_hook { /// @cond template struct pack : Base { typedef BaseHook value_traits; }; /// @endcond }; //!This option setter specifies the type of //!a void pointer. This will instruct the hook //!to use this type of pointer instead of the //!default one template struct void_pointer { /// @cond template struct pack : Base { typedef VoidPointer void_pointer; }; /// @endcond }; //!This option setter specifies the type of //!the tag of a base hook. A type cannot have two //!base hooks of the same type, so a tag can be used //!to differentiate two base hooks with otherwise same type template struct tag { /// @cond template struct pack : Base { typedef Tag tag; }; /// @endcond }; //!This option setter specifies the link mode //!(normal_link, safe_link or auto_unlink) template struct link_mode { /// @cond template struct pack : Base { static const link_mode_type link_mode = LinkType; }; /// @endcond }; //!This option setter specifies if the hook //!should be optimized for size instead of for speed. template struct optimize_size { /// @cond template struct pack : Base { static const bool optimize_size = Enabled; }; /// @endcond }; //!This option setter specifies if the list container should //!use a linear implementation instead of a circular one. template struct linear { /// @cond template struct pack : Base { static const bool linear = Enabled; }; /// @endcond }; //!This option setter specifies if the list container should //!use a linear implementation instead of a circular one. template struct cache_last { /// @cond template struct pack : Base { static const bool cache_last = Enabled; }; /// @endcond }; //!This option setter specifies the bucket traits //!class for unordered associative containers. When this option is specified, //!instead of using the default bucket traits, a user defined holder will be defined template struct bucket_traits { /// @cond template struct pack : Base { typedef BucketTraits bucket_traits; }; /// @endcond }; //!This option setter specifies if the unordered hook //!should offer room to store the hash value. //!Storing the hash in the hook will speed up rehashing //!processes in applications where rehashing is frequent, //!rehashing might throw or the value is heavy to hash. template struct store_hash { /// @cond template struct pack : Base { static const bool store_hash = Enabled; }; /// @endcond }; //!This option setter specifies if the unordered hook //!should offer room to store another link to another node //!with the same key. //!Storing this link will speed up lookups and insertions on //!unordered_multiset containers with a great number of elements //!with the same key. template struct optimize_multikey { /// @cond template struct pack : Base { static const bool optimize_multikey = Enabled; }; /// @endcond }; //!This option setter specifies if the bucket array will be always power of two. //!This allows using masks instead of the default modulo operation to determine //!the bucket number from the hash value, leading to better performance. //!In debug mode, if power of two buckets mode is activated, the bucket length //!will be checked to through assertions to assure the bucket length is power of two. template struct power_2_buckets { /// @cond template struct pack : Base { static const bool power_2_buckets = Enabled; }; /// @endcond }; //!This option setter specifies if the container will cache a pointer to the first //!non-empty bucket so that begin() is always constant-time. //!This is specially helpful when we can have containers with a few elements //!but with big bucket arrays (that is, hashtables with low load factors). template struct cache_begin { /// @cond template struct pack : Base { static const bool cache_begin = Enabled; }; /// @endcond }; //!This option setter specifies if the container will compare the hash value //!before comparing objects. This option can't be specified if store_hash<> //!is not true. //!This is specially helpful when we have containers with a high load factor. //!and the comparison function is much more expensive that comparing already //!stored hash values. template struct compare_hash { /// @cond template struct pack : Base { static const bool compare_hash = Enabled; }; /// @endcond }; //!This option setter specifies if the hash container will use incremental //!hashing. With incremental hashing the cost of hash table expansion is spread //!out across each hash table insertion operation, as opposed to be incurred all at once. //!Therefore linear hashing is well suited for interactive applications or real-time //!appplications where the worst-case insertion time of non-incremental hash containers //!(rehashing the whole bucket array) is not admisible. template struct incremental { /// @cond template struct pack : Base { static const bool incremental = Enabled; }; /// @endcond }; /// @cond //To-do: pass to variadic templates #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template struct do_pack { //Use "pack" member template to pack options typedef typename Next::template pack type; }; template struct do_pack { //Avoid packing "none" to shorten template names typedef Prev type; }; template < class DefaultOptions , class O1 = none , class O2 = none , class O3 = none , class O4 = none , class O5 = none , class O6 = none , class O7 = none , class O8 = none , class O9 = none , class O10 = none , class O11 = none > struct pack_options { // join options typedef typename do_pack < typename do_pack < typename do_pack < typename do_pack < typename do_pack < typename do_pack < typename do_pack < typename do_pack < typename do_pack < typename do_pack < typename do_pack < DefaultOptions , O1 >::type , O2 >::type , O3 >::type , O4 >::type , O5 >::type , O6 >::type , O7 >::type , O8 >::type , O9 >::type , O10 >::type , O11 >::type type; }; #else //index_tuple template struct index_tuple{}; //build_number_seq template > struct build_number_seq; template struct build_number_seq > : build_number_seq > {}; template struct build_number_seq<0, index_tuple > { typedef index_tuple type; }; template struct typelist {}; //invert_typelist template struct invert_typelist; template struct typelist_element; template struct typelist_element > { typedef typename typelist_element >::type type; }; template struct typelist_element<0, typelist > { typedef Head type; }; template typelist >::type...> inverted_typelist(index_tuple, typelist) { return typelist >::type...>(); } //sizeof_typelist template struct sizeof_typelist; template struct sizeof_typelist< typelist > { static const std::size_t value = sizeof...(Types); }; //invert_typelist_impl template struct invert_typelist_impl; template struct invert_typelist_impl< Typelist, index_tuple > { static const std::size_t last_idx = sizeof_typelist::value - 1; typedef typelist ::type...> type; }; template struct invert_typelist_impl< Typelist, index_tuple > { typedef Typelist type; }; template struct invert_typelist_impl< Typelist, index_tuple<> > { typedef Typelist type; }; //invert_typelist template struct invert_typelist; template struct invert_typelist< typelist > { typedef typelist typelist_t; typedef typename build_number_seq::type indexes_t; typedef typename invert_typelist_impl::type type; }; //Do pack template struct do_pack; template<> struct do_pack >; template struct do_pack > { typedef Prev type; }; template struct do_pack > { typedef typename Prev::template pack type; }; template struct do_pack > { typedef typename Prev::template pack >::type> type; }; template struct pack_options { typedef typelist typelist_t; typedef typename invert_typelist::type inverted_typelist; typedef typename do_pack::type type; }; #endif struct hook_defaults : public pack_options < none , void_pointer , link_mode , tag , optimize_size , store_hash , linear , optimize_multikey >::type {}; /// @endcond } //namespace intrusive { } //namespace boost { #include #endif //#ifndef BOOST_INTRUSIVE_OPTIONS_HPP