From 0d3d73fb0cacd3d1cf7eb8b83ba87f8b740b871a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 16 Dec 2009 23:54:13 +0000 Subject: Signals is even safer and works even better. Also, OptParser is nearly done. Now I just have to come up with a way to modify data that you already have, that sure was a nice feature of the old one, even if it was implemented in a silly way. --- src/tests/optparser.cpp | 25 ++++++++++++++++++++++--- src/tests/signals.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 4 deletions(-) (limited to 'src/tests') diff --git a/src/tests/optparser.cpp b/src/tests/optparser.cpp index 9168af8..ee2ea58 100644 --- a/src/tests/optparser.cpp +++ b/src/tests/optparser.cpp @@ -8,13 +8,30 @@ public: Opts() : iBob( 542 ) { - callback( this, &Opts::cb ); + Option o; + o.sUsed = slot( this, &Opts::cb ); + o.cOpt = 'x'; + o.sOpt = "things"; + o.bShortHasParams = true; + o.sHelp = "This is the first test parameter. It calls a function, and takes parameters."; + addOption( o ); + + Option o2; + o2.sUsed = slot( this, &Opts::cb ); + o2.cOpt = 'y'; + o2.sOpt = "stuff"; + o2.bShortHasParams = false; + o2.sHelp = "This is the second test parameter. It does not take parameters. However, I do want to make this part much longer to see how it looks when you add way too much text to one of these things. It can't really be that bad, right?"; + addOption( o2 ); + + addHelpOption('h', "help", "This help."); } - int cb( int argc, char *argv[] ) + int cb( StrArray aParams ) { sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl; - return 5; + sio << "argv[] = " << aParams << sio.nl; + return 1; } int iBob; @@ -23,5 +40,7 @@ public: int main( int argc, char *argv[] ) { Opts o; + + o.parse( argc, argv ); } diff --git a/src/tests/signals.cpp b/src/tests/signals.cpp index b4b1363..4af2b8e 100644 --- a/src/tests/signals.cpp +++ b/src/tests/signals.cpp @@ -51,7 +51,32 @@ private: void pfnc0() { - sio << "This doesn't have state, it's pfnc0()!" << sio.nl; + sio << ": void pfnc0()" << sio.nl; +} + +void pfnc1( int a ) +{ + sio << ": void pfnc1( " << a << " )" << sio.nl; +} + +void pfnc2( int a, Bu::FString b ) +{ + sio << ": void pfnc2( " << a << ", \"" << b << "\" )" << sio.nl; +} + +void pfnc3( int a, Bu::FString b, double c ) +{ + sio << ": void pfnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl; +} + +void pfnc4( int a, Bu::FString b, double c, char d ) +{ + sio << ": void pfnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl; +} + +void pfnc5( int a, Bu::FString b, double c, char d, long e ) +{ + sio << ": void pfnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl; } void callit( Signal0 sig ) @@ -65,21 +90,33 @@ int main() Signal0 cb0( slot( &t, &Thing::fnc0 ) ); cb0(); + cb0 = slot( &pfnc0 ); + cb0(); Signal1 cb1( slot( &t, &Thing::fnc1 ) ); cb1( 5 ); + cb1 = slot( &pfnc1 ); + cb1( 5 ); Signal2 cb2( slot( &t, &Thing::fnc2 ) ); cb2( 5, "Hi there" ); + cb2 = slot( &pfnc2 ); + cb2( 5, "Hi there" ); Signal3 cb3( slot( &t, &Thing::fnc3 ) ); cb3( 5, "Hi there", 12.85 ); + cb3 = slot( &pfnc3 ); + cb3( 5, "Hi there", 12.85 ); Signal4 cb4( slot( &t, &Thing::fnc4 ) ); cb4( 5, "Hi there", 12.85, 'z' ); + cb4 = slot( &pfnc4 ); + cb4( 5, "Hi there", 12.85, 'z' ); Signal5 cb5( slot( &t, &Thing::fnc5 ) ); cb5( 5, "Hi there", 12.85, 'z', 849 ); + cb5 = slot( &pfnc5 ); + cb5( 5, "Hi there", 12.85, 'z', 849 ); // Signal1 cb1( slot( &t, &Thing::fnc1 ) ); // sio << "Result: " << cb1( 5 ) << sio.nl; -- cgit v1.2.3