signal.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. // Boost.Signals library
  2. // Copyright Douglas Gregor 2001-2006. Use, modification and
  3. // distribution is subject to the Boost Software License, Version
  4. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // For more information, see http://www.boost.org/libs/signals
  7. #ifndef BOOST_SIGNAL_HPP
  8. #define BOOST_SIGNAL_HPP
  9. #ifndef BOOST_SIGNALS_MAX_ARGS
  10. # define BOOST_SIGNALS_MAX_ARGS 10
  11. #endif
  12. #include <boost/config.hpp>
  13. #include <boost/type_traits/function_traits.hpp>
  14. #include <boost/signals/signal0.hpp>
  15. #include <boost/signals/signal1.hpp>
  16. #include <boost/signals/signal2.hpp>
  17. #include <boost/signals/signal3.hpp>
  18. #include <boost/signals/signal4.hpp>
  19. #include <boost/signals/signal5.hpp>
  20. #include <boost/signals/signal6.hpp>
  21. #include <boost/signals/signal7.hpp>
  22. #include <boost/signals/signal8.hpp>
  23. #include <boost/signals/signal9.hpp>
  24. #include <boost/signals/signal10.hpp>
  25. #include <boost/function.hpp>
  26. #ifdef BOOST_HAS_ABI_HEADERS
  27. # include BOOST_ABI_PREFIX
  28. #endif
  29. namespace boost {
  30. #ifndef BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
  31. namespace BOOST_SIGNALS_NAMESPACE {
  32. namespace detail {
  33. template<int Arity,
  34. typename Signature,
  35. typename Combiner,
  36. typename Group,
  37. typename GroupCompare,
  38. typename SlotFunction>
  39. class real_get_signal_impl;
  40. template<typename Signature,
  41. typename Combiner,
  42. typename Group,
  43. typename GroupCompare,
  44. typename SlotFunction>
  45. class real_get_signal_impl<0, Signature, Combiner, Group, GroupCompare,
  46. SlotFunction>
  47. {
  48. typedef function_traits<Signature> traits;
  49. public:
  50. typedef signal0<typename traits::result_type,
  51. Combiner,
  52. Group,
  53. GroupCompare,
  54. SlotFunction> type;
  55. };
  56. template<typename Signature,
  57. typename Combiner,
  58. typename Group,
  59. typename GroupCompare,
  60. typename SlotFunction>
  61. class real_get_signal_impl<1, Signature, Combiner, Group, GroupCompare,
  62. SlotFunction>
  63. {
  64. typedef function_traits<Signature> traits;
  65. public:
  66. typedef signal1<typename traits::result_type,
  67. typename traits::arg1_type,
  68. Combiner,
  69. Group,
  70. GroupCompare,
  71. SlotFunction> type;
  72. };
  73. template<typename Signature,
  74. typename Combiner,
  75. typename Group,
  76. typename GroupCompare,
  77. typename SlotFunction>
  78. class real_get_signal_impl<2, Signature, Combiner, Group, GroupCompare,
  79. SlotFunction>
  80. {
  81. typedef function_traits<Signature> traits;
  82. public:
  83. typedef signal2<typename traits::result_type,
  84. typename traits::arg1_type,
  85. typename traits::arg2_type,
  86. Combiner,
  87. Group,
  88. GroupCompare,
  89. SlotFunction> type;
  90. };
  91. template<typename Signature,
  92. typename Combiner,
  93. typename Group,
  94. typename GroupCompare,
  95. typename SlotFunction>
  96. class real_get_signal_impl<3, Signature, Combiner, Group, GroupCompare,
  97. SlotFunction>
  98. {
  99. typedef function_traits<Signature> traits;
  100. public:
  101. typedef signal3<typename traits::result_type,
  102. typename traits::arg1_type,
  103. typename traits::arg2_type,
  104. typename traits::arg3_type,
  105. Combiner,
  106. Group,
  107. GroupCompare,
  108. SlotFunction> type;
  109. };
  110. template<typename Signature,
  111. typename Combiner,
  112. typename Group,
  113. typename GroupCompare,
  114. typename SlotFunction>
  115. class real_get_signal_impl<4, Signature, Combiner, Group, GroupCompare,
  116. SlotFunction>
  117. {
  118. typedef function_traits<Signature> traits;
  119. public:
  120. typedef signal4<typename traits::result_type,
  121. typename traits::arg1_type,
  122. typename traits::arg2_type,
  123. typename traits::arg3_type,
  124. typename traits::arg4_type,
  125. Combiner,
  126. Group,
  127. GroupCompare,
  128. SlotFunction> type;
  129. };
  130. template<typename Signature,
  131. typename Combiner,
  132. typename Group,
  133. typename GroupCompare,
  134. typename SlotFunction>
  135. class real_get_signal_impl<5, Signature, Combiner, Group, GroupCompare,
  136. SlotFunction>
  137. {
  138. typedef function_traits<Signature> traits;
  139. public:
  140. typedef signal5<typename traits::result_type,
  141. typename traits::arg1_type,
  142. typename traits::arg2_type,
  143. typename traits::arg3_type,
  144. typename traits::arg4_type,
  145. typename traits::arg5_type,
  146. Combiner,
  147. Group,
  148. GroupCompare,
  149. SlotFunction> type;
  150. };
  151. template<typename Signature,
  152. typename Combiner,
  153. typename Group,
  154. typename GroupCompare,
  155. typename SlotFunction>
  156. class real_get_signal_impl<6, Signature, Combiner, Group, GroupCompare,
  157. SlotFunction>
  158. {
  159. typedef function_traits<Signature> traits;
  160. public:
  161. typedef signal6<typename traits::result_type,
  162. typename traits::arg1_type,
  163. typename traits::arg2_type,
  164. typename traits::arg3_type,
  165. typename traits::arg4_type,
  166. typename traits::arg5_type,
  167. typename traits::arg6_type,
  168. Combiner,
  169. Group,
  170. GroupCompare,
  171. SlotFunction> type;
  172. };
  173. template<typename Signature,
  174. typename Combiner,
  175. typename Group,
  176. typename GroupCompare,
  177. typename SlotFunction>
  178. class real_get_signal_impl<7, Signature, Combiner, Group, GroupCompare,
  179. SlotFunction>
  180. {
  181. typedef function_traits<Signature> traits;
  182. public:
  183. typedef signal7<typename traits::result_type,
  184. typename traits::arg1_type,
  185. typename traits::arg2_type,
  186. typename traits::arg3_type,
  187. typename traits::arg4_type,
  188. typename traits::arg5_type,
  189. typename traits::arg6_type,
  190. typename traits::arg7_type,
  191. Combiner,
  192. Group,
  193. GroupCompare,
  194. SlotFunction> type;
  195. };
  196. template<typename Signature,
  197. typename Combiner,
  198. typename Group,
  199. typename GroupCompare,
  200. typename SlotFunction>
  201. class real_get_signal_impl<8, Signature, Combiner, Group, GroupCompare,
  202. SlotFunction>
  203. {
  204. typedef function_traits<Signature> traits;
  205. public:
  206. typedef signal8<typename traits::result_type,
  207. typename traits::arg1_type,
  208. typename traits::arg2_type,
  209. typename traits::arg3_type,
  210. typename traits::arg4_type,
  211. typename traits::arg5_type,
  212. typename traits::arg6_type,
  213. typename traits::arg7_type,
  214. typename traits::arg8_type,
  215. Combiner,
  216. Group,
  217. GroupCompare,
  218. SlotFunction> type;
  219. };
  220. template<typename Signature,
  221. typename Combiner,
  222. typename Group,
  223. typename GroupCompare,
  224. typename SlotFunction>
  225. class real_get_signal_impl<9, Signature, Combiner, Group, GroupCompare,
  226. SlotFunction>
  227. {
  228. typedef function_traits<Signature> traits;
  229. public:
  230. typedef signal9<typename traits::result_type,
  231. typename traits::arg1_type,
  232. typename traits::arg2_type,
  233. typename traits::arg3_type,
  234. typename traits::arg4_type,
  235. typename traits::arg5_type,
  236. typename traits::arg6_type,
  237. typename traits::arg7_type,
  238. typename traits::arg8_type,
  239. typename traits::arg9_type,
  240. Combiner,
  241. Group,
  242. GroupCompare,
  243. SlotFunction> type;
  244. };
  245. template<typename Signature,
  246. typename Combiner,
  247. typename Group,
  248. typename GroupCompare,
  249. typename SlotFunction>
  250. class real_get_signal_impl<10, Signature, Combiner, Group, GroupCompare,
  251. SlotFunction>
  252. {
  253. typedef function_traits<Signature> traits;
  254. public:
  255. typedef signal10<typename traits::result_type,
  256. typename traits::arg1_type,
  257. typename traits::arg2_type,
  258. typename traits::arg3_type,
  259. typename traits::arg4_type,
  260. typename traits::arg5_type,
  261. typename traits::arg6_type,
  262. typename traits::arg7_type,
  263. typename traits::arg8_type,
  264. typename traits::arg9_type,
  265. typename traits::arg10_type,
  266. Combiner,
  267. Group,
  268. GroupCompare,
  269. SlotFunction> type;
  270. };
  271. template<typename Signature,
  272. typename Combiner,
  273. typename Group,
  274. typename GroupCompare,
  275. typename SlotFunction>
  276. struct get_signal_impl :
  277. public real_get_signal_impl<(function_traits<Signature>::arity),
  278. Signature,
  279. Combiner,
  280. Group,
  281. GroupCompare,
  282. SlotFunction>
  283. {
  284. };
  285. } // end namespace detail
  286. } // end namespace BOOST_SIGNALS_NAMESPACE
  287. // Very lightweight wrapper around the signalN classes that allows signals to
  288. // be created where the number of arguments does not need to be part of the
  289. // class name.
  290. template<
  291. typename Signature, // function type R (T1, T2, ..., TN)
  292. typename Combiner = last_value<typename function_traits<Signature>::result_type>,
  293. typename Group = int,
  294. typename GroupCompare = std::less<Group>,
  295. typename SlotFunction = function<Signature>
  296. >
  297. class signal :
  298. public BOOST_SIGNALS_NAMESPACE::detail::get_signal_impl<Signature,
  299. Combiner,
  300. Group,
  301. GroupCompare,
  302. SlotFunction>::type
  303. {
  304. typedef typename BOOST_SIGNALS_NAMESPACE::detail::get_signal_impl<
  305. Signature,
  306. Combiner,
  307. Group,
  308. GroupCompare,
  309. SlotFunction>::type base_type;
  310. public:
  311. explicit signal(const Combiner& combiner = Combiner(),
  312. const GroupCompare& group_compare = GroupCompare()) :
  313. base_type(combiner, group_compare)
  314. {
  315. }
  316. };
  317. #endif // ndef BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
  318. } // end namespace boost
  319. #ifdef BOOST_HAS_ABI_HEADERS
  320. # include BOOST_ABI_SUFFIX
  321. #endif
  322. #endif // BOOST_SIGNAL_HPP