]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/signal/signal.cpp
initial
[xonotic/netradiant.git] / libs / signal / signal.cpp
1
2 #include "signal.h"
3
4
5
6 namespace
7 {
8   class Test
9   {
10   };
11   class A1
12   {
13   };
14   class A2
15   {
16   };
17   class A3
18   {
19   };
20
21   SignalHandlerResult handler0(Test&)
22   {
23     return SIGNAL_CONTINUE_EMISSION;
24   }
25   typedef Function1<Test&, SignalHandlerResult, handler0> TestHandler0;
26
27   int function0(Test&)
28   {
29     return 7;
30   }
31   typedef Function1<Test&, int, function0> TestFunction0;
32
33   SignalHandlerResult handler1(Test&, A1)
34   {
35     return SIGNAL_CONTINUE_EMISSION;
36   }
37   typedef Function2<Test&, A1, SignalHandlerResult, handler1> TestHandler1;
38
39   void function1(Test&, A1)
40   {
41   }
42   typedef ReferenceCaller1<Test, A1, function1> TestFunction1;
43
44   SignalHandlerResult handler2(Test&, A1, A2)
45   {
46     return SIGNAL_CONTINUE_EMISSION;
47   }
48   typedef Function3<Test&, A1, A2, SignalHandlerResult, handler2> TestHandler2;
49
50   void function2(Test&, A1, A2)
51   {
52   }
53   typedef Function3<Test&, A1, A2, void, function2> TestFunction2;
54
55   SignalHandlerResult handler3(Test&, A1, A2, A3)
56   {
57     return SIGNAL_CONTINUE_EMISSION;
58   }
59   typedef Function4<Test&, A1, A2, A3, SignalHandlerResult, handler3> TestHandler3;
60
61   void function3(Test&, A1, A2, A3)
62   {
63   }
64   typedef Function4<Test&, A1, A2, A3, void, function3> TestFunction3;
65
66   void testSignals()
67   {
68     Test test;
69     {
70       Signal0 e0;
71       Signal0::handler_id_type a = e0.connectLast(makeSignalHandler(TestHandler0(), test)); // signal handler from direct caller returning result
72       Signal0::handler_id_type b = e0.connectFirst(makeSignalHandler(TestFunction0(), test)); // signal handler from direct caller returning int
73       e0();
74       e0.disconnect(a);
75       e0.disconnect(b);
76     }
77     {
78       typedef Signal1<A1> Signal1Test;
79       Signal1Test e1;
80       Signal1Test::handler_id_type a = e1.connectLast(makeSignalHandler1(TestHandler1(), test)); // signal handler from direct caller with one argument, returning result
81       Signal1Test::handler_id_type b = e1.connectFirst(makeSignalHandler1(TestFunction1(test))); // signal handler from opaque caller with one argument, returning void
82       e1(A1());
83       e1.disconnect(a);
84       e1.disconnect(b);
85     }
86     {
87       typedef Signal2<A1, A2> Signal2Test;
88       Signal2Test e2;
89       Signal2Test::handler_id_type a = e2.connectLast(makeSignalHandler2(TestHandler2(), test)); // signal handler from direct caller with two arguments, returning result
90       Signal2Test::handler_id_type b = e2.connectLast(makeSignalHandler2(TestFunction2(), test)); // signal handler from direct caller with two arguments, returning void
91       e2(A1(), A2());
92       e2.disconnect(a);
93       e2.disconnect(b);
94     }
95     {
96       typedef Signal3<A1, A2, A3> Signal3Test;
97       Signal3Test e3;
98       Signal3Test::handler_id_type a = e3.connectLast(makeSignalHandler3(TestHandler3(), test)); // signal handler from direct caller with three arguments, returning result
99       Signal3Test::handler_id_type b = e3.connectLast(makeSignalHandler3(TestFunction3(), test)); // signal handler from direct caller with three arguments, returning void
100       e3(A1(), A2(), A3());
101       e3.disconnect(a);
102       e3.disconnect(b);
103     }
104   }
105 }