-#ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED\r
-#define BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED\r
-\r
-//\r
-// enable_shared_from_this2.hpp\r
-//\r
-// Copyright 2002, 2009 Peter Dimov\r
-// Copyright 2008 Frank Mori Hess\r
-//\r
-// Distributed under the Boost Software License, Version 1.0.\r
-// See accompanying file LICENSE_1_0.txt or copy at\r
-// http://www.boost.org/LICENSE_1_0.txt\r
-//\r
-\r
-#include <boost/config.hpp>\r
-#include <boost/shared_ptr.hpp>\r
-#include <boost/assert.hpp>\r
-#include <boost/detail/workaround.hpp>\r
-\r
-namespace boost\r
-{\r
-\r
-namespace detail\r
-{\r
-\r
-class esft2_deleter_wrapper\r
-{\r
-private:\r
-\r
- shared_ptr<void> deleter_;\r
-\r
-public:\r
-\r
- esft2_deleter_wrapper()\r
- {\r
- }\r
-\r
- template< class T > void set_deleter( shared_ptr<T> const & deleter )\r
- {\r
- deleter_ = deleter;\r
- }\r
-\r
- template< class T> void operator()( T* )\r
- {\r
- BOOST_ASSERT( deleter_.use_count() <= 1 );\r
- deleter_.reset();\r
- }\r
-};\r
-\r
-} // namespace detail\r
-\r
-template< class T > class enable_shared_from_this2\r
-{\r
-protected:\r
-\r
- enable_shared_from_this2()\r
- {\r
- }\r
-\r
- enable_shared_from_this2( enable_shared_from_this2 const & )\r
- {\r
- }\r
-\r
- enable_shared_from_this2 & operator=( enable_shared_from_this2 const & )\r
- {\r
- return *this;\r
- }\r
-\r
- ~enable_shared_from_this2()\r
- {\r
- BOOST_ASSERT( shared_this_.use_count() <= 1 ); // make sure no dangling shared_ptr objects exist\r
- }\r
-\r
-private:\r
-\r
- mutable weak_ptr<T> weak_this_;\r
- mutable shared_ptr<T> shared_this_;\r
-\r
-public:\r
-\r
- shared_ptr<T> shared_from_this()\r
- {\r
- init_weak_once();\r
- return shared_ptr<T>( weak_this_ );\r
- }\r
-\r
- shared_ptr<T const> shared_from_this() const\r
- {\r
- init_weak_once();\r
- return shared_ptr<T>( weak_this_ );\r
- }\r
-\r
-private:\r
-\r
- void init_weak_once() const\r
- {\r
- if( weak_this_._empty() )\r
- {\r
- shared_this_.reset( static_cast< T* >( 0 ), detail::esft2_deleter_wrapper() );\r
- weak_this_ = shared_this_;\r
- }\r
- }\r
-\r
-public: // actually private, but avoids compiler template friendship issues\r
-\r
- // Note: invoked automatically by shared_ptr; do not call\r
- template<class X, class Y> void _internal_accept_owner( shared_ptr<X> * ppx, Y * py ) const\r
- {\r
- BOOST_ASSERT( ppx != 0 );\r
-\r
- if( weak_this_.use_count() == 0 )\r
- {\r
- weak_this_ = shared_ptr<T>( *ppx, py );\r
- }\r
- else if( shared_this_.use_count() != 0 )\r
- {\r
- BOOST_ASSERT( ppx->unique() ); // no weak_ptrs should exist either, but there's no way to check that\r
-\r
- detail::esft2_deleter_wrapper * pd = boost::get_deleter<detail::esft2_deleter_wrapper>( shared_this_ );\r
- BOOST_ASSERT( pd != 0 );\r
-\r
- pd->set_deleter( *ppx );\r
-\r
- ppx->reset( shared_this_, ppx->get() );\r
- shared_this_.reset();\r
- }\r
- }\r
-};\r
-\r
-} // namespace boost\r
-\r
-#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED\r
+#ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED
+#define BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED
+
+//
+// enable_shared_from_this2.hpp
+//
+// Copyright 2002, 2009 Peter Dimov
+// Copyright 2008 Frank Mori Hess
+//
+// 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
+//
+
+#include <boost/config.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/assert.hpp>
+#include <boost/detail/workaround.hpp>
+
+namespace boost
+{
+
+namespace detail
+{
+
+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< class T> void operator()( T* )
+ {
+ BOOST_ASSERT( deleter_.use_count() <= 1 );
+ deleter_.reset();
+ }
+};
+
+} // namespace detail
+
+template< class T > class enable_shared_from_this2
+{
+protected:
+
+ enable_shared_from_this2()
+ {
+ }
+
+ enable_shared_from_this2( enable_shared_from_this2 const & )
+ {
+ }
+
+ enable_shared_from_this2 & operator=( enable_shared_from_this2 const & )
+ {
+ return *this;
+ }
+
+ ~enable_shared_from_this2()
+ {
+ BOOST_ASSERT( shared_this_.use_count() <= 1 ); // make sure no dangling shared_ptr objects exist
+ }
+
+private:
+
+ mutable weak_ptr<T> weak_this_;
+ mutable shared_ptr<T> shared_this_;
+
+public:
+
+ shared_ptr<T> shared_from_this()
+ {
+ init_weak_once();
+ return shared_ptr<T>( weak_this_ );
+ }
+
+ shared_ptr<T const> shared_from_this() const
+ {
+ init_weak_once();
+ return shared_ptr<T>( weak_this_ );
+ }
+
+private:
+
+ void init_weak_once() const
+ {
+ if( weak_this_._empty() )
+ {
+ shared_this_.reset( static_cast< T* >( 0 ), detail::esft2_deleter_wrapper() );
+ weak_this_ = shared_this_;
+ }
+ }
+
+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> * ppx, Y * py ) const
+ {
+ BOOST_ASSERT( ppx != 0 );
+
+ if( weak_this_.use_count() == 0 )
+ {
+ weak_this_ = shared_ptr<T>( *ppx, py );
+ }
+ else if( shared_this_.use_count() != 0 )
+ {
+ BOOST_ASSERT( ppx->unique() ); // no weak_ptrs should exist either, but there's no way to check that
+
+ detail::esft2_deleter_wrapper * pd = boost::get_deleter<detail::esft2_deleter_wrapper>( shared_this_ );
+ BOOST_ASSERT( pd != 0 );
+
+ pd->set_deleter( *ppx );
+
+ ppx->reset( shared_this_, ppx->get() );
+ shared_this_.reset();
+ }
+ }
+};
+
+} // namespace boost
+
+#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS2_HPP_INCLUDED