mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-08 03:40:21 -04:00
fixed xor bug
This commit is contained in:
parent
505936eb05
commit
ee4e8d9783
@ -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<Arg*>& argList ) const
|
||||
argList.push_front( (Arg*)this );
|
||||
}
|
||||
|
||||
inline bool Arg::allowMore()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//END Arg.cpp
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -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<class T>
|
||||
@ -334,7 +338,8 @@ MultiArg<T>::MultiArg(const std::string& flag,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_typeDesc( typeDesc ),
|
||||
_constraint( NULL )
|
||||
_constraint( NULL ),
|
||||
_allowMore(false)
|
||||
{ }
|
||||
|
||||
template<class T>
|
||||
@ -347,7 +352,8 @@ MultiArg<T>::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<T>::MultiArg(const std::string& flag,
|
||||
Visitor* v)
|
||||
: Arg( flag, name, desc, req, true, v ),
|
||||
_typeDesc( constraint->shortID() ),
|
||||
_constraint( constraint )
|
||||
_constraint( constraint ),
|
||||
_allowMore(false)
|
||||
{ }
|
||||
|
||||
template<class T>
|
||||
@ -377,7 +384,8 @@ MultiArg<T>::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<T>::processArg(int *i, std::vector<std::string>& 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<T>::processArg(int *i, std::vector<std::string>& 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<T>::_extractValue( const std::string& val )
|
||||
toString() ) );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool MultiArg<T>::allowMore()
|
||||
{
|
||||
bool am = _allowMore;
|
||||
_allowMore = true;
|
||||
return am;
|
||||
}
|
||||
|
||||
} // namespace TCLAP
|
||||
|
||||
|
@ -227,7 +227,20 @@ bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& 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;
|
||||
}
|
||||
|
||||
|
@ -97,49 +97,14 @@ inline void XorHandler::add( std::vector<Arg*>& 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user