author | William Roberts <williamr@symbian.org> |
Wed, 31 Mar 2010 12:27:01 +0100 | |
branch | Symbian2 |
changeset 3 | e1b950c65cb4 |
permissions | -rw-r--r-- |
williamr@2 | 1 |
#ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED |
williamr@2 | 2 |
#define BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED |
williamr@2 | 3 |
|
williamr@2 | 4 |
// |
williamr@2 | 5 |
// enable_shared_from_this.hpp |
williamr@2 | 6 |
// |
williamr@2 | 7 |
// Copyright (c) 2002 Peter Dimov |
williamr@2 | 8 |
// |
williamr@2 | 9 |
// Distributed under the Boost Software License, Version 1.0. (See |
williamr@2 | 10 |
// accompanying file LICENSE_1_0.txt or copy at |
williamr@2 | 11 |
// http://www.boost.org/LICENSE_1_0.txt) |
williamr@2 | 12 |
// |
williamr@2 | 13 |
// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html |
williamr@2 | 14 |
// |
williamr@2 | 15 |
|
williamr@2 | 16 |
#include <boost/weak_ptr.hpp> |
williamr@2 | 17 |
#include <boost/shared_ptr.hpp> |
williamr@2 | 18 |
#include <boost/assert.hpp> |
williamr@2 | 19 |
#include <boost/config.hpp> |
williamr@2 | 20 |
|
williamr@2 | 21 |
namespace boost |
williamr@2 | 22 |
{ |
williamr@2 | 23 |
|
williamr@2 | 24 |
template<class T> class enable_shared_from_this |
williamr@2 | 25 |
{ |
williamr@2 | 26 |
protected: |
williamr@2 | 27 |
|
williamr@2 | 28 |
enable_shared_from_this() |
williamr@2 | 29 |
{ |
williamr@2 | 30 |
} |
williamr@2 | 31 |
|
williamr@2 | 32 |
enable_shared_from_this(enable_shared_from_this const &) |
williamr@2 | 33 |
{ |
williamr@2 | 34 |
} |
williamr@2 | 35 |
|
williamr@2 | 36 |
enable_shared_from_this & operator=(enable_shared_from_this const &) |
williamr@2 | 37 |
{ |
williamr@2 | 38 |
return *this; |
williamr@2 | 39 |
} |
williamr@2 | 40 |
|
williamr@2 | 41 |
~enable_shared_from_this() |
williamr@2 | 42 |
{ |
williamr@2 | 43 |
} |
williamr@2 | 44 |
|
williamr@2 | 45 |
public: |
williamr@2 | 46 |
|
williamr@2 | 47 |
shared_ptr<T> shared_from_this() |
williamr@2 | 48 |
{ |
williamr@2 | 49 |
shared_ptr<T> p(_internal_weak_this); |
williamr@2 | 50 |
BOOST_ASSERT(p.get() == this); |
williamr@2 | 51 |
return p; |
williamr@2 | 52 |
} |
williamr@2 | 53 |
|
williamr@2 | 54 |
shared_ptr<T const> shared_from_this() const |
williamr@2 | 55 |
{ |
williamr@2 | 56 |
shared_ptr<T const> p(_internal_weak_this); |
williamr@2 | 57 |
BOOST_ASSERT(p.get() == this); |
williamr@2 | 58 |
return p; |
williamr@2 | 59 |
} |
williamr@2 | 60 |
|
williamr@2 | 61 |
// Note: No, you don't need to initialize _internal_weak_this |
williamr@2 | 62 |
// |
williamr@2 | 63 |
// Please read the documentation, not the code |
williamr@2 | 64 |
// |
williamr@2 | 65 |
// http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html |
williamr@2 | 66 |
|
williamr@2 | 67 |
typedef T _internal_element_type; // for bcc 5.5.1 |
williamr@2 | 68 |
mutable weak_ptr<_internal_element_type> _internal_weak_this; |
williamr@2 | 69 |
}; |
williamr@2 | 70 |
|
williamr@2 | 71 |
} // namespace boost |
williamr@2 | 72 |
|
williamr@2 | 73 |
#endif // #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED |