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