From 10b68e6b5e7d12c7af51b960191e1be9eb788d2e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 27 Oct 2010 03:27:05 +0000 Subject: Interesting tweak to the variant and optparser classes. In the Variant, it would always fail if a const char * was passed in, it now converts these silently to Bu::FStrings, good to know... Also, the OptParser now uses a Variant for overrides, meaning it doesn't have to do extra parsing, and the amount of code you have to write may be significantly reduced. Pretty sweet, overall. There is one downside. For the moment if you use a non-standard type or object as the target of a parameter it always needs to have a formatter >> operator defined, even if you override and the formatter >> operator is never called. Hopefully we can get around this in the future. Also, it looks like it should be relatively trivial to create conversion functions for the variant, they'll just be global template functions that take two parameters, source type and target type. Should be good times. --- src/tools/myriad.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'src/tools') diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index 73ceba1..c6a3a4d 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp @@ -56,11 +56,11 @@ public: addOption( iStream, 's', "stream", "Substream to work with."); addOption( sSrc, "src", "Source file for copying into a Myriad file."); - setOverride( "create", "create" ); - setOverride( "info", "info" ); - setOverride( "new", "new" ); - setOverride( "dump", "dump" ); - setOverride( "put", "put" ); + setOverride( "create", modeCreate ); + setOverride( "info", modeInfo ); + setOverride( "new", modeStreamNew ); + setOverride( "dump", modeStreamDump ); + setOverride( "put", modeStreamPut ); parse( argc, argv ); } @@ -73,21 +73,9 @@ public: Bu::FString sSrc; }; -Bu::Formatter &operator>>( Bu::Formatter &f, Mode &m ) +Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) { - Bu::FString sTok = f.readToken(); - if( sTok == "create" ) - m = modeCreate; - else if( sTok == "info" ) - m = modeInfo; - else if( sTok == "new" ) - m = modeStreamNew; - else if( sTok == "dump" ) - m = modeStreamDump; - else if( sTok == "put" ) - m = modeStreamPut; - else - m = modeNone; + sio << "Uh oh, the formatter was called..." << sio.nl; return f; } -- cgit v1.2.3