isignal.h

Go to the documentation of this file.
00001 
00002 #if !defined(INCLUDED_ISIGNAL_H)
00003 #define INCLUDED_ISIGNAL_H
00004 
00005 #include "generic/callback.h"
00006 #include "signal/signalfwd.h"
00007 
00008 class SignalHandlerResult {
00009     bool value;
00010 public:
00011     explicit SignalHandlerResult(bool value) : value(value) {
00012     }
00013     bool operator==(SignalHandlerResult other) const {
00014         return value == other.value;
00015     }
00016     bool operator!=(SignalHandlerResult other) const {
00017         return !operator==(other);
00018     }
00019 };
00020 
00021 const SignalHandlerResult SIGNAL_CONTINUE_EMISSION = SignalHandlerResult(false);
00022 const SignalHandlerResult SIGNAL_STOP_EMISSION = SignalHandlerResult(true);
00023 
00024 template<typename Caller>
00025 class SignalHandlerCaller1 {
00026 public:
00027     typedef typename Caller::first_argument_type first_argument_type;
00028     typedef SignalHandlerResult result_type;
00029     static result_type call(first_argument_type a1) {
00030         Caller::call(a1);
00031         return SIGNAL_CONTINUE_EMISSION;
00032     }
00033 };
00034 
00035 template<typename Caller>
00036 class SignalHandlerCaller2 {
00037 public:
00038     typedef typename Caller::first_argument_type first_argument_type;
00039     typedef typename Caller::second_argument_type second_argument_type;
00040     typedef SignalHandlerResult result_type;
00041     static result_type call(first_argument_type a1, second_argument_type a2) {
00042         Caller::call(a1, a2);
00043         return SIGNAL_CONTINUE_EMISSION;
00044     }
00045 };
00046 
00047 template<typename Caller>
00048 class SignalHandlerCaller3 {
00049 public:
00050     typedef typename Caller::first_argument_type first_argument_type;
00051     typedef typename Caller::second_argument_type second_argument_type;
00052     typedef typename Caller::third_argument_type third_argument_type;
00053     typedef SignalHandlerResult result_type;
00054     static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3) {
00055         Caller::call(a1, a2, a3);
00056         return SIGNAL_CONTINUE_EMISSION;
00057     }
00058 };
00059 
00060 template<typename Caller>
00061 class SignalHandlerCaller4 {
00062 public:
00063     typedef typename Caller::first_argument_type first_argument_type;
00064     typedef typename Caller::second_argument_type second_argument_type;
00065     typedef typename Caller::third_argument_type third_argument_type;
00066     typedef typename Caller::fourth_argument_type fourth_argument_type;
00067     typedef SignalHandlerResult result_type;
00068     static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) {
00069         Caller::call(a1, a2, a3, a4);
00070         return SIGNAL_CONTINUE_EMISSION;
00071     }
00072 };
00073 
00074 class SignalHandler : public Callback0<SignalHandlerResult> {
00075 public:
00076     template<typename Caller>
00077     SignalHandler(const BindFirstOpaque<Caller>& caller)
00078             : Callback0<SignalHandlerResult>(BindFirstOpaque < typename TypeEqual <
00079                                              SignalHandlerResult,
00080                                              Caller,
00081                                              SignalHandlerCaller1<Caller>,
00082                                              typename Caller::result_type
00083                                              >::type > (caller.getBound())) {
00084     }
00085 };
00086 
00087 template<typename Caller>
00088 inline SignalHandler makeSignalHandler(const BindFirstOpaque<Caller>& caller) {
00089     return SignalHandler(caller);
00090 }
00091 template<typename Caller>
00092 inline SignalHandler makeSignalHandler(const Caller& caller, typename Caller::first_argument_type callee) {
00093     return SignalHandler(BindFirstOpaque<Caller>(callee));
00094 }
00095 
00096 
00097 template<typename FirstArgument>
00098 class SignalHandler1 : public Callback1<FirstArgument, SignalHandlerResult> {
00099 public:
00100     template<typename Caller>
00101     SignalHandler1(const BindFirstOpaque1<Caller>& caller)
00102             : Callback1<FirstArgument, SignalHandlerResult>(BindFirstOpaque1 < typename TypeEqual <
00103                     SignalHandlerResult,
00104                     Caller,
00105                     SignalHandlerCaller2<Caller>,
00106                     typename Caller::result_type
00107                     >::type > (caller.getBound())) {
00108     }
00109 };
00110 
00111 template<typename Caller>
00112 inline SignalHandler1<typename Caller::second_argument_type> makeSignalHandler1(const BindFirstOpaque1<Caller>& caller) {
00113     return SignalHandler1<typename Caller::second_argument_type>(caller);
00114 }
00115 template<typename Caller>
00116 inline SignalHandler1<typename Caller::second_argument_type> makeSignalHandler1(const Caller& caller, typename Caller::first_argument_type callee) {
00117     return SignalHandler1<typename Caller::second_argument_type>(BindFirstOpaque1<Caller>(callee));
00118 }
00119 
00120 
00121 template<typename FirstArgument, typename SecondArgument>
00122 class SignalHandler2 : public Callback2<FirstArgument, SecondArgument, SignalHandlerResult> {
00123 public:
00124     template<typename Caller>
00125     SignalHandler2(const BindFirstOpaque2<Caller>& caller)
00126             : Callback2<FirstArgument, SecondArgument, SignalHandlerResult>(BindFirstOpaque2 < typename TypeEqual <
00127                     SignalHandlerResult,
00128                     Caller,
00129                     SignalHandlerCaller3<Caller>,
00130                     typename Caller::result_type
00131                     >::type > (caller.getBound())) {
00132     }
00133 };
00134 
00135 template<typename Caller>
00136 inline SignalHandler2 <
00137 typename Caller::second_argument_type,
00138 typename Caller::third_argument_type
00139 > makeSignalHandler2(const BindFirstOpaque2<Caller>& caller) {
00140     return SignalHandler2 <
00141            typename Caller::second_argument_type,
00142            typename Caller::third_argument_type
00143            > (caller);
00144 }
00145 template<typename Caller>
00146 inline SignalHandler2 <
00147 typename Caller::second_argument_type,
00148 typename Caller::third_argument_type
00149 > makeSignalHandler2(const Caller& caller, typename Caller::first_argument_type callee) {
00150     return SignalHandler2 <
00151            typename Caller::second_argument_type,
00152            typename Caller::third_argument_type
00153            > (BindFirstOpaque2<Caller>(callee));
00154 }
00155 
00156 
00157 template<typename FirstArgument, typename SecondArgument, typename ThirdArgument>
00158 class SignalHandler3 : public Callback3<FirstArgument, SecondArgument, ThirdArgument, SignalHandlerResult> {
00159 public:
00160     template<typename Caller>
00161     SignalHandler3(const BindFirstOpaque3<Caller>& caller)
00162             : Callback3<FirstArgument, SecondArgument, ThirdArgument, SignalHandlerResult>(BindFirstOpaque3 < typename TypeEqual <
00163                     SignalHandlerResult,
00164                     Caller,
00165                     SignalHandlerCaller4<Caller>,
00166                     typename Caller::result_type
00167                     >::type > (caller.getBound())) {
00168     }
00169 };
00170 
00171 template<typename Caller>
00172 inline SignalHandler3 <
00173 typename Caller::second_argument_type,
00174 typename Caller::third_argument_type,
00175 typename Caller::fourth_argument_type
00176 > makeSignalHandler3(const BindFirstOpaque3<Caller>& caller) {
00177     return SignalHandler3 <
00178            typename Caller::second_argument_type,
00179            typename Caller::third_argument_type,
00180            typename Caller::fourth_argument_type
00181            > (caller);
00182 }
00183 template<typename Caller>
00184 inline SignalHandler3 <
00185 typename Caller::second_argument_type,
00186 typename Caller::third_argument_type,
00187 typename Caller::fourth_argument_type
00188 > makeSignalHandler3(const Caller& caller, typename Caller::first_argument_type callee) {
00189     return SignalHandler3 <
00190            typename Caller::second_argument_type,
00191            typename Caller::third_argument_type,
00192            typename Caller::fourth_argument_type
00193            > (BindFirstOpaque3<Caller>(callee));
00194 }
00195 
00196 #endif

Generated by  doxygen 1.6.2