2002-11-18 14:37:02 +00:00
|
|
|
#ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
|
|
|
|
#define BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
|
|
|
|
|
|
|
|
//
|
|
|
|
// enable_shared_from_this.hpp
|
|
|
|
//
|
|
|
|
// Copyright (c) 2002 Peter Dimov
|
|
|
|
//
|
2004-07-26 00:32:12 +00:00
|
|
|
// 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)
|
2002-11-18 14:37:02 +00:00
|
|
|
//
|
|
|
|
// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
|
|
|
|
//
|
|
|
|
|
2009-02-28 20:02:12 +00:00
|
|
|
#include <boost/weak_ptr.hpp>
|
2002-11-19 16:18:18 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/assert.hpp>
|
2009-02-28 20:02:12 +00:00
|
|
|
#include <boost/config.hpp>
|
2002-11-18 14:37:02 +00:00
|
|
|
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
|
2009-02-28 20:02:12 +00:00
|
|
|
template<class T> class enable_shared_from_this
|
2008-04-26 19:59:11 +00:00
|
|
|
{
|
2003-03-28 12:27:55 +00:00
|
|
|
protected:
|
|
|
|
|
2008-04-26 19:59:11 +00:00
|
|
|
enable_shared_from_this()
|
2003-03-28 12:27:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-26 19:59:11 +00:00
|
|
|
enable_shared_from_this(enable_shared_from_this const &)
|
2003-03-28 12:27:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_shared_from_this & operator=(enable_shared_from_this const &)
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-02-28 20:02:12 +00:00
|
|
|
~enable_shared_from_this()
|
2003-03-28 12:27:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-11-18 14:37:02 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
shared_ptr<T> shared_from_this()
|
|
|
|
{
|
2009-02-28 20:02:12 +00:00
|
|
|
shared_ptr<T> p(_internal_weak_this);
|
|
|
|
BOOST_ASSERT(p.get() == this);
|
|
|
|
return p;
|
2002-11-18 14:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
shared_ptr<T const> shared_from_this() const
|
|
|
|
{
|
2009-02-28 20:02:12 +00:00
|
|
|
shared_ptr<T const> p(_internal_weak_this);
|
|
|
|
BOOST_ASSERT(p.get() == this);
|
|
|
|
return p;
|
2008-04-26 19:59:11 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 20:02:12 +00:00
|
|
|
// Note: No, you don't need to initialize _internal_weak_this
|
|
|
|
//
|
|
|
|
// Please read the documentation, not the code
|
|
|
|
//
|
|
|
|
// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
|
2008-04-29 05:32:13 +00:00
|
|
|
|
2009-02-28 20:02:12 +00:00
|
|
|
typedef T _internal_element_type; // for bcc 5.5.1
|
|
|
|
mutable weak_ptr<_internal_element_type> _internal_weak_this;
|
2002-11-18 14:37:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace boost
|
|
|
|
|
|
|
|
#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
|