diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-06-01 08:48:42 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-06-01 09:24:28 (GMT) |
commit | 2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch) | |
tree | d46294f35150c4f0f43deaf2d31fceaf945ae715 /3rdParty/Boost/boost/smart_ptr/enable_shared_from_this.hpp | |
download | swift-contrib-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip swift-contrib-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2 |
Import.
Diffstat (limited to '3rdParty/Boost/boost/smart_ptr/enable_shared_from_this.hpp')
-rw-r--r-- | 3rdParty/Boost/boost/smart_ptr/enable_shared_from_this.hpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/3rdParty/Boost/boost/smart_ptr/enable_shared_from_this.hpp b/3rdParty/Boost/boost/smart_ptr/enable_shared_from_this.hpp new file mode 100644 index 0000000..f7b1445 --- /dev/null +++ b/3rdParty/Boost/boost/smart_ptr/enable_shared_from_this.hpp @@ -0,0 +1,79 @@ +#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 |