signals_common_macros.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. Author: Frank Mori Hess <fmhess@users.sourceforge.net>
  3. Begin: 2007-01-23
  4. */
  5. // Copyright Frank Mori Hess 2007-2008
  6. // Use, modification and
  7. // distribution is subject to the Boost Software License, Version
  8. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_SIGNALS2_SIGNALS_COMMON_MACROS_HPP
  11. #define BOOST_SIGNALS2_SIGNALS_COMMON_MACROS_HPP
  12. #include <boost/config.hpp>
  13. #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
  14. #ifndef BOOST_SIGNALS2_MAX_ARGS
  15. #define BOOST_SIGNALS2_MAX_ARGS 9
  16. #endif
  17. // signaln
  18. #define BOOST_SIGNALS2_SIGNAL_CLASS_NAME(arity) BOOST_PP_CAT(signal, arity)
  19. // weak_signaln
  20. #define BOOST_SIGNALS2_WEAK_SIGNAL_CLASS_NAME(arity) BOOST_PP_CAT(weak_, BOOST_SIGNALS2_SIGNAL_CLASS_NAME(arity))
  21. // signaln_impl
  22. #define BOOST_SIGNALS2_SIGNAL_IMPL_CLASS_NAME(arity) BOOST_PP_CAT(BOOST_SIGNALS2_SIGNAL_CLASS_NAME(arity), _impl)
  23. // argn
  24. #define BOOST_SIGNALS2_SIGNATURE_ARG_NAME(z, n, data) BOOST_PP_CAT(arg, BOOST_PP_INC(n))
  25. // Tn argn
  26. #define BOOST_SIGNALS2_SIGNATURE_FULL_ARG(z, n, data) \
  27. BOOST_PP_CAT(T, BOOST_PP_INC(n)) BOOST_SIGNALS2_SIGNATURE_ARG_NAME(~, n, ~)
  28. // T1 arg1, T2 arg2, ..., Tn argn
  29. #define BOOST_SIGNALS2_SIGNATURE_FULL_ARGS(arity) \
  30. BOOST_PP_ENUM(arity, BOOST_SIGNALS2_SIGNATURE_FULL_ARG, ~)
  31. // arg1, arg2, ..., argn
  32. #define BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(arity) BOOST_PP_ENUM(arity, BOOST_SIGNALS2_SIGNATURE_ARG_NAME, ~)
  33. // T1, T2, ..., TN
  34. #define BOOST_SIGNALS2_ARGS_TEMPLATE_INSTANTIATION(arity) \
  35. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), T)
  36. // R (T1, T2, ..., TN)
  37. #define BOOST_SIGNALS2_SIGNATURE_FUNCTION_TYPE(arity) \
  38. R ( BOOST_SIGNALS2_ARGS_TEMPLATE_INSTANTIATION(arity) )
  39. // typename prefixR, typename prefixT1, typename prefixT2, ..., typename prefixTN
  40. #define BOOST_SIGNALS2_PREFIXED_SIGNATURE_TEMPLATE_DECL(arity, prefix) \
  41. typename BOOST_PP_CAT(prefix, R) BOOST_PP_COMMA_IF(arity) \
  42. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), typename BOOST_PP_CAT(prefix, T))
  43. // typename R, typename T1, typename T2, ..., typename TN
  44. #define BOOST_SIGNALS2_SIGNATURE_TEMPLATE_DECL(arity) \
  45. typename R BOOST_PP_COMMA_IF(arity) \
  46. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), typename T)
  47. // typename prefixT1, typename prefixT2, ..., typename prefixTN
  48. #define BOOST_SIGNALS2_PREFIXED_ARGS_TEMPLATE_DECL(arity, prefix) \
  49. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), typename BOOST_PP_CAT(prefix, T))
  50. // typename T1, typename T2, ..., typename TN
  51. #define BOOST_SIGNALS2_ARGS_TEMPLATE_DECL(arity) \
  52. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), typename T)
  53. // prefixR, prefixT1, prefixT2, ..., prefixTN
  54. #define BOOST_SIGNALS2_PREFIXED_SIGNATURE_TEMPLATE_INSTANTIATION(arity, prefix) \
  55. BOOST_PP_CAT(prefix, R) BOOST_PP_COMMA_IF(arity) BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), BOOST_PP_CAT(prefix, T))
  56. // R, T1, T2, ..., TN
  57. #define BOOST_SIGNALS2_SIGNATURE_TEMPLATE_INSTANTIATION(arity) \
  58. R BOOST_PP_COMMA_IF(arity) BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), T)
  59. // boost::functionN<R, T1, T2, ..., TN>
  60. #define BOOST_SIGNALS2_FUNCTION_N_DECL(arity) BOOST_PP_CAT(boost::function, arity)<\
  61. BOOST_SIGNALS2_SIGNATURE_TEMPLATE_INSTANTIATION(arity) >
  62. // R, const boost::signals2::connection&, T1, T2, ..., TN
  63. #define BOOST_SIGNALS2_EXT_SLOT_TEMPLATE_INSTANTIATION(arity) \
  64. R, const boost::signals2::connection& BOOST_PP_COMMA_IF(arity) \
  65. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(arity), T)
  66. // boost::functionN<R, const boost::signals2::connection &, T1, T2, ..., TN>
  67. #define BOOST_SIGNALS2_EXT_FUNCTION_N_DECL(arity) BOOST_PP_CAT(boost::function, BOOST_PP_INC(arity))<\
  68. BOOST_SIGNALS2_EXT_SLOT_TEMPLATE_INSTANTIATION(arity) >
  69. // slotN
  70. #define BOOST_SIGNALS2_SLOT_CLASS_NAME(arity) BOOST_PP_CAT(slot, arity)
  71. // slotN+1<R, const connection &, T1, T2, ..., TN, extended_slot_function_type>
  72. #define BOOST_SIGNALS2_EXTENDED_SLOT_TYPE(arity) \
  73. BOOST_SIGNALS2_SLOT_CLASS_NAME(BOOST_PP_INC(arity))< \
  74. BOOST_SIGNALS2_EXT_SLOT_TEMPLATE_INSTANTIATION(arity), \
  75. extended_slot_function_type>
  76. // bound_extended_slot_functionN
  77. #define BOOST_SIGNALS2_BOUND_EXTENDED_SLOT_FUNCTION_N(arity) BOOST_PP_CAT(bound_extended_slot_function, arity)
  78. // bound_extended_slot_function_helperN
  79. #define BOOST_SIGNALS2_BOUND_EXTENDED_SLOT_FUNCTION_INVOKER_N(arity) BOOST_PP_CAT(bound_extended_slot_function_invoker, arity)
  80. // typename function_traits<Signature>::argn_type
  81. #define BOOST_SIGNALS2_SIGNATURE_TO_ARGN_TYPE(z, n, Signature) \
  82. BOOST_PP_CAT(BOOST_PP_CAT(typename function_traits<Signature>::arg, BOOST_PP_INC(n)), _type)
  83. // typename function_traits<Signature>::result_type,
  84. // typename function_traits<Signature>::arg1_type,
  85. // typename function_traits<Signature>::arg2_type,
  86. // ...,
  87. // typename function_traits<Signature>::argn_type
  88. #define BOOST_SIGNALS2_PORTABLE_SIGNATURE(arity, Signature) \
  89. typename function_traits<Signature>::result_type \
  90. BOOST_PP_COMMA_IF(arity) BOOST_PP_ENUM(arity, BOOST_SIGNALS2_SIGNATURE_TO_ARGN_TYPE, Signature)
  91. // prefixTn & argn
  92. #define BOOST_SIGNALS2_PREFIXED_FULL_REF_ARG(z, n, prefix) \
  93. BOOST_PP_CAT(BOOST_PP_CAT(prefix, T), BOOST_PP_INC(n)) & BOOST_SIGNALS2_SIGNATURE_ARG_NAME(~, n, ~)
  94. // prefixT1 & arg1, prefixT2 & arg2, ..., prefixTn & argn
  95. #define BOOST_SIGNALS2_PREFIXED_FULL_REF_ARGS(arity, prefix) \
  96. BOOST_PP_ENUM(arity, BOOST_SIGNALS2_PREFIXED_FULL_REF_ARG, prefix)
  97. // Tn & argn
  98. #define BOOST_SIGNALS2_FULL_CREF_ARG(z, n, data) \
  99. const BOOST_PP_CAT(T, BOOST_PP_INC(n)) & BOOST_SIGNALS2_SIGNATURE_ARG_NAME(~, n, ~)
  100. // const T1 & arg1, const T2 & arg2, ..., const Tn & argn
  101. #define BOOST_SIGNALS2_FULL_FORWARD_ARGS(arity) \
  102. BOOST_PP_ENUM(arity, BOOST_SIGNALS2_FULL_CREF_ARG, ~)
  103. #define BOOST_SIGNALS2_FORWARDED_ARGS(arity) \
  104. BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(arity)
  105. // preprocessed_arg_typeN
  106. #define BOOST_SIGNALS2_PREPROCESSED_ARG_N_TYPE_CLASS_NAME(arity) BOOST_PP_CAT(preprocessed_arg_type, arity)
  107. // typename R, typename T1, typename T2, ..., typename TN, typename SlotFunction
  108. #define BOOST_SIGNALS2_SLOT_TEMPLATE_SPECIALIZATION_DECL(arity) \
  109. BOOST_SIGNALS2_SIGNATURE_TEMPLATE_DECL(arity), \
  110. typename SlotFunction
  111. #define BOOST_SIGNALS2_SLOT_TEMPLATE_SPECIALIZATION
  112. // typename R, typename T1, typename T2, ..., typename TN, typename Combiner, ...
  113. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_DECL(arity) \
  114. BOOST_SIGNALS2_SIGNATURE_TEMPLATE_DECL(arity), \
  115. typename Combiner, \
  116. typename Group, \
  117. typename GroupCompare, \
  118. typename SlotFunction, \
  119. typename ExtendedSlotFunction, \
  120. typename Mutex
  121. // typename R, typename T1, typename T2, ..., typename TN, typename Combiner = optional_last_value<R>, ...
  122. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_DEFAULTED_DECL(arity) \
  123. BOOST_SIGNALS2_SIGNATURE_TEMPLATE_DECL(arity), \
  124. typename Combiner = optional_last_value<R>, \
  125. typename Group = int, \
  126. typename GroupCompare = std::less<Group>, \
  127. typename SlotFunction = BOOST_SIGNALS2_FUNCTION_N_DECL(arity), \
  128. typename ExtendedSlotFunction = BOOST_SIGNALS2_EXT_FUNCTION_N_DECL(arity), \
  129. typename Mutex = signals2::mutex
  130. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_SPECIALIZATION_DECL(arity) BOOST_SIGNALS2_SIGNAL_TEMPLATE_DECL(arity)
  131. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_SPECIALIZATION
  132. #define BOOST_SIGNALS2_STD_FUNCTIONAL_BASE std_functional_base
  133. #define BOOST_SIGNALS2_PP_COMMA_IF(arity) BOOST_PP_COMMA_IF(arity)
  134. #else // BOOST_NO_CXX11_VARIADIC_TEMPLATES
  135. #define BOOST_SIGNALS2_SIGNAL_CLASS_NAME(arity) signal
  136. #define BOOST_SIGNALS2_WEAK_SIGNAL_CLASS_NAME(arity) weak_signal
  137. #define BOOST_SIGNALS2_SIGNAL_IMPL_CLASS_NAME(arity) signal_impl
  138. #define BOOST_SIGNALS2_SIGNATURE_TEMPLATE_DECL(arity) typename Signature
  139. #define BOOST_SIGNALS2_ARGS_TEMPLATE_INSTANTIATION(arity) Args...
  140. #define BOOST_SIGNALS2_SIGNATURE_TEMPLATE_INSTANTIATION(arity) R (Args...)
  141. #define BOOST_SIGNALS2_SIGNATURE_FUNCTION_TYPE(arity) R (Args...)
  142. #define BOOST_SIGNALS2_ARGS_TEMPLATE_DECL(arity) typename ... Args
  143. #define BOOST_SIGNALS2_FULL_FORWARD_ARGS(arity) Args && ... args
  144. #define BOOST_SIGNALS2_FORWARDED_ARGS(arity) std::forward<Args>(args)...
  145. #define BOOST_SIGNALS2_SLOT_CLASS_NAME(arity) slot
  146. #define BOOST_SIGNALS2_EXTENDED_SLOT_TYPE(arity) slot<R (const connection &, Args...), extended_slot_function_type>
  147. #define BOOST_SIGNALS2_BOUND_EXTENDED_SLOT_FUNCTION_N(arity) bound_extended_slot_function
  148. #define BOOST_SIGNALS2_BOUND_EXTENDED_SLOT_FUNCTION_INVOKER_N(arity) bound_extended_slot_function_invoker
  149. #define BOOST_SIGNALS2_FUNCTION_N_DECL(arity) boost::function<Signature>
  150. #define BOOST_SIGNALS2_PREFIXED_SIGNATURE_TEMPLATE_DECL(arity, prefix) typename prefixSignature
  151. #define BOOST_SIGNALS2_PREFIXED_SIGNATURE_TEMPLATE_INSTANTIATION(arity, prefix) prefixSignature
  152. #define BOOST_SIGNALS2_SIGNATURE_FULL_ARGS(arity) Args ... args
  153. #define BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(arity) args...
  154. #define BOOST_SIGNALS2_PORTABLE_SIGNATURE(arity, Signature) Signature
  155. #define BOOST_SIGNALS2_SLOT_TEMPLATE_SPECIALIZATION_DECL(arity) \
  156. typename SlotFunction, \
  157. typename R, \
  158. typename ... Args
  159. #define BOOST_SIGNALS2_SLOT_TEMPLATE_SPECIALIZATION \
  160. <R (Args...), SlotFunction>
  161. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_DECL(arity) \
  162. typename Signature, \
  163. typename Combiner, \
  164. typename Group, \
  165. typename GroupCompare, \
  166. typename SlotFunction, \
  167. typename ExtendedSlotFunction, \
  168. typename Mutex
  169. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_DEFAULTED_DECL(arity) \
  170. typename Signature, \
  171. typename Combiner = optional_last_value<typename boost::function_traits<Signature>::result_type>, \
  172. typename Group = int, \
  173. typename GroupCompare = std::less<Group>, \
  174. typename SlotFunction = boost::function<Signature>, \
  175. typename ExtendedSlotFunction = typename detail::variadic_extended_signature<Signature>::function_type, \
  176. typename Mutex = signals2::mutex
  177. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_SPECIALIZATION_DECL(arity) \
  178. typename Combiner, \
  179. typename Group, \
  180. typename GroupCompare, \
  181. typename SlotFunction, \
  182. typename ExtendedSlotFunction, \
  183. typename Mutex, \
  184. typename R, \
  185. typename ... Args
  186. #define BOOST_SIGNALS2_SIGNAL_TEMPLATE_SPECIALIZATION <\
  187. R (Args...), \
  188. Combiner, \
  189. Group, \
  190. GroupCompare, \
  191. SlotFunction, \
  192. ExtendedSlotFunction, \
  193. Mutex>
  194. #define BOOST_SIGNALS2_STD_FUNCTIONAL_BASE \
  195. std_functional_base<Args...>
  196. #define BOOST_SIGNALS2_PP_COMMA_IF(arity) ,
  197. #endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
  198. #endif // BOOST_SIGNALS2_SIGNALS_COMMON_MACROS_HPP