Chris@16
|
1 // Boost.Signals2 library
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright Frank Mori Hess 2007,2009.
|
Chris@16
|
4 // Copyright Timmo Stange 2007.
|
Chris@16
|
5 // Copyright Douglas Gregor 2001-2004. Use, modification and
|
Chris@16
|
6 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
7 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
8 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9
|
Chris@16
|
10 // Compatibility class to ease porting from the original
|
Chris@16
|
11 // Boost.Signals library. However,
|
Chris@16
|
12 // boost::signals2::trackable is NOT thread-safe.
|
Chris@16
|
13
|
Chris@16
|
14 // For more information, see http://www.boost.org
|
Chris@16
|
15
|
Chris@16
|
16 #ifndef BOOST_SIGNALS2_TRACKABLE_HPP
|
Chris@16
|
17 #define BOOST_SIGNALS2_TRACKABLE_HPP
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/assert.hpp>
|
Chris@16
|
20 #include <boost/shared_ptr.hpp>
|
Chris@101
|
21 #include <boost/weak_ptr.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost {
|
Chris@16
|
24 namespace signals2 {
|
Chris@16
|
25 namespace detail
|
Chris@16
|
26 {
|
Chris@16
|
27 class tracked_objects_visitor;
|
Chris@101
|
28
|
Chris@101
|
29 // trackable_pointee is used to identify the tracked shared_ptr
|
Chris@101
|
30 // originating from the signals2::trackable class. These tracked
|
Chris@101
|
31 // shared_ptr are special in that we shouldn't bother to
|
Chris@101
|
32 // increment their use count during signal invocation, since
|
Chris@101
|
33 // they don't actually control the lifetime of the
|
Chris@101
|
34 // signals2::trackable object they are associated with.
|
Chris@101
|
35 class trackable_pointee
|
Chris@101
|
36 {};
|
Chris@16
|
37 }
|
Chris@16
|
38 class trackable {
|
Chris@16
|
39 protected:
|
Chris@101
|
40 trackable(): _tracked_ptr(static_cast<detail::trackable_pointee*>(0)) {}
|
Chris@101
|
41 trackable(const trackable &): _tracked_ptr(static_cast<detail::trackable_pointee*>(0)) {}
|
Chris@16
|
42 trackable& operator=(const trackable &)
|
Chris@16
|
43 {
|
Chris@16
|
44 return *this;
|
Chris@16
|
45 }
|
Chris@16
|
46 ~trackable() {}
|
Chris@16
|
47 private:
|
Chris@16
|
48 friend class detail::tracked_objects_visitor;
|
Chris@101
|
49 weak_ptr<detail::trackable_pointee> get_weak_ptr() const
|
Chris@16
|
50 {
|
Chris@16
|
51 return _tracked_ptr;
|
Chris@16
|
52 }
|
Chris@16
|
53
|
Chris@101
|
54 shared_ptr<detail::trackable_pointee> _tracked_ptr;
|
Chris@16
|
55 };
|
Chris@16
|
56 } // end namespace signals2
|
Chris@16
|
57 } // end namespace boost
|
Chris@16
|
58
|
Chris@16
|
59 #endif // BOOST_SIGNALS2_TRACKABLE_HPP
|