Allows xor args to be optional

This commit is contained in:
Mike Smoot 2011-05-22 12:05:21 -07:00
parent a5105dc72a
commit fdce4f38f0
2 changed files with 16 additions and 11 deletions

View File

@ -224,15 +224,17 @@ private:
* not need to be called. * not need to be called.
* \param a - Argument to be added and xor'd. * \param a - Argument to be added and xor'd.
* \param b - Argument to be added and xor'd. * \param b - Argument to be added and xor'd.
* \param required - Require at least one option (defaults to true)
*/ */
void xorAdd( Arg& a, Arg& b ); void xorAdd( Arg& a, Arg& b, bool required=true );
/** /**
* Add a list of Args that will be xor'd. If this method is used, * Add a list of Args that will be xor'd. If this method is used,
* add does not need to be called. * add does not need to be called.
* \param xors - List of Args to be added and xor'd. * \param xors - List of Args to be added and xor'd.
* \param required - Require at least one option (defaults to true)
*/ */
void xorAdd( std::vector<Arg*>& xors ); void xorAdd( std::vector<Arg*>& xors, bool required=true );
/** /**
* Parses the command line. * Parses the command line.
@ -390,24 +392,25 @@ inline void CmdLine::_constructor()
deleteOnExit(v); deleteOnExit(v);
} }
inline void CmdLine::xorAdd( std::vector<Arg*>& ors ) inline void CmdLine::xorAdd( std::vector<Arg*>& ors, bool required )
{ {
_xorHandler.add( ors ); _xorHandler.add( ors );
for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++) for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++) {
{ if (required) {
(*it)->forceRequired(); (*it)->forceRequired();
(*it)->setRequireLabel( "OR required" ); (*it)->setRequireLabel( "OR required" );
}
add( *it ); add( *it );
} }
} }
inline void CmdLine::xorAdd( Arg& a, Arg& b ) inline void CmdLine::xorAdd( Arg& a, Arg& b, bool required )
{ {
std::vector<Arg*> ors; std::vector<Arg*> ors;
ors.push_back( &a ); ors.push_back( &a );
ors.push_back( &b ); ors.push_back( &b );
xorAdd( ors ); xorAdd( ors, required );
} }
inline void CmdLine::add( Arg& a ) inline void CmdLine::add( Arg& a )

View File

@ -67,15 +67,17 @@ class CmdLineInterface
* not need to be called. * not need to be called.
* \param a - Argument to be added and xor'd. * \param a - Argument to be added and xor'd.
* \param b - Argument to be added and xor'd. * \param b - Argument to be added and xor'd.
* \param required - Require at least one option (defaults to true)
*/ */
virtual void xorAdd( Arg& a, Arg& b )=0; virtual void xorAdd( Arg& a, Arg& b, bool required=true )=0;
/** /**
* Add a list of Args that will be xor'd. If this method is used, * Add a list of Args that will be xor'd. If this method is used,
* add does not need to be called. * add does not need to be called.
* \param xors - List of Args to be added and xor'd. * \param xors - List of Args to be added and xor'd.
* \param required - Require at least one option (defaults to true)
*/ */
virtual void xorAdd( std::vector<Arg*>& xors )=0; virtual void xorAdd( std::vector<Arg*>& xors, bool required=true )=0;
/** /**
* Parses the command line. * Parses the command line.