]> git.lyx.org Git - lyx.git/blob - boost/boost/enable_shared_from_this.hpp
Boost 1.31.0
[lyx.git] / boost / boost / enable_shared_from_this.hpp
1 #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
2 #define BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
3
4 //
5 //  enable_shared_from_this.hpp
6 //
7 //  Copyright (c) 2002 Peter Dimov
8 //
9 //  Permission to copy, use, modify, sell and distribute this software
10 //  is granted provided this copyright notice appears in all copies.
11 //  This software is provided "as is" without express or implied
12 //  warranty, and with no claim as to its suitability for any purpose.
13 //
14 //  http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
15 //
16
17 #include <boost/weak_ptr.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include <boost/assert.hpp>
20 #include <boost/config.hpp>
21
22 namespace boost
23 {
24
25 template<class T> class enable_shared_from_this
26 {
27 protected:
28
29     enable_shared_from_this()
30     {
31     }
32
33     enable_shared_from_this(enable_shared_from_this const &)
34     {
35     }
36
37     enable_shared_from_this & operator=(enable_shared_from_this const &)
38     {
39         return *this;
40     }
41
42     ~enable_shared_from_this()
43     {
44     }
45
46 public:
47
48     shared_ptr<T> shared_from_this()
49     {
50         shared_ptr<T> p(_internal_weak_this);
51         BOOST_ASSERT(p.get() == this);
52         return p;
53     }
54
55     shared_ptr<T const> shared_from_this() const
56     {
57         shared_ptr<T const> p(_internal_weak_this);
58         BOOST_ASSERT(p.get() == this);
59         return p;
60     }
61
62     typedef T _internal_element_type; // for bcc 5.5.1
63     weak_ptr<_internal_element_type> _internal_weak_this;
64 };
65
66 } // namespace boost
67
68 #endif  // #ifndef BOOST_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED