uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Signal.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 
27 
28 #ifndef U_CORE_SIGNAL_H
29 #define U_CORE_SIGNAL_H
30 
31 #include <boost/typeof/typeof.hpp>
32 
33 #include <boost/signals2/signal.hpp>
34 #include <boost/signals2/slot.hpp>
35 #include <boost/signals2/signal_type.hpp>
36 
37 #include "Function.h"
38 
39 
40 
41 
45 // Signals macro //
46 
47 #define default(vlaue)
48 #define slots
49 #define signals /*virtual void init_signals();*/ public
50 #define emit
51 #define SLOT(a) BOOST_STRINGIZE(a)
52 #define SIGNAL(a) BOOST_STRINGIZE(a)
53 
54 #define _ULIB_DETAIL_SIGNAL_EMIT(_name,...) \
55  static BOOST_AUTO(sig,this->findOrAddSignal(&_name)); \
56  sig->operator()(__VA_ARGS__);
57 
70 #define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__)
71 
72 
73 namespace uLib {
74 
75 
76 // A boost::signal wrapper structure ///////////////////////////////////////////
77 
78 // TODO ...
79 
80 typedef boost::signals2::signal_base SignalBase;
81 
82 template <typename T>
83 struct Signal {
84  typedef boost::signals2::signal<T> type;
85 };
86 
87 
88 
90 
91 
92 namespace detail {
93 
94 
95 template <typename FuncT, int arity>
96 struct ConnectSignal {};
97 
98 template <typename FuncT>
99 struct ConnectSignal< FuncT, 0 > {
100  static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
101  typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
102  reinterpret_cast<SigT*>(sigb)->connect(slof);
103  }
104 };
105 
106 template <typename FuncT>
107 struct ConnectSignal< FuncT, 1 > {
108  static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
109  typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
110  reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver));
111  }
112 };
113 
114 template <typename FuncT>
115 struct ConnectSignal< FuncT, 2 > {
116  static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
117  typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
118  reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1));
119  }
120 };
121 
122 template <typename FuncT>
123 struct ConnectSignal< FuncT, 3 > {
124  static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
125  typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
126  reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2));
127  }
128 };
129 
130 template <typename FuncT>
131 struct ConnectSignal< FuncT, 4 > {
132  static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
133  typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
134  reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3));
135  }
136 };
137 
138 template <typename FuncT>
139 struct ConnectSignal< FuncT, 5 > {
140  static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
141  typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
142  reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4));
143  }
144 };
145 
146 
147 } // detail
148 
149 
150 
151 template <typename FuncT>
153  // seems to work wow !
154  return new Signal<void()>::type;
155 }
156 
157 template <typename FuncT>
158 void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver)
159 {
161 }
162 
163 
164 
165 
166 } // uLib
167 
168 #endif // SIGNAL_H
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer< FuncT >::Object *receiver)
Definition: Signal.h:108
FunctionTypes< Func >::obj Object
Definition: Function.h:109
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer< FuncT >::Object *receiver)
Definition: Signal.h:116
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer< FuncT >::Object *receiver)
Definition: Signal.h:100
boost::signals2::signal< T > type
Definition: Signal.h:84
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer< FuncT >::Object *receiver)
Definition: Signal.h:132
SignalBase * NewSignal(FuncT f)
Definition: Signal.h:152
void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer< FuncT >::Object *receiver)
Definition: Signal.h:158
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer< FuncT >::Object *receiver)
Definition: Signal.h:124
Definition: Signal.h:83
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer< FuncT >::Object *receiver)
Definition: Signal.h:140
boost::signals2::signal_base SignalBase
Definition: Signal.h:80
Definition: Signal.h:96