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_TO_VALUE_HPP Chris@102: #define BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_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: Chris@102: namespace boost { Chris@102: namespace intrusive { Chris@102: namespace detail { Chris@102: Chris@102: template Chris@102: struct dummy_constptr Chris@102: { Chris@102: typedef typename boost::intrusive::pointer_traits:: Chris@102: template rebind_pointer::type ConstVoidPtr; Chris@102: Chris@102: explicit dummy_constptr(ConstVoidPtr) Chris@102: {} Chris@102: Chris@102: dummy_constptr() Chris@102: {} Chris@102: Chris@102: ConstVoidPtr get_ptr() const Chris@102: { return ConstVoidPtr(); } Chris@102: }; Chris@102: Chris@102: template Chris@102: struct constptr Chris@102: { Chris@102: typedef typename boost::intrusive::pointer_traits:: Chris@102: template rebind_pointer::type ConstVoidPtr; Chris@102: Chris@102: constptr() Chris@102: {} Chris@102: Chris@102: explicit constptr(const ConstVoidPtr &ptr) Chris@102: : const_void_ptr_(ptr) Chris@102: {} Chris@102: Chris@102: const void *get_ptr() const Chris@102: { return boost::intrusive::detail::to_raw_pointer(const_void_ptr_); } Chris@102: Chris@102: ConstVoidPtr const_void_ptr_; Chris@102: }; Chris@102: Chris@102: template Chris@102: struct select_constptr Chris@102: { Chris@102: typedef typename if_c Chris@102: < store_ptr Chris@102: , constptr Chris@102: , dummy_constptr Chris@102: >::type type; Chris@102: }; Chris@102: Chris@102: Chris@102: template Chris@102: struct node_to_value Chris@102: : public select_constptr Chris@102: < typename pointer_traits Chris@102: ::template rebind_pointer::type Chris@102: , is_stateful_value_traits::value Chris@102: >::type Chris@102: { Chris@102: static const bool stateful_value_traits = is_stateful_value_traits::value; Chris@102: typedef typename select_constptr Chris@102: < typename pointer_traits Chris@102: :: Chris@102: template rebind_pointer::type Chris@102: , stateful_value_traits >::type Base; Chris@102: Chris@102: typedef ValueTraits value_traits; Chris@102: typedef typename value_traits::value_type value_type; Chris@102: typedef typename value_traits::node_traits::node node; Chris@102: typedef typename add_const_if_c Chris@102: ::type vtype; Chris@102: typedef typename add_const_if_c Chris@102: ::type ntype; Chris@102: typedef typename pointer_traits Chris@102: :: Chris@102: template rebind_pointer::type npointer; Chris@102: typedef typename pointer_traits:: Chris@102: template rebind_pointer::type const_value_traits_ptr; Chris@102: Chris@102: node_to_value(const const_value_traits_ptr &ptr) Chris@102: : Base(ptr) Chris@102: {} Chris@102: Chris@102: typedef vtype & result_type; Chris@102: typedef ntype & first_argument_type; Chris@102: Chris@102: const_value_traits_ptr get_value_traits() const Chris@102: { return pointer_traits::static_cast_from(Base::get_ptr()); } Chris@102: Chris@102: result_type to_value(first_argument_type arg, false_) const Chris@102: { return *(value_traits::to_value_ptr(pointer_traits::pointer_to(arg))); } Chris@102: Chris@102: result_type to_value(first_argument_type arg, true_) const Chris@102: { return *(this->get_value_traits()->to_value_ptr(pointer_traits::pointer_to(arg))); } Chris@102: Chris@102: result_type operator()(first_argument_type arg) const Chris@102: { return this->to_value(arg, bool_()); } 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_TO_VALUE_HPP