Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:14:08

0001 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
0003 
0004 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 //
0011 //  detail/sp_counted_impl.hpp
0012 //
0013 //  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
0014 //  Copyright 2004-2005 Peter Dimov
0015 //
0016 // Distributed under the Boost Software License, Version 1.0. (See
0017 // accompanying file LICENSE_1_0.txt or copy at
0018 // http://www.boost.org/LICENSE_1_0.txt)
0019 //
0020 
0021 #include <boost/smart_ptr/detail/sp_counted_base.hpp>
0022 #include <boost/smart_ptr/detail/deprecated_macros.hpp>
0023 #include <boost/core/checked_delete.hpp>
0024 #include <boost/core/addressof.hpp>
0025 #include <boost/config.hpp>
0026 
0027 #include <memory>           // std::allocator, std::allocator_traits
0028 #include <cstddef>          // std::size_t
0029 
0030 namespace boost
0031 {
0032 
0033 namespace detail
0034 {
0035 
0036 // get_local_deleter
0037 
0038 template<class D> class local_sp_deleter;
0039 
0040 template<class D> D * get_local_deleter( D * /*p*/ ) noexcept
0041 {
0042     return 0;
0043 }
0044 
0045 template<class D> D * get_local_deleter( local_sp_deleter<D> * p ) noexcept;
0046 
0047 //
0048 
0049 template<class X> class BOOST_SYMBOL_VISIBLE sp_counted_impl_p: public sp_counted_base
0050 {
0051 private:
0052 
0053     X * px_;
0054 
0055     sp_counted_impl_p( sp_counted_impl_p const & );
0056     sp_counted_impl_p & operator= ( sp_counted_impl_p const & );
0057 
0058     typedef sp_counted_impl_p<X> this_type;
0059 
0060 public:
0061 
0062     explicit sp_counted_impl_p( X * px ): px_( px )
0063     {
0064     }
0065 
0066     void dispose() noexcept override
0067     {
0068         boost::checked_delete( px_ );
0069     }
0070 
0071     void * get_deleter( sp_typeinfo_ const & ) noexcept override
0072     {
0073         return 0;
0074     }
0075 
0076     void * get_local_deleter( sp_typeinfo_ const & ) noexcept override
0077     {
0078         return 0;
0079     }
0080 
0081     void * get_untyped_deleter() noexcept override
0082     {
0083         return 0;
0084     }
0085 };
0086 
0087 template<class P, class D> class BOOST_SYMBOL_VISIBLE sp_counted_impl_pd: public sp_counted_base
0088 {
0089 private:
0090 
0091     P ptr; // copy constructor must not throw
0092     D del; // copy/move constructor must not throw
0093 
0094     sp_counted_impl_pd( sp_counted_impl_pd const & );
0095     sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
0096 
0097     typedef sp_counted_impl_pd<P, D> this_type;
0098 
0099 public:
0100 
0101     // pre: d(p) must not throw
0102 
0103     sp_counted_impl_pd( P p, D & d ): ptr( p ), del( static_cast< D&& >( d ) )
0104     {
0105     }
0106 
0107     sp_counted_impl_pd( P p ): ptr( p ), del()
0108     {
0109     }
0110 
0111     void dispose() noexcept override
0112     {
0113         del( ptr );
0114     }
0115 
0116     void * get_deleter( sp_typeinfo_ const & ti ) noexcept override
0117     {
0118         return ti == BOOST_SP_TYPEID_(D)? &reinterpret_cast<char&>( del ): 0;
0119     }
0120 
0121     void * get_local_deleter( sp_typeinfo_ const & ti ) noexcept override
0122     {
0123         return ti == BOOST_SP_TYPEID_(D)? boost::detail::get_local_deleter( boost::addressof( del ) ): 0;
0124     }
0125 
0126     void * get_untyped_deleter() noexcept override
0127     {
0128         return &reinterpret_cast<char&>( del );
0129     }
0130 };
0131 
0132 template<class P, class D, class A> class BOOST_SYMBOL_VISIBLE sp_counted_impl_pda: public sp_counted_base
0133 {
0134 private:
0135 
0136     P p_; // copy constructor must not throw
0137     D d_; // copy/move constructor must not throw
0138     A a_; // copy constructor must not throw
0139 
0140     sp_counted_impl_pda( sp_counted_impl_pda const & );
0141     sp_counted_impl_pda & operator= ( sp_counted_impl_pda const & );
0142 
0143     typedef sp_counted_impl_pda<P, D, A> this_type;
0144 
0145 public:
0146 
0147     // pre: d( p ) must not throw
0148 
0149     sp_counted_impl_pda( P p, D & d, A a ): p_( p ), d_( static_cast< D&& >( d ) ), a_( a )
0150     {
0151     }
0152 
0153     sp_counted_impl_pda( P p, A a ): p_( p ), d_( a ), a_( a )
0154     {
0155     }
0156 
0157     void dispose() noexcept override
0158     {
0159         d_( p_ );
0160     }
0161 
0162     void destroy() noexcept override
0163     {
0164         typedef typename std::allocator_traits<A>::template rebind_alloc< this_type > A2;
0165 
0166         A2 a2( a_ );
0167 
0168         this->~this_type();
0169 
0170         a2.deallocate( this, 1 );
0171     }
0172 
0173     void * get_deleter( sp_typeinfo_ const & ti ) noexcept override
0174     {
0175         return ti == BOOST_SP_TYPEID_( D )? &reinterpret_cast<char&>( d_ ): 0;
0176     }
0177 
0178     void * get_local_deleter( sp_typeinfo_ const & ti ) noexcept override
0179     {
0180         return ti == BOOST_SP_TYPEID_( D )? boost::detail::get_local_deleter( boost::addressof( d_ ) ): 0;
0181     }
0182 
0183     void * get_untyped_deleter() noexcept override
0184     {
0185         return &reinterpret_cast<char&>( d_ );
0186     }
0187 };
0188 
0189 } // namespace detail
0190 
0191 } // namespace boost
0192 
0193 #endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED