summaryrefslogtreecommitdiff
path: root/src/tests/signal.cpp
blob: 8920461fdf614088e0417d201a3bcd2d1b37601e (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
#include <bu/signals.h>
#include <bu/list.h>
#include <bu/string.h>
#include <bu/sio.h>

using namespace Bu;

void PrintPlain( const Bu::String &s )
{
	println(s);
}

void PrintFancy( const Bu::String &s )
{
	println("STRING!!! ->%1<- !!!GNIRTS").arg( s );
}

int Square( int a )
{
	return a*a;
}

int Double( int a )
{
	return a+a;
}

template<typename R, typename P>
class SignalList1 : public Bu::List<Bu::Signal1<R,P> >
{
	typedef Bu::List<Bu::Signal1<R,P> > MyType;
public:
	SignalList1()
	{
	}

	using MyType::iterator;
	using MyType::const_iterator;

	R operator()( P p1 )
	{
		println("===Non-void um...non-specialization===");
		R tmp;
		for( typename MyType::iterator i = MyType::begin(); i; i++ )
			tmp = (*i)( p1 );
		return tmp;
	}
};

template<typename P>
class SignalList1<void, P> : public Bu::List<Bu::Signal1<void,P> >
{
	typedef Bu::List<Bu::Signal1<void,P> > MyType;
public:
	SignalList1()
	{
	}

	using MyType::iterator;
	using MyType::const_iterator;

	void operator()( P p1 )
	{
		println("===Void specialization===");
		for( typename MyType::iterator i = MyType::begin(); i; i++ )
			(*i)( p1 );
	}
};

int main()
{
	SignalList1<void,const Bu::String &> lPrints;

	lPrints += slot(PrintPlain);
	lPrints += slot(PrintFancy);

	lPrints("Hello there");

	SignalList1<int,int> lMaths;
	lMaths += slot(Double);
	lMaths += slot(Square);
	println("Math'd %1 = %2").arg( 5 ).arg( lMaths(5) );

	return 0;
}