forked from boostorg/smart_ptr
Merged revision(s) 57197, 57206, 57423, 57518 from trunk:
Renamed enable_shared_from_this2 to enable_shared_from_raw and added shared_from_raw free function. These changes fix the pointer value in shared_ptr which were obtained before an external shared_ptr has taken ownership of the object (for example when a shared_ptr to this is obtained in an object's constructor). ........ Brought back code which fixes get_deleter when it is called on a deleter which has been wrapped inside a deleter_wrapper by "shared_from_raw() in constructors" support. ........ Added weak_from_raw(), for use in conjunction with enable_shared_from_raw base class. ........ Fixed access to enable_shared_from_raw::weak_this_ when BOOST_NO_MEMBER_TEMPLATE_FRIENDS is defined. ........ [SVN r81337]
This commit is contained in:
@@ -57,7 +57,7 @@ namespace boost
|
||||
template<class T> class shared_ptr;
|
||||
template<class T> class weak_ptr;
|
||||
template<class T> class enable_shared_from_this;
|
||||
template<class T> class enable_shared_from_this2;
|
||||
class enable_shared_from_raw;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
@@ -106,13 +106,7 @@ template< class X, class Y, class T > inline void sp_enable_shared_from_this( bo
|
||||
}
|
||||
}
|
||||
|
||||
template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_this2< T > const * pe )
|
||||
{
|
||||
if( pe != 0 )
|
||||
{
|
||||
pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
|
||||
}
|
||||
}
|
||||
template< class X, class Y > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe );
|
||||
|
||||
#ifdef _MANAGED
|
||||
|
||||
@@ -612,6 +606,9 @@ template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::
|
||||
|
||||
// get_deleter
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
|
||||
( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
|
||||
( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
|
||||
@@ -619,7 +616,7 @@ template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::
|
||||
// g++ 2.9x doesn't allow static_cast<X const *>(void *)
|
||||
// apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
|
||||
|
||||
template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
|
||||
template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
|
||||
{
|
||||
void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
|
||||
return const_cast<D *>(static_cast<D const *>(q));
|
||||
@@ -627,13 +624,55 @@ template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
|
||||
|
||||
#else
|
||||
|
||||
template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
|
||||
template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
|
||||
{
|
||||
return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class esft2_deleter_wrapper
|
||||
{
|
||||
private:
|
||||
|
||||
shared_ptr<void> deleter_;
|
||||
|
||||
public:
|
||||
|
||||
esft2_deleter_wrapper()
|
||||
{
|
||||
}
|
||||
|
||||
template< class T > void set_deleter( shared_ptr<T> const & deleter )
|
||||
{
|
||||
deleter_ = deleter;
|
||||
}
|
||||
template<typename D> D* get_deleter() const
|
||||
{
|
||||
return boost::detail::basic_get_deleter<D>(deleter_);
|
||||
}
|
||||
template< class T> void operator()( T* )
|
||||
{
|
||||
BOOST_ASSERT( deleter_.use_count() <= 1 );
|
||||
deleter_.reset();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
|
||||
{
|
||||
D *del = detail::basic_get_deleter<D>(p);
|
||||
if(del == 0)
|
||||
{
|
||||
detail::esft2_deleter_wrapper *del_wrapper = detail::basic_get_deleter<detail::esft2_deleter_wrapper>(p);
|
||||
// The following get_deleter method call is fully qualified because
|
||||
// older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>()
|
||||
if(del_wrapper) del = del_wrapper->::boost::detail::esft2_deleter_wrapper::get_deleter<D>();
|
||||
}
|
||||
return del;
|
||||
}
|
||||
|
||||
// atomic access
|
||||
|
||||
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
|
||||
|
||||
Reference in New Issue
Block a user