Chris@102: ///////////////////////////////////////////////////////////////////////////// Chris@102: // Chris@102: // (C) Copyright Ion Gaztanaga 2014-2014 Chris@102: // Chris@102: // Distributed under the Boost Software License, Version 1.0. Chris@102: // (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: // Chris@102: // See http://www.boost.org/libs/intrusive for documentation. Chris@102: // Chris@102: ///////////////////////////////////////////////////////////////////////////// Chris@102: Chris@102: #ifndef BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP Chris@102: #define BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP Chris@102: Chris@102: #ifndef BOOST_CONFIG_HPP Chris@102: # include Chris@102: #endif Chris@102: Chris@102: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@102: # pragma once Chris@102: #endif Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: namespace boost { Chris@102: namespace intrusive { Chris@102: namespace detail { Chris@102: Chris@102: template Chris@102: struct node_cloner Chris@102: //Use public inheritance to avoid MSVC bugs with closures Chris@102: : public ebo_functor_holder Chris@102: { Chris@102: typedef ValueTraits value_traits; Chris@102: typedef typename value_traits::node_traits node_traits; Chris@102: typedef typename node_traits::node_ptr node_ptr; Chris@102: typedef ebo_functor_holder base_t; Chris@102: typedef typename get_algo< AlgoType Chris@102: , node_traits>::type node_algorithms; Chris@102: static const bool safemode_or_autounlink = Chris@102: is_safe_autounlink::value; Chris@102: typedef typename value_traits::value_type value_type; Chris@102: typedef typename value_traits::pointer pointer; Chris@102: typedef typename node_traits::node node; Chris@102: typedef typename value_traits::const_node_ptr const_node_ptr; Chris@102: typedef typename value_traits::reference reference; Chris@102: typedef typename value_traits::const_reference const_reference; Chris@102: Chris@102: typedef typename if_c::type reference_type; Chris@102: Chris@102: node_cloner(F f, const ValueTraits *traits) Chris@102: : base_t(f), traits_(traits) Chris@102: {} Chris@102: Chris@102: // tree-based containers use this method, which is proxy-reference friendly Chris@102: node_ptr operator()(const node_ptr & p) Chris@102: { Chris@102: reference_type v = *traits_->to_value_ptr(p); Chris@102: node_ptr n = traits_->to_node_ptr(*base_t::get()(v)); Chris@102: //Cloned node must be in default mode if the linking mode requires it Chris@102: if(safemode_or_autounlink) Chris@102: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); Chris@102: return n; Chris@102: } Chris@102: Chris@102: // hashtables use this method, which is proxy-reference unfriendly Chris@102: node_ptr operator()(const node &to_clone) Chris@102: { Chris@102: reference_type v = Chris@102: *traits_->to_value_ptr Chris@102: (pointer_traits::pointer_to(to_clone)); Chris@102: node_ptr n = traits_->to_node_ptr(*base_t::get()(v)); Chris@102: //Cloned node must be in default mode if the linking mode requires it Chris@102: if(safemode_or_autounlink) Chris@102: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); Chris@102: return n; Chris@102: } Chris@102: Chris@102: const ValueTraits * const traits_; Chris@102: }; Chris@102: Chris@102: template Chris@102: struct node_disposer Chris@102: //Use public inheritance to avoid MSVC bugs with closures Chris@102: : public ebo_functor_holder Chris@102: { Chris@102: typedef ValueTraits value_traits; Chris@102: typedef typename value_traits::node_traits node_traits; Chris@102: typedef typename node_traits::node_ptr node_ptr; Chris@102: typedef ebo_functor_holder base_t; Chris@102: typedef typename get_algo< AlgoType Chris@102: , node_traits>::type node_algorithms; Chris@102: static const bool safemode_or_autounlink = Chris@102: is_safe_autounlink::value; Chris@102: Chris@102: node_disposer(F f, const ValueTraits *cont) Chris@102: : base_t(f), traits_(cont) Chris@102: {} Chris@102: Chris@102: void operator()(const node_ptr & p) Chris@102: { Chris@102: if(safemode_or_autounlink) Chris@102: node_algorithms::init(p); Chris@102: base_t::get()(traits_->to_value_ptr(p)); Chris@102: } Chris@102: const ValueTraits * const traits_; Chris@102: }; Chris@102: Chris@102: } //namespace detail{ Chris@102: } //namespace intrusive{ Chris@102: } //namespace boost{ Chris@102: Chris@102: #endif //BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP