diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-18T16·52+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-06-18T16·52+0000 |
commit | 3454c685eec2aebe6f61f7deebc40162bab22e69 (patch) | |
tree | f0345c0913ed95adc5dbee6e8d67eef9eca267e1 /src/boost/enable_shared_from_this.hpp | |
parent | 6ba26f27c3665ec5f72638a8c658b0aa68068410 (diff) |
* This is also useful.
Diffstat (limited to 'src/boost/enable_shared_from_this.hpp')
-rw-r--r-- | src/boost/enable_shared_from_this.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/boost/enable_shared_from_this.hpp b/src/boost/enable_shared_from_this.hpp new file mode 100644 index 000000000000..1d52e72c2077 --- /dev/null +++ b/src/boost/enable_shared_from_this.hpp @@ -0,0 +1,68 @@ +#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 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html +// + +#include <boost/weak_ptr.hpp> +#include <boost/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(_internal_weak_this); + BOOST_ASSERT(p.get() == this); + return p; + } + + shared_ptr<T const> shared_from_this() const + { + shared_ptr<T const> p(_internal_weak_this); + BOOST_ASSERT(p.get() == this); + return p; + } + + typedef T _internal_element_type; // for bcc 5.5.1 + weak_ptr<_internal_element_type> _internal_weak_this; +}; + +} // namespace boost + +#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED |