trackable.hpp 1.9 KB

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