This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A sample Emit() method on a signal object for slots that take | |
// two arguments. | |
void Emit( TArg1 a1, TArg2 a2 ) const | |
{ | |
// Here, the iterator is just a pointer to a list node. | |
// Incrementing the iterator means that we just follow the node's | |
// "next" pointer. But what happens if the current node is freed | |
// before the iterator can be incremented? | |
for ( ConnectionListIter i = m_oConnections.begin(); | |
i.isValid(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The "Boy Scout" principle of signal disconnection: | |
// clean up your own mess! | |
class ExampleContext | |
{ | |
void Init() | |
{ | |
m_pButton = new Button(); | |
m_pWindow = new Window(); | |
m_pButton->ClickSignal()->Connect( m_pWindow, &Window::Open ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExampleObserver : public EventObserver | |
{ | |
... | |
virtual void HandleEvent( Event e ) | |
{ | |
switch ( e.id ) | |
{ | |
case eAppEvent_Click: | |
... | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JL_SIGNAL() oSignalThatEmitsNoParams; | |
JL_SIGNAL( int ) oSignalThatEmitsInt; | |
JL_SIGNAL( const char* const* ) oEmitsConstArraysOfConstStrings; | |
JL_SIGNAL( unsigned, double, size_t, char**& ) oSignalThatIsComplicated; | |
JL_SIGNAL( JL_SIGNAL()& ) oSignalThatIsMeta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef jl::Signal< void(int) > SignalInt; | |
typedef jl::Signal< void(int, char) > SignalIntChar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Forward-declare an empty template class | |
template< typename SomeFunctionType > | |
class Signal; | |
// Specialize the above with a function type and trivially inherit | |
// from the signal class with the arity in the typename. | |
template< typename ReturnType, typename P1, typename P2 > | |
class Signal< ReturnType(P1, P2) > : public Signal2< P1, P2 > | |
{ | |
// Nothing required in here. But since this is not exactly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template< typename P1 > | |
class Signal { ... }; | |
template< typename P1, typename P2 > | |
class Signal { ... }; | |
typedef Signal< int > SignalInt; | |
typedef Signal< int, char > SignalIntChar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template< typename P1 > | |
class Signal1 { .... }; | |
template< typename P1, typename P2 > | |
class Signal2 { ... }; | |
... | |
template< typename P1, typename P2, typename P3, ..., template P8 > | |
class Signal8 { ... }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id="divs"></div> | |
<br /> | |
<div id="log"></div> | |
<script type="text/javascript" src="./jquery.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
// Build one div for each callback, to display the order of callback dispatch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JL_SIGNAL() oSignal; | |
void f1() { oSignal.Disconnect( &f1 ); } | |
void f2() { /* do something */ } | |
oSignal.Connect( &f1 ); | |
oSignal.Connect( &f2 ); | |
oSignal.Emit(); |