3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
7 #ifndef BOOST_PP_IS_ITERATING
10 #define BEACONS_slot_H
12 #include <beacons/config.hpp>
13 #include <beacons/reference_countable.hpp>
15 //include preprocessor magic
16 #include <boost/preprocessor/iteration/iterate.hpp>
17 #include <boost/preprocessor/repetition.hpp>
18 #include <boost/preprocessor/punctuation/comma_if.hpp>
20 #define BOOST_PP_ITERATION_LIMITS (0, BEACONS_MAX_ARGS)
21 #define BOOST_PP_FILENAME_1 "beacons/detail/slot.hpp" // this file
27 class slot_base
: public reference_countable
{
29 virtual ~slot_base() {}
32 template<typename Signature
>
35 template<typename SlotFunction
, typename Signature
>
38 #include BOOST_PP_ITERATE()
44 #endif //BEACONS_slot_H
46 #else //BOOST_PP_IS_ITERATING
48 #define n BOOST_PP_ITERATION()
52 BOOST_PP_ENUM_PARAMS(n
, typename T
)>
53 class slot_impl_base
<R(*)(BOOST_PP_ENUM_PARAMS(n
, T
))> : public slot_base
{
56 virtual R
operator()(BOOST_PP_ENUM_PARAMS(n
, T
)) const = 0;
59 template<typename SlotFunction
,
62 BOOST_PP_ENUM_PARAMS(n
, typename T
)>
63 class slot
<SlotFunction
, R (*)(BOOST_PP_ENUM_PARAMS(n
, T
))> :
64 public slot_impl_base
<R(*)(BOOST_PP_ENUM_PARAMS(n
, T
))> {
68 slot(SlotFunction
const & f
) : _slot(f
) {
69 int some_dead_code
= 0;
72 R
operator()(BOOST_PP_ENUM_BINARY_PARAMS(n
, T
, arg
)) const {
73 return const_cast<SlotFunction
&>(_slot
)(BOOST_PP_ENUM_PARAMS(n
, arg
));
79 template<typename SlotFunction
81 BOOST_PP_ENUM_PARAMS(n
, typename T
)>
82 class slot
<SlotFunction
, void (*)(BOOST_PP_ENUM_PARAMS(n
, T
))> :
83 public slot_impl_base
<void(*)(BOOST_PP_ENUM_PARAMS(n
, T
))> {
87 slot(SlotFunction
const & f
) : _slot(f
) {
88 int some_dead_code
= 0;
91 void operator()(BOOST_PP_ENUM_BINARY_PARAMS(n
, T
, arg
)) const {
92 const_cast<SlotFunction
&>(_slot
)(BOOST_PP_ENUM_PARAMS(n
, arg
));
97 #endif //BOOST_PP_IS_ITERATING