quite important changes in last couple of commits, increasing version to 0.1.2
[beacon-ss.git] / src / beacons / detail / slot.hpp
blobeb1dabcb453d583c4d95b14c0ff7bbe5dc7fa6fb
1 /**
2 * beacon
3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
5 */
7 #ifndef BOOST_PP_IS_ITERATING
9 #ifndef BEACONS_slot_H
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
23 namespace beacons {
25 namespace detail {
27 class slot_base : public reference_countable {
28 public:
29 virtual ~slot_base() {}
32 template<typename Signature>
33 class slot_impl_base;
35 template<typename SlotFunction, typename Signature>
36 class slot;
38 #include BOOST_PP_ITERATE()
40 } //namespace detail
42 } //namespace beacons
44 #endif //BEACONS_slot_H
46 #else //BOOST_PP_IS_ITERATING
48 #define n BOOST_PP_ITERATION()
50 template<typename R
51 BOOST_PP_COMMA_IF(n)
52 BOOST_PP_ENUM_PARAMS(n, typename T)>
53 class slot_impl_base<R(*)(BOOST_PP_ENUM_PARAMS(n, T))> : public slot_base {
54 public:
56 virtual R operator()(BOOST_PP_ENUM_PARAMS(n, T)) const = 0;
59 template<typename SlotFunction,
60 typename R
61 BOOST_PP_COMMA_IF(n)
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))> {
66 public:
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));
75 private:
76 SlotFunction _slot;
79 template<typename SlotFunction
80 BOOST_PP_COMMA_IF(n)
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))> {
85 public:
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));
94 private:
95 SlotFunction _slot;
97 #endif //BOOST_PP_IS_ITERATING