signals_common.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Boost.Signals library
  2. // Copyright Douglas Gregor 2001-2004.
  3. // Copyright Frank Mori Hess 2007. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see http://www.boost.org
  8. #ifndef BOOST_SIGNALS2_SIGNALS_COMMON_HPP
  9. #define BOOST_SIGNALS2_SIGNALS_COMMON_HPP
  10. #include <boost/mpl/bool.hpp>
  11. #include <boost/mpl/if.hpp>
  12. #include <boost/ref.hpp>
  13. #include <boost/signals2/signal_base.hpp>
  14. #include <boost/type_traits/is_base_of.hpp>
  15. namespace boost {
  16. namespace signals2 {
  17. namespace detail {
  18. // Determine if the given type T is a signal
  19. template<typename T>
  20. class is_signal: public mpl::bool_<is_base_of<signal_base, T>::value>
  21. {};
  22. // A slot can be a signal, a reference to a function object, or a
  23. // function object.
  24. struct signal_tag {};
  25. struct reference_tag {};
  26. struct value_tag {};
  27. // Classify the given slot as a signal, a reference-to-slot, or a
  28. // standard slot
  29. template<typename S>
  30. class get_slot_tag {
  31. typedef typename mpl::if_<is_signal<S>,
  32. signal_tag, value_tag>::type signal_or_value;
  33. public:
  34. typedef typename mpl::if_<is_reference_wrapper<S>,
  35. reference_tag,
  36. signal_or_value>::type type;
  37. };
  38. // Get the slot so that it can be copied
  39. template<typename F>
  40. typename F::weak_signal_type
  41. get_invocable_slot(const F &signal, signal_tag)
  42. { return typename F::weak_signal_type(signal); }
  43. template<typename F>
  44. const F&
  45. get_invocable_slot(const F& f, reference_tag)
  46. { return f; }
  47. template<typename F>
  48. const F&
  49. get_invocable_slot(const F& f, value_tag)
  50. { return f; }
  51. // Determines the type of the slot - is it a signal, a reference to a
  52. // slot or just a normal slot.
  53. template<typename F>
  54. typename get_slot_tag<F>::type
  55. tag_type(const F&)
  56. {
  57. typedef typename get_slot_tag<F>::type
  58. the_tag_type;
  59. the_tag_type tag = the_tag_type();
  60. return tag;
  61. }
  62. } // end namespace detail
  63. } // end namespace signals2
  64. } // end namespace boost
  65. #endif // BOOST_SIGNALS2_SIGNALS_COMMON_HPP