]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/signal/signal.cpp
netradiant: strip 16-bit png to 8-bit, fix #153
[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         return SIGNAL_CONTINUE_EMISSION;
23 }
24 typedef Function<SignalHandlerResult(Test&), handler0> TestHandler0;
25
26 int function0( Test& ){
27         return 7;
28 }
29 typedef Function<int(Test&), function0> TestFunction0;
30
31 SignalHandlerResult handler1( Test&, A1 ){
32         return SIGNAL_CONTINUE_EMISSION;
33 }
34 typedef Function<SignalHandlerResult(Test&, A1), handler1> TestHandler1;
35
36 void function1( Test&, A1 ){
37 }
38 typedef ReferenceCaller<Test, void(A1), function1> TestFunction1;
39
40 SignalHandlerResult handler2( Test&, A1, A2 ){
41         return SIGNAL_CONTINUE_EMISSION;
42 }
43 typedef Function<SignalHandlerResult(Test&, A1, A2), handler2> TestHandler2;
44
45 void function2( Test&, A1, A2 ){
46 }
47 typedef Function<void(Test&, A1, A2), function2> TestFunction2;
48
49 SignalHandlerResult handler3( Test&, A1, A2, A3 ){
50         return SIGNAL_CONTINUE_EMISSION;
51 }
52 typedef Function<SignalHandlerResult(Test&, A1, A2, A3), handler3> TestHandler3;
53
54 void function3( Test&, A1, A2, A3 ){
55 }
56 typedef Function<void(Test&, A1, A2, A3), function3> TestFunction3;
57
58 void testSignals(){
59         Test test;
60         {
61                 Signal0 e0;
62                 Signal0::handler_id_type a = e0.connectLast( makeSignalHandler( TestHandler0(), test ) ); // signal handler from direct caller returning result
63                 Signal0::handler_id_type b = e0.connectFirst( makeSignalHandler( TestFunction0(), test ) ); // signal handler from direct caller returning int
64                 e0();
65                 e0.disconnect( a );
66                 e0.disconnect( b );
67         }
68         {
69                 typedef Signal1<A1> Signal1Test;
70                 Signal1Test e1;
71                 Signal1Test::handler_id_type a = e1.connectLast( makeSignalHandler1( TestHandler1(), test ) ); // signal handler from direct caller with one argument, returning result
72                 Signal1Test::handler_id_type b = e1.connectFirst( makeSignalHandler1( TestFunction1( test ) ) ); // signal handler from opaque caller with one argument, returning void
73                 e1( A1() );
74                 e1.disconnect( a );
75                 e1.disconnect( b );
76         }
77         {
78                 typedef Signal2<A1, A2> Signal2Test;
79                 Signal2Test e2;
80                 Signal2Test::handler_id_type a = e2.connectLast( makeSignalHandler2( TestHandler2(), test ) ); // signal handler from direct caller with two arguments, returning result
81                 Signal2Test::handler_id_type b = e2.connectLast( makeSignalHandler2( TestFunction2(), test ) ); // signal handler from direct caller with two arguments, returning void
82                 e2( A1(), A2() );
83                 e2.disconnect( a );
84                 e2.disconnect( b );
85         }
86         {
87                 typedef Signal3<A1, A2, A3> Signal3Test;
88                 Signal3Test e3;
89                 Signal3Test::handler_id_type a = e3.connectLast( makeSignalHandler3( TestHandler3(), test ) ); // signal handler from direct caller with three arguments, returning result
90                 Signal3Test::handler_id_type b = e3.connectLast( makeSignalHandler3( TestFunction3(), test ) ); // signal handler from direct caller with three arguments, returning void
91                 e3( A1(), A2(), A3() );
92                 e3.disconnect( a );
93                 e3.disconnect( b );
94         }
95 }
96 }