///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2006-2014 // // 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_DETAIL_HOOK_TRAITS_HPP #define BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP #ifndef BOOST_CONFIG_HPP # include #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include #include #include #include #include #include namespace boost { namespace intrusive { template struct bhtraits_base { public: typedef NodePtr node_ptr; typedef typename pointer_traits::element_type node; typedef node_holder node_holder_type; typedef T value_type; typedef typename pointer_traits:: template rebind_pointer::type const_node_ptr; typedef typename pointer_traits:: template rebind_pointer::type pointer; typedef typename pointer_traits:: template rebind_pointer::type const_pointer; //typedef typename pointer_traits::reference reference; //typedef typename pointer_traits::reference const_reference; typedef T & reference; typedef const T & const_reference; typedef node_holder_type & node_holder_reference; typedef const node_holder_type & const_node_holder_reference; typedef node& node_reference; typedef const node & const_node_reference; static pointer to_value_ptr(const node_ptr & n) { return pointer_traits::pointer_to (static_cast(static_cast(*n))); } static const_pointer to_value_ptr(const const_node_ptr & n) { return pointer_traits::pointer_to (static_cast(static_cast(*n))); } static node_ptr to_node_ptr(reference value) { return pointer_traits::pointer_to (static_cast(static_cast(value))); } static const_node_ptr to_node_ptr(const_reference value) { return pointer_traits::pointer_to (static_cast(static_cast(value))); } }; template struct bhtraits : public bhtraits_base { static const link_mode_type link_mode = LinkMode; typedef NodeTraits node_traits; }; template struct mhtraits { public: typedef Hook hook_type; typedef typename hook_type::hooktags::node_traits node_traits; typedef typename node_traits::node node; typedef T value_type; typedef typename node_traits::node_ptr node_ptr; typedef typename node_traits::const_node_ptr const_node_ptr; typedef typename pointer_traits:: template rebind_pointer::type pointer; typedef typename pointer_traits:: template rebind_pointer::type const_pointer; typedef T & reference; typedef const T & const_reference; typedef node& node_reference; typedef const node & const_node_reference; typedef hook_type& hook_reference; typedef const hook_type & const_hook_reference; static const link_mode_type link_mode = Hook::hooktags::link_mode; static node_ptr to_node_ptr(reference value) { return pointer_traits::pointer_to (static_cast(static_cast(value.*P))); } static const_node_ptr to_node_ptr(const_reference value) { return pointer_traits::pointer_to (static_cast(static_cast(value.*P))); } static pointer to_value_ptr(const node_ptr & n) { return pointer_traits::pointer_to (*detail::parent_from_member (static_cast(boost::intrusive::detail::to_raw_pointer(n)), P)); } static const_pointer to_value_ptr(const const_node_ptr & n) { return pointer_traits::pointer_to (*detail::parent_from_member (static_cast(boost::intrusive::detail::to_raw_pointer(n)), P)); } }; template struct fhtraits { public: typedef typename Functor::hook_type hook_type; typedef typename Functor::hook_ptr hook_ptr; typedef typename Functor::const_hook_ptr const_hook_ptr; typedef typename hook_type::hooktags::node_traits node_traits; typedef typename node_traits::node node; typedef typename Functor::value_type value_type; typedef typename node_traits::node_ptr node_ptr; typedef typename node_traits::const_node_ptr const_node_ptr; typedef typename pointer_traits:: template rebind_pointer::type pointer; typedef typename pointer_traits:: template rebind_pointer::type const_pointer; typedef value_type & reference; typedef const value_type & const_reference; static const link_mode_type link_mode = hook_type::hooktags::link_mode; static node_ptr to_node_ptr(reference value) { return static_cast(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); } static const_node_ptr to_node_ptr(const_reference value) { return static_cast(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); } static pointer to_value_ptr(const node_ptr & n) { return Functor::to_value_ptr(to_hook_ptr(n)); } static const_pointer to_value_ptr(const const_node_ptr & n) { return Functor::to_value_ptr(to_hook_ptr(n)); } private: static hook_ptr to_hook_ptr(const node_ptr & n) { return hook_ptr(&*static_cast(&*n)); } static const_hook_ptr to_hook_ptr(const const_node_ptr & n) { return const_hook_ptr(&*static_cast(&*n)); } }; } //namespace intrusive } //namespace boost #endif //BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP