]> git.lyx.org Git - lyx.git/blob - boost/boost/smart_ptr/enable_shared_from_this.hpp
Don't need this.
[lyx.git] / boost / boost / smart_ptr / enable_shared_from_this.hpp
1 #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED\r
2 #define BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED\r
3 \r
4 //\r
5 //  enable_shared_from_this.hpp\r
6 //\r
7 //  Copyright 2002, 2009 Peter Dimov\r
8 //\r
9 //  Distributed under the Boost Software License, Version 1.0.\r
10 //  See accompanying file LICENSE_1_0.txt or copy at\r
11 //  http://www.boost.org/LICENSE_1_0.txt\r
12 //\r
13 //  http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html\r
14 //\r
15 \r
16 #include <boost/smart_ptr/weak_ptr.hpp>\r
17 #include <boost/smart_ptr/shared_ptr.hpp>\r
18 #include <boost/assert.hpp>\r
19 #include <boost/config.hpp>\r
20 \r
21 namespace boost\r
22 {\r
23 \r
24 template<class T> class enable_shared_from_this\r
25 {\r
26 protected:\r
27 \r
28     enable_shared_from_this()\r
29     {\r
30     }\r
31 \r
32     enable_shared_from_this(enable_shared_from_this const &)\r
33     {\r
34     }\r
35 \r
36     enable_shared_from_this & operator=(enable_shared_from_this const &)\r
37     {\r
38         return *this;\r
39     }\r
40 \r
41     ~enable_shared_from_this()\r
42     {\r
43     }\r
44 \r
45 public:\r
46 \r
47     shared_ptr<T> shared_from_this()\r
48     {\r
49         shared_ptr<T> p( weak_this_ );\r
50         BOOST_ASSERT( p.get() == this );\r
51         return p;\r
52     }\r
53 \r
54     shared_ptr<T const> shared_from_this() const\r
55     {\r
56         shared_ptr<T const> p( weak_this_ );\r
57         BOOST_ASSERT( p.get() == this );\r
58         return p;\r
59     }\r
60 \r
61 public: // actually private, but avoids compiler template friendship issues\r
62 \r
63     // Note: invoked automatically by shared_ptr; do not call\r
64     template<class X, class Y> void _internal_accept_owner( shared_ptr<X> const * ppx, Y * py ) const\r
65     {\r
66         if( weak_this_.expired() )\r
67         {\r
68             weak_this_ = shared_ptr<T>( *ppx, py );\r
69         }\r
70     }\r
71 \r
72 private:\r
73 \r
74     mutable weak_ptr<T> weak_this_;\r
75 };\r
76 \r
77 } // namespace boost\r
78 \r
79 #endif  // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED\r