preprocessed_slot.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // For more information, see http://www.boost.org
  9. #ifndef BOOST_SIGNALS2_PREPROCESSED_SLOT_HPP
  10. #define BOOST_SIGNALS2_PREPROCESSED_SLOT_HPP
  11. #include <boost/preprocessor/repetition.hpp>
  12. #include <boost/signals2/detail/preprocessed_arg_type.hpp>
  13. #include <boost/type_traits/function_traits.hpp>
  14. #ifndef BOOST_SIGNALS2_SLOT_MAX_BINDING_ARGS
  15. #define BOOST_SIGNALS2_SLOT_MAX_BINDING_ARGS 10
  16. #endif
  17. // template<typename Func, typename BindArgT0, typename BindArgT1, ..., typename BindArgTN-1> slotN(...
  18. #define BOOST_SIGNALS2_SLOT_N_BINDING_CONSTRUCTOR(z, n, data) \
  19. template<typename Func, BOOST_SIGNALS2_PREFIXED_ARGS_TEMPLATE_DECL(n, BindArg)> \
  20. BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_SIGNALS2_NUM_ARGS)( \
  21. const Func &func, BOOST_SIGNALS2_PREFIXED_FULL_REF_ARGS(n, const BindArg)) \
  22. { \
  23. init_slot_function(boost::bind(func, BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(n))); \
  24. }
  25. #define BOOST_SIGNALS2_SLOT_N_BINDING_CONSTRUCTORS \
  26. BOOST_PP_REPEAT_FROM_TO(1, BOOST_SIGNALS2_SLOT_MAX_BINDING_ARGS, BOOST_SIGNALS2_SLOT_N_BINDING_CONSTRUCTOR, ~)
  27. #define BOOST_PP_ITERATION_LIMITS (0, BOOST_PP_INC(BOOST_SIGNALS2_MAX_ARGS))
  28. #define BOOST_PP_FILENAME_1 <boost/signals2/detail/slot_template.hpp>
  29. #include BOOST_PP_ITERATE()
  30. #undef BOOST_SIGNALS2_SLOT_N_BINDING_CONSTRUCTOR
  31. #undef BOOST_SIGNALS2_SLOT_N_BINDING_CONSTRUCTORS
  32. namespace boost
  33. {
  34. namespace signals2
  35. {
  36. template<typename Signature,
  37. typename SlotFunction = boost::function<Signature> >
  38. class slot: public detail::slotN<function_traits<Signature>::arity,
  39. Signature, SlotFunction>::type
  40. {
  41. private:
  42. typedef typename detail::slotN<boost::function_traits<Signature>::arity,
  43. Signature, SlotFunction>::type base_type;
  44. public:
  45. template<typename F>
  46. slot(const F& f): base_type(f)
  47. {}
  48. // bind syntactic sugar
  49. // template<typename F, typename BindArgT0, typename BindArgT1, ..., typename BindArgTn-1> slot(...
  50. #define BOOST_SIGNALS2_SLOT_BINDING_CONSTRUCTOR(z, n, data) \
  51. template<typename Func, BOOST_SIGNALS2_PREFIXED_ARGS_TEMPLATE_DECL(n, BindArg)> \
  52. slot(const Func &func, BOOST_SIGNALS2_PREFIXED_FULL_REF_ARGS(n, const BindArg)): \
  53. base_type(func, BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(n)) \
  54. {}
  55. BOOST_PP_REPEAT_FROM_TO(1, BOOST_SIGNALS2_SLOT_MAX_BINDING_ARGS, BOOST_SIGNALS2_SLOT_BINDING_CONSTRUCTOR, ~)
  56. #undef BOOST_SIGNALS2_SLOT_BINDING_CONSTRUCTOR
  57. };
  58. } // namespace signals2
  59. }
  60. #endif // BOOST_SIGNALS2_PREPROCESSED_SLOT_HPP