mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-08-04 02:06:29 -04:00
finally fixed bug relating to mutually exclusive combined switched
This commit is contained in:
parent
4ba45abdb9
commit
fc9d87a003
@ -116,6 +116,17 @@ class SwitchArg : public Arg
|
|||||||
|
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Checks to see if we've found the last match in
|
||||||
|
* a combined string.
|
||||||
|
*/
|
||||||
|
bool lastCombined(std::string& combined);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the common processing of processArg.
|
||||||
|
*/
|
||||||
|
void commonProcessing();
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
@ -146,6 +157,15 @@ inline SwitchArg::SwitchArg(const std::string& flag,
|
|||||||
|
|
||||||
inline bool SwitchArg::getValue() { return _value; }
|
inline bool SwitchArg::getValue() { return _value; }
|
||||||
|
|
||||||
|
inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
|
||||||
|
{
|
||||||
|
for ( unsigned int i = 1; i < combinedSwitches.length(); i++ )
|
||||||
|
if ( combinedSwitches[i] != Arg::blankChar() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
||||||
{
|
{
|
||||||
// make sure this is actually a combined switch
|
// make sure this is actually a combined switch
|
||||||
@ -181,31 +201,14 @@ inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void SwitchArg::commonProcessing()
|
||||||
inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
|
|
||||||
{
|
{
|
||||||
if ( _ignoreable && Arg::ignoreRest() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ( argMatches( args[*i] ) || combinedSwitchesMatch( args[*i] ) )
|
|
||||||
{
|
|
||||||
// If we match on a combined switch, then we want to return false
|
|
||||||
// so that other switches in the combination will also have a
|
|
||||||
// chance to match.
|
|
||||||
bool ret = false;
|
|
||||||
if ( argMatches( args[*i] ) )
|
|
||||||
ret = true;
|
|
||||||
|
|
||||||
if ( _alreadySet || ( !ret && combinedSwitchesMatch( args[*i] ) ) )
|
|
||||||
{
|
|
||||||
if ( _xorSet )
|
if ( _xorSet )
|
||||||
throw(CmdLineParseException(
|
throw(CmdLineParseException(
|
||||||
"Mutually exclusive argument already set!",
|
"Mutually exclusive argument already set!", toString()));
|
||||||
toString()));
|
|
||||||
else
|
if ( _alreadySet )
|
||||||
throw(CmdLineParseException("Argument already set!",
|
throw(CmdLineParseException("Argument already set!", toString()));
|
||||||
toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
_alreadySet = true;
|
_alreadySet = true;
|
||||||
|
|
||||||
@ -215,8 +218,35 @@ inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
|
|||||||
_value = true;
|
_value = true;
|
||||||
|
|
||||||
_checkWithVisitor();
|
_checkWithVisitor();
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
inline bool SwitchArg::processArg(int *i, std::vector<std::string>& args)
|
||||||
|
{
|
||||||
|
if ( _ignoreable && Arg::ignoreRest() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// if the whole string matches the flag or name string
|
||||||
|
if ( argMatches( args[*i] ) )
|
||||||
|
{
|
||||||
|
commonProcessing();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// if a substring matches the flag as part of a combination
|
||||||
|
else if ( combinedSwitchesMatch( args[*i] ) )
|
||||||
|
{
|
||||||
|
// check again to ensure we don't misinterpret
|
||||||
|
// this as a MultiSwitchArg
|
||||||
|
if ( combinedSwitchesMatch( args[*i] ) )
|
||||||
|
throw(CmdLineParseException("Argument already set!",
|
||||||
|
toString()));
|
||||||
|
|
||||||
|
commonProcessing();
|
||||||
|
|
||||||
|
// We only want to return true if we've found the last combined
|
||||||
|
// match in the string, otherwise we return true so that other
|
||||||
|
// switches in the combination will have a chance to match.
|
||||||
|
return lastCombined( args[*i] );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -107,6 +107,16 @@ inline int XorHandler::check( const Arg* a )
|
|||||||
_orList[i].end(), a );
|
_orList[i].end(), a );
|
||||||
if ( ait != _orList[i].end() )
|
if ( ait != _orList[i].end() )
|
||||||
{
|
{
|
||||||
|
// first check to see if a mutually exclusive switch
|
||||||
|
// has not already been set
|
||||||
|
for ( ArgVectorIterator it = _orList[i].begin();
|
||||||
|
it != _orList[i].end();
|
||||||
|
it++ )
|
||||||
|
if ( a != (*it) && (*it)->isSet() )
|
||||||
|
throw(CmdLineParseException(
|
||||||
|
"Mutually exclusive argument already set!",
|
||||||
|
(*it)->toString()));
|
||||||
|
|
||||||
// go through and set each arg that is not a
|
// go through and set each arg that is not a
|
||||||
for ( ArgVectorIterator it = _orList[i].begin();
|
for ( ArgVectorIterator it = _orList[i].begin();
|
||||||
it != _orList[i].end();
|
it != _orList[i].end();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user