From ee4e8d9783c019c86ca757cb7898b618d9a4029f Mon Sep 17 00:00:00 2001 From: mes5k Date: Fri, 21 Jan 2005 04:03:20 +0000 Subject: [PATCH] fixed xor bug --- include/tclap/Arg.h | 7 +++++ include/tclap/MultiArg.h | 35 ++++++++++++++++++++---- include/tclap/UnlabeledMultiArg.h | 15 ++++++++++- include/tclap/XorHandler.h | 44 +++++-------------------------- 4 files changed, 57 insertions(+), 44 deletions(-) diff --git a/include/tclap/Arg.h b/include/tclap/Arg.h index 054307c..1f74ea2 100644 --- a/include/tclap/Arg.h +++ b/include/tclap/Arg.h @@ -329,6 +329,8 @@ class Arg */ void setRequireLabel( const std::string& s ); + virtual bool allowMore(); + }; /** @@ -560,6 +562,11 @@ inline void Arg::addToList( std::list& argList ) const argList.push_front( (Arg*)this ); } +inline bool Arg::allowMore() +{ + return false; +} + ////////////////////////////////////////////////////////////////////// //END Arg.cpp ////////////////////////////////////////////////////////////////////// diff --git a/include/tclap/MultiArg.h b/include/tclap/MultiArg.h index 06546ab..cc0e5b3 100644 --- a/include/tclap/MultiArg.h +++ b/include/tclap/MultiArg.h @@ -191,6 +191,8 @@ class MultiArg : public Arg */ void _extractValue( const std::string& val ); + bool _allowMore; + public: /** @@ -323,6 +325,8 @@ class MultiArg : public Arg */ virtual bool isRequired() const; + virtual bool allowMore(); + }; template @@ -334,7 +338,8 @@ MultiArg::MultiArg(const std::string& flag, Visitor* v) : Arg( flag, name, desc, req, true, v ), _typeDesc( typeDesc ), - _constraint( NULL ) + _constraint( NULL ), + _allowMore(false) { } template @@ -347,7 +352,8 @@ MultiArg::MultiArg(const std::string& flag, Visitor* v) : Arg( flag, name, desc, req, true, v ), _typeDesc( typeDesc ), - _constraint( NULL ) + _constraint( NULL ), + _allowMore(false) { parser.add( this ); } @@ -364,7 +370,8 @@ MultiArg::MultiArg(const std::string& flag, Visitor* v) : Arg( flag, name, desc, req, true, v ), _typeDesc( constraint->shortID() ), - _constraint( constraint ) + _constraint( constraint ), + _allowMore(false) { } template @@ -377,7 +384,8 @@ MultiArg::MultiArg(const std::string& flag, Visitor* v) : Arg( flag, name, desc, req, true, v ), _typeDesc( constraint->shortID() ), - _constraint( constraint ) + _constraint( constraint ), + _allowMore(false) { parser.add( this ); } @@ -406,6 +414,7 @@ bool MultiArg::processArg(int *i, std::vector& args) "Couldn't find delimiter for this argument!", toString() ) ); + // always take the first one, regardless of start string if ( value == "" ) { (*i)++; @@ -414,10 +423,19 @@ bool MultiArg::processArg(int *i, std::vector& args) else throw( ArgParseException("Missing a value for this argument!", toString() ) ); - } + } else _extractValue( value ); + /* + // continuing taking the args until we hit one with a start string + while ( (unsigned int)(*i)+1 < args.size() && + args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && + args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) + _extractValue( args[++(*i)] ); + */ + + _alreadySet = true; _checkWithVisitor(); return true; @@ -490,6 +508,13 @@ void MultiArg::_extractValue( const std::string& val ) toString() ) ); } +template +bool MultiArg::allowMore() +{ + bool am = _allowMore; + _allowMore = true; + return am; +} } // namespace TCLAP diff --git a/include/tclap/UnlabeledMultiArg.h b/include/tclap/UnlabeledMultiArg.h index 5a9eea3..52b2966 100644 --- a/include/tclap/UnlabeledMultiArg.h +++ b/include/tclap/UnlabeledMultiArg.h @@ -227,7 +227,20 @@ bool UnlabeledMultiArg::processArg(int *i, std::vector& args) // never ignore an unlabeled multi arg - _extractValue( args[*i] ); + + // always take the first value, regardless of the start string + _extractValue( args[(*i)] ); + + /* + // continue taking args until we hit the end or a start string + while ( (unsigned int)(*i)+1 < args.size() && + args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 && + args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) + _extractValue( args[++(*i)] ); + */ + + _alreadySet = true; + return true; } diff --git a/include/tclap/XorHandler.h b/include/tclap/XorHandler.h index 4e66368..5116119 100644 --- a/include/tclap/XorHandler.h +++ b/include/tclap/XorHandler.h @@ -97,49 +97,14 @@ inline void XorHandler::add( std::vector& ors ) _orList.push_back( ors ); } -/* -inline std::string XorHandler::shortUsage() -{ - std::string out = ""; - for ( int i = 0; (unsigned int)i < _orList.size(); i++ ) - { - out += " {"; - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); it++ ) - out += (*it)->shortID() + "|"; - - out[out.length()-1] = '}'; - } - - return out; -} - -inline void XorHandler::printLongUsage( std::ostream& os ) -{ - for ( int i = 0; (unsigned int)i < _orList.size(); i++ ) - { - for ( ArgVectorIterator it = _orList[i].begin(); - it != _orList[i].end(); - it++ ) - { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - - if ( it+1 != _orList[i].end() ) - spacePrint(os, "-- OR --", 75, 9); - } - os << std::endl << std::endl; - } -} -*/ inline int XorHandler::check( const Arg* a ) { // iterate over each XOR list for ( int i = 0; (unsigned int)i < _orList.size(); i++ ) { // if the XOR list contains the arg.. - if ( find( _orList[i].begin(), _orList[i].end(), a ) != - _orList[i].end() ) + ArgVectorIterator ait = find( _orList[i].begin(), _orList[i].end(), a ); + if ( ait != _orList[i].end() ) { // go through and set each arg that is not a for ( ArgVectorIterator it = _orList[i].begin(); @@ -149,7 +114,10 @@ inline int XorHandler::check( const Arg* a ) (*it)->xorSet(); // return the number of required args that have now been set - return (int)_orList[i].size(); + if ( (*ait)->allowMore() ) + return 0; + else + return (int)_orList[i].size(); } }