11 #ifndef BOGUS_SIGNAL_HPP
12 #define BOGUS_SIGNAL_HPP
18 template <
typename Derived >
22 template<
typename Arg1,
typename Arg2 =
void,
typename Arg3 =
void >
26 template<
typename Derived >
42 void connect(
typename Traits::Function::Type func ) ;
46 template <
typename T >
47 void connect( T&
object,
typename Traits::template Method< T >::Type member_func ) ;
51 void connect(
const Derived &other ) ;
54 typedef std::list< typename Traits::Callable* > Callables ;
59 template <
typename Arg1,
typename Arg2,
typename Arg3 >
64 virtual ~Callable() {}
65 virtual void call( Arg1, Arg2, Arg3 ) = 0 ;
68 struct Function :
public Callable
70 typedef void (*Type)( Arg1, Arg2, Arg3 ) ;
72 Function ( Type _func ) : func( _func ) {}
73 virtual void call( Arg1 arg1, Arg2 arg2, Arg3 arg3 ) { func( arg1, arg2, arg3 ) ; }
75 template<
typename T >
76 struct Method :
public Callable
78 typedef void (T::*Type)( Arg1, Arg2, Arg3 ) ;
81 Method ( T& _obj, Type _func ) : obj( _obj ), func( _func ) {}
82 virtual void call( Arg1 arg1, Arg2 arg2, Arg3 arg3 ) { (obj.*func)( arg1, arg2, arg3 ) ; }
84 struct Proxy :
public Callable
88 Proxy(
const Type& _obj ) : obj( _obj ) {}
89 virtual void call( Arg1 arg1, Arg2 arg2, Arg3 arg3 ) { obj.trigger( arg1, arg2, arg3 ) ; }
93 template <
typename Arg1,
typename Arg2 >
98 virtual ~Callable() {}
99 virtual void call( Arg1, Arg2 ) = 0 ;
102 struct Function :
public Callable
104 typedef void (*Type)( Arg1, Arg2 ) ;
106 Function ( Type _func ) : func( _func ) {}
107 virtual void call( Arg1 arg1, Arg2 arg2 ) { func( arg1, arg2 ) ; }
109 template<
typename T >
110 struct Method :
public Callable
112 typedef void (T::*Type)( Arg1, Arg2 ) ;
115 Method ( T& _obj, Type _func ) : obj( _obj ), func( _func ) {}
116 virtual void call( Arg1 arg1, Arg2 arg2 ) { (obj.*func)( arg1, arg2 ) ; }
118 struct Proxy :
public Callable
122 Proxy(
const Type& _obj ) : obj( _obj ) {}
123 virtual void call( Arg1 arg1, Arg2 arg2 ) { obj.trigger( arg1, arg2 ) ; }
127 template<
typename Arg >
132 virtual ~Callable() {}
133 virtual void call( Arg ) = 0 ;
136 struct Function :
public Callable
138 typedef void (*Type)( Arg ) ;
140 Function ( Type _func ) : func( _func ) {}
141 virtual void call( Arg arg ) { func( arg ) ; }
143 template<
typename T >
144 struct Method :
public Callable
146 typedef void (T::*Type)( Arg ) ;
149 Method ( T& _obj, Type _func ) : obj( _obj ), func( _func ) {}
150 virtual void call( Arg arg ) { (obj.*func)( arg ) ; }
152 struct Proxy :
public Callable
156 Proxy(
const Type& _obj ) : obj( _obj ) {}
157 virtual void call( Arg arg ) { trigger( arg ) ; }
170 template<
typename Arg1,
typename Arg2,
typename Arg3 >
174 void trigger( Arg1 arg1, Arg2 arg2, Arg3 arg3 )
const
178 for(
typename Base::Callables::const_iterator it = this->m_callees.begin() ; it != this->m_callees.end() ; ++it )
179 { (*it)->call( arg1, arg2, arg3 ) ; }
184 template<
typename Arg1,
typename Arg2 >
192 for(
typename Base::Callables::const_iterator it = this->m_callees.begin() ; it != this->m_callees.end() ; ++it )
193 { (*it)->call( arg1, arg2 ) ; }
198 template<
typename Arg >
206 for(
typename Base::Callables::const_iterator it = this->m_callees.begin() ; it != this->m_callees.end() ; ++it )
207 { (*it)->call( arg ) ; }
212 template<
typename Derived >
214 for(
typename Callables::iterator it = m_callees.begin() ; it != m_callees.end() ; ++it )
221 template<
typename Derived >
224 m_callees.push_back(
new typename Traits::Function( func ) );
227 template<
typename Derived >
228 template <
typename T >
231 m_callees.push_back(
new typename Traits::template Method< T >(
object, member_func ) );
234 template<
typename Derived >
237 m_callees.push_back(
new typename Traits::Proxy( other ) );
Base class for Signal of different arities.
Definition: Signal.hpp:27
Definition: Signal.hpp:19
void trigger(Arg arg) const
Triggers the signal.
Definition: Signal.hpp:202
void trigger(Arg1 arg1, Arg2 arg2) const
Triggers the signal.
Definition: Signal.hpp:188
void disconnectAll()
Disconnects all listeners.
Definition: Signal.hpp:213
void trigger(Arg1 arg1, Arg2 arg2, Arg3 arg3) const
Triggers the signal.
Definition: Signal.hpp:174
void connect(typename Traits::Function::Type func)
Connects the signal to a free function.
Definition: Signal.hpp:222
Signal class, to which an arbitrary number of listeners can be connected.
Definition: Signal.hpp:23