Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:37

0001 /////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga  2014-2014
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // See http://www.boost.org/libs/intrusive for documentation.
0010 //
0011 /////////////////////////////////////////////////////////////////////////////
0012 
0013 #ifndef BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP
0014 #define BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP
0015 
0016 #ifndef BOOST_CONFIG_HPP
0017 #  include <boost/config.hpp>
0018 #endif
0019 
0020 #if defined(BOOST_HAS_PRAGMA_ONCE)
0021 #  pragma once
0022 #endif
0023 
0024 #include <boost/intrusive/pointer_traits.hpp>
0025 #include <boost/intrusive/detail/mpl.hpp>
0026 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
0027 
0028 namespace boost {
0029 namespace intrusive {
0030 namespace detail {
0031 
0032 template<class VoidPointer>
0033 struct dummy_constptr
0034 {
0035    typedef typename boost::intrusive::pointer_traits<VoidPointer>::
0036       template rebind_pointer<const void>::type ConstVoidPtr;
0037 
0038    explicit dummy_constptr(ConstVoidPtr)
0039    {}
0040 
0041    dummy_constptr()
0042    {}
0043 
0044    ConstVoidPtr get_ptr() const
0045    {  return ConstVoidPtr();  }
0046 };
0047 
0048 template<class VoidPointer>
0049 struct constptr
0050 {
0051    typedef typename boost::intrusive::pointer_traits<VoidPointer>::
0052       template rebind_pointer<const void>::type ConstVoidPtr;
0053 
0054    constptr()
0055    {}
0056 
0057    explicit constptr(const ConstVoidPtr &ptr)
0058       :  const_void_ptr_(ptr)
0059    {}
0060 
0061    const void *get_ptr() const
0062    {  return boost::movelib::to_raw_pointer(const_void_ptr_);  }
0063 
0064    ConstVoidPtr const_void_ptr_;
0065 };
0066 
0067 template <class VoidPointer, bool store_ptr>
0068 struct select_constptr
0069 {
0070    typedef typename if_c
0071       < store_ptr
0072       , constptr<VoidPointer>
0073       , dummy_constptr<VoidPointer>
0074       >::type type;
0075 };
0076 
0077 
0078 template<class ValueTraits, bool IsConst>
0079 struct node_to_value
0080    :  public select_constptr
0081       < typename pointer_traits
0082             <typename ValueTraits::pointer>::template rebind_pointer<void>::type
0083       , is_stateful_value_traits<ValueTraits>::value
0084       >::type
0085 {
0086    static const bool stateful_value_traits = is_stateful_value_traits<ValueTraits>::value;
0087    typedef typename select_constptr
0088       < typename pointer_traits
0089             <typename ValueTraits::pointer>::
0090                template rebind_pointer<void>::type
0091       , stateful_value_traits >::type                 Base;
0092 
0093    typedef ValueTraits                                 value_traits;
0094    typedef typename value_traits::value_type           value_type;
0095    typedef typename value_traits::node_traits::node    node;
0096    typedef typename add_const_if_c
0097          <value_type, IsConst>::type                   vtype;
0098    typedef typename add_const_if_c
0099          <node, IsConst>::type                         ntype;
0100    typedef typename pointer_traits
0101       <typename ValueTraits::pointer>::
0102          template rebind_pointer<ntype>::type          npointer;
0103    typedef typename pointer_traits<npointer>::
0104       template rebind_pointer<const ValueTraits>::type const_value_traits_ptr;
0105 
0106    node_to_value(const_value_traits_ptr ptr)
0107       :  Base(ptr)
0108    {}
0109 
0110    typedef vtype &                                 result_type;
0111    typedef ntype &                                 first_argument_type;
0112 
0113    const_value_traits_ptr get_value_traits() const
0114    {  return pointer_traits<const_value_traits_ptr>::static_cast_from(Base::get_ptr());  }
0115 
0116    result_type to_value(first_argument_type arg, false_) const
0117    {  return *(value_traits::to_value_ptr(pointer_traits<npointer>::pointer_to(arg)));  }
0118 
0119    result_type to_value(first_argument_type arg, true_) const
0120    {  return *(this->get_value_traits()->to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); }
0121 
0122    result_type operator()(first_argument_type arg) const
0123    {  return this->to_value(arg, bool_<stateful_value_traits>()); }
0124 };
0125 
0126 }  //namespace detail{
0127 }  //namespace intrusive{
0128 }  //namespace boost{
0129 
0130 #endif //BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP