fix doc example typo
[boost.git] / boost / signal.hpp
blobd1538e110d194865d390d9e2ff093d085544e64a
1 // Boost.Signals library
3 // Copyright Douglas Gregor 2001-2006. 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)
8 // For more information, see http://www.boost.org/libs/signals
10 #ifndef BOOST_SIGNAL_HPP
11 #define BOOST_SIGNAL_HPP
13 #ifndef BOOST_SIGNALS_MAX_ARGS
14 # define BOOST_SIGNALS_MAX_ARGS 10
15 #endif
17 #include <boost/config.hpp>
18 #include <boost/type_traits/function_traits.hpp>
19 #include <boost/signals/signal0.hpp>
20 #include <boost/signals/signal1.hpp>
21 #include <boost/signals/signal2.hpp>
22 #include <boost/signals/signal3.hpp>
23 #include <boost/signals/signal4.hpp>
24 #include <boost/signals/signal5.hpp>
25 #include <boost/signals/signal6.hpp>
26 #include <boost/signals/signal7.hpp>
27 #include <boost/signals/signal8.hpp>
28 #include <boost/signals/signal9.hpp>
29 #include <boost/signals/signal10.hpp>
30 #include <boost/function.hpp>
32 #ifdef BOOST_HAS_ABI_HEADERS
33 # include BOOST_ABI_PREFIX
34 #endif
36 namespace boost {
37 #ifndef BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
38 namespace BOOST_SIGNALS_NAMESPACE {
39 namespace detail {
40 template<int Arity,
41 typename Signature,
42 typename Combiner,
43 typename Group,
44 typename GroupCompare,
45 typename SlotFunction>
46 class real_get_signal_impl;
48 template<typename Signature,
49 typename Combiner,
50 typename Group,
51 typename GroupCompare,
52 typename SlotFunction>
53 class real_get_signal_impl<0, Signature, Combiner, Group, GroupCompare,
54 SlotFunction>
56 typedef function_traits<Signature> traits;
58 public:
59 typedef signal0<typename traits::result_type,
60 Combiner,
61 Group,
62 GroupCompare,
63 SlotFunction> type;
66 template<typename Signature,
67 typename Combiner,
68 typename Group,
69 typename GroupCompare,
70 typename SlotFunction>
71 class real_get_signal_impl<1, Signature, Combiner, Group, GroupCompare,
72 SlotFunction>
74 typedef function_traits<Signature> traits;
76 public:
77 typedef signal1<typename traits::result_type,
78 typename traits::arg1_type,
79 Combiner,
80 Group,
81 GroupCompare,
82 SlotFunction> type;
85 template<typename Signature,
86 typename Combiner,
87 typename Group,
88 typename GroupCompare,
89 typename SlotFunction>
90 class real_get_signal_impl<2, Signature, Combiner, Group, GroupCompare,
91 SlotFunction>
93 typedef function_traits<Signature> traits;
95 public:
96 typedef signal2<typename traits::result_type,
97 typename traits::arg1_type,
98 typename traits::arg2_type,
99 Combiner,
100 Group,
101 GroupCompare,
102 SlotFunction> type;
105 template<typename Signature,
106 typename Combiner,
107 typename Group,
108 typename GroupCompare,
109 typename SlotFunction>
110 class real_get_signal_impl<3, Signature, Combiner, Group, GroupCompare,
111 SlotFunction>
113 typedef function_traits<Signature> traits;
115 public:
116 typedef signal3<typename traits::result_type,
117 typename traits::arg1_type,
118 typename traits::arg2_type,
119 typename traits::arg3_type,
120 Combiner,
121 Group,
122 GroupCompare,
123 SlotFunction> type;
126 template<typename Signature,
127 typename Combiner,
128 typename Group,
129 typename GroupCompare,
130 typename SlotFunction>
131 class real_get_signal_impl<4, Signature, Combiner, Group, GroupCompare,
132 SlotFunction>
134 typedef function_traits<Signature> traits;
136 public:
137 typedef signal4<typename traits::result_type,
138 typename traits::arg1_type,
139 typename traits::arg2_type,
140 typename traits::arg3_type,
141 typename traits::arg4_type,
142 Combiner,
143 Group,
144 GroupCompare,
145 SlotFunction> type;
148 template<typename Signature,
149 typename Combiner,
150 typename Group,
151 typename GroupCompare,
152 typename SlotFunction>
153 class real_get_signal_impl<5, Signature, Combiner, Group, GroupCompare,
154 SlotFunction>
156 typedef function_traits<Signature> traits;
158 public:
159 typedef signal5<typename traits::result_type,
160 typename traits::arg1_type,
161 typename traits::arg2_type,
162 typename traits::arg3_type,
163 typename traits::arg4_type,
164 typename traits::arg5_type,
165 Combiner,
166 Group,
167 GroupCompare,
168 SlotFunction> type;
171 template<typename Signature,
172 typename Combiner,
173 typename Group,
174 typename GroupCompare,
175 typename SlotFunction>
176 class real_get_signal_impl<6, Signature, Combiner, Group, GroupCompare,
177 SlotFunction>
179 typedef function_traits<Signature> traits;
181 public:
182 typedef signal6<typename traits::result_type,
183 typename traits::arg1_type,
184 typename traits::arg2_type,
185 typename traits::arg3_type,
186 typename traits::arg4_type,
187 typename traits::arg5_type,
188 typename traits::arg6_type,
189 Combiner,
190 Group,
191 GroupCompare,
192 SlotFunction> type;
195 template<typename Signature,
196 typename Combiner,
197 typename Group,
198 typename GroupCompare,
199 typename SlotFunction>
200 class real_get_signal_impl<7, Signature, Combiner, Group, GroupCompare,
201 SlotFunction>
203 typedef function_traits<Signature> traits;
205 public:
206 typedef signal7<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 Combiner,
215 Group,
216 GroupCompare,
217 SlotFunction> type;
220 template<typename Signature,
221 typename Combiner,
222 typename Group,
223 typename GroupCompare,
224 typename SlotFunction>
225 class real_get_signal_impl<8, Signature, Combiner, Group, GroupCompare,
226 SlotFunction>
228 typedef function_traits<Signature> traits;
230 public:
231 typedef signal8<typename traits::result_type,
232 typename traits::arg1_type,
233 typename traits::arg2_type,
234 typename traits::arg3_type,
235 typename traits::arg4_type,
236 typename traits::arg5_type,
237 typename traits::arg6_type,
238 typename traits::arg7_type,
239 typename traits::arg8_type,
240 Combiner,
241 Group,
242 GroupCompare,
243 SlotFunction> type;
246 template<typename Signature,
247 typename Combiner,
248 typename Group,
249 typename GroupCompare,
250 typename SlotFunction>
251 class real_get_signal_impl<9, Signature, Combiner, Group, GroupCompare,
252 SlotFunction>
254 typedef function_traits<Signature> traits;
256 public:
257 typedef signal9<typename traits::result_type,
258 typename traits::arg1_type,
259 typename traits::arg2_type,
260 typename traits::arg3_type,
261 typename traits::arg4_type,
262 typename traits::arg5_type,
263 typename traits::arg6_type,
264 typename traits::arg7_type,
265 typename traits::arg8_type,
266 typename traits::arg9_type,
267 Combiner,
268 Group,
269 GroupCompare,
270 SlotFunction> type;
273 template<typename Signature,
274 typename Combiner,
275 typename Group,
276 typename GroupCompare,
277 typename SlotFunction>
278 class real_get_signal_impl<10, Signature, Combiner, Group, GroupCompare,
279 SlotFunction>
281 typedef function_traits<Signature> traits;
283 public:
284 typedef signal10<typename traits::result_type,
285 typename traits::arg1_type,
286 typename traits::arg2_type,
287 typename traits::arg3_type,
288 typename traits::arg4_type,
289 typename traits::arg5_type,
290 typename traits::arg6_type,
291 typename traits::arg7_type,
292 typename traits::arg8_type,
293 typename traits::arg9_type,
294 typename traits::arg10_type,
295 Combiner,
296 Group,
297 GroupCompare,
298 SlotFunction> type;
301 template<typename Signature,
302 typename Combiner,
303 typename Group,
304 typename GroupCompare,
305 typename SlotFunction>
306 struct get_signal_impl :
307 public real_get_signal_impl<(function_traits<Signature>::arity),
308 Signature,
309 Combiner,
310 Group,
311 GroupCompare,
312 SlotFunction>
316 } // end namespace detail
317 } // end namespace BOOST_SIGNALS_NAMESPACE
319 // Very lightweight wrapper around the signalN classes that allows signals to
320 // be created where the number of arguments does not need to be part of the
321 // class name.
322 template<
323 typename Signature, // function type R (T1, T2, ..., TN)
324 typename Combiner = last_value<typename function_traits<Signature>::result_type>,
325 typename Group = int,
326 typename GroupCompare = std::less<Group>,
327 typename SlotFunction = function<Signature>
329 class signal :
330 public BOOST_SIGNALS_NAMESPACE::detail::get_signal_impl<Signature,
331 Combiner,
332 Group,
333 GroupCompare,
334 SlotFunction>::type
336 typedef typename BOOST_SIGNALS_NAMESPACE::detail::get_signal_impl<
337 Signature,
338 Combiner,
339 Group,
340 GroupCompare,
341 SlotFunction>::type base_type;
343 public:
344 explicit signal(const Combiner& combiner = Combiner(),
345 const GroupCompare& group_compare = GroupCompare()) :
346 base_type(combiner, group_compare)
350 #endif // ndef BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
352 } // end namespace boost
354 #ifdef BOOST_HAS_ABI_HEADERS
355 # include BOOST_ABI_SUFFIX
356 #endif
358 #endif // BOOST_SIGNAL_HPP