summaryrefslogtreecommitdiff
path: root/src/tests/signals.cpp
blob: b4b1363bd77c3ee23a123751e65a96161a4de66e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bu/signals.h>
#include <bu/sio.h>

using namespace Bu;

class Thing
{
public:
	Thing() :
		iState( 82731 )
	{
	}

	virtual ~Thing()
	{
	}

	void fnc0()
	{
		sio << iState << ": void fnc0()" << sio.nl;
	}
	
	void fnc1( int a )
	{
		sio << iState << ": void fnc1( " << a << " )" << sio.nl;
	}
	
	void fnc2( int a, Bu::FString b )
	{
		sio << iState << ": void fnc2( " << a << ", \"" << b << "\" )" << sio.nl;
	}
	
	void fnc3( int a, Bu::FString b, double c )
	{
		sio << iState << ": void fnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl;
	}
	
	void fnc4( int a, Bu::FString b, double c, char d )
	{
		sio << iState << ": void fnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl;
	}
	
	void fnc5( int a, Bu::FString b, double c, char d, long e )
	{
		sio << iState << ": void fnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl;
	}

private:
	int iState;
};

void pfnc0()
{
	sio << "This doesn't have state, it's pfnc0()!" << sio.nl;
}

void callit( Signal0<void> sig )
{
	sig();
}

int main()
{
	Thing t;

	Signal0<void> cb0( slot( &t, &Thing::fnc0 ) );
	cb0();
	
	Signal1<void, int> cb1( slot( &t, &Thing::fnc1 ) );
	cb1( 5 );
	
	Signal2<void, int, Bu::FString> cb2( slot( &t, &Thing::fnc2 ) );
	cb2( 5, "Hi there" );
	
	Signal3<void, int, Bu::FString, double> cb3( slot( &t, &Thing::fnc3 ) );
	cb3( 5, "Hi there", 12.85 );
	
	Signal4<void, int, Bu::FString, double, char> cb4( slot( &t, &Thing::fnc4 ) );
	cb4( 5, "Hi there", 12.85, 'z' );
	
	Signal5<void, int, Bu::FString, double, char, long> cb5( slot( &t, &Thing::fnc5 ) );
	cb5( 5, "Hi there", 12.85, 'z', 849 );

//	Signal1<int, int> cb1( slot( &t, &Thing::fnc1 ) );
//	sio << "Result: " << cb1( 5 ) << sio.nl;
}