Skip to content

Instantly share code, notes, and snippets.

@jeffomatic
Created August 2, 2012 05:22
Show Gist options
  • Save jeffomatic/3233944 to your computer and use it in GitHub Desktop.
Save jeffomatic/3233944 to your computer and use it in GitHub Desktop.
blog: jl_signal, code: usage example
// 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