Sha256: e4fc961d4328942d92665ac31382cd5a25133115f0c29459c54da312a1415bd1

Contents?: true

Size: 1.71 KB

Versions: 47

Compression:

Stored size: 1.71 KB

Contents

#ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
#define BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED

//
//  enable_shared_from_this.hpp
//
//  Copyright 2002, 2009 Peter Dimov
//
//  Distributed under the Boost Software License, Version 1.0.
//  See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt
//
//  http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
//

#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>

namespace boost
{

template<class T> class enable_shared_from_this
{
protected:

    enable_shared_from_this()
    {
    }

    enable_shared_from_this(enable_shared_from_this const &)
    {
    }

    enable_shared_from_this & operator=(enable_shared_from_this const &)
    {
        return *this;
    }

    ~enable_shared_from_this()
    {
    }

public:

    shared_ptr<T> shared_from_this()
    {
        shared_ptr<T> p( weak_this_ );
        BOOST_ASSERT( p.get() == this );
        return p;
    }

    shared_ptr<T const> shared_from_this() const
    {
        shared_ptr<T const> p( weak_this_ );
        BOOST_ASSERT( p.get() == this );
        return p;
    }

public: // actually private, but avoids compiler template friendship issues

    // Note: invoked automatically by shared_ptr; do not call
    template<class X, class Y> void _internal_accept_owner( shared_ptr<X> const * ppx, Y * py ) const
    {
        if( weak_this_.expired() )
        {
            weak_this_ = shared_ptr<T>( *ppx, py );
        }
    }

private:

    mutable weak_ptr<T> weak_this_;
};

} // namespace boost

#endif  // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED

Version data entries

47 entries across 47 versions & 4 rubygems

Version Path
passenger-4.0.20 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.19 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.18 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.17 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.16 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.14 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.13 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.10 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.8 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.7 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.6 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.5 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-3.0.21 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.4 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.3 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.2 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.1 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.0.rc6 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-4.0.0.rc4 ext/boost/smart_ptr/enable_shared_from_this.hpp
passenger-3.9.2.beta ext/boost/smart_ptr/enable_shared_from_this.hpp