Created
August 2, 2012 05:22
-
-
Save jeffomatic/3233944 to your computer and use it in GitHub Desktop.
blog: jl_signal, code: usage example
This file contains hidden or 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
// Declare and instantiate a signal for functions that take a | |
// single char arg. | |
JL_SIGNAL( char ) oKeyPressSignal; | |
// Two objects of unrelated type. | |
Piano oPiano; // plays notes | |
Transcriber oTranscriber; // generates text logs | |
// Lets assume the following instance method declarations: | |
// | |
// void Piano::PlayNote( char nKey ); | |
// void Transcriber::LogInput( char c ); | |
// | |
// Now let's connect these objects to oKeyPressSignal: | |
oKeyPressSignal.connect( &oPiano, &Piano::PlayNote ); | |
oKeyPressSignal.connect( &oTranscriber, &Transcriber::LogInput ); | |
for (;;) | |
{ | |
// Gather user input. | |
char nKey = getchar(); | |
// Terminate if the user presses ENTER. | |
if (nKey == 10) | |
{ | |
break; | |
} | |
// Now let's emit the signal with the user's input. This is the | |
// equivalent of making the following function calls: | |
// | |
// oPiano.PlayNote( nKey ); | |
// oTranscriber.LogInput( nKey ); | |
oKeyPressSignal.Emit( nKey ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment