mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-08-04 10:16:41 -04:00
delimiter changes
This commit is contained in:
parent
3bf473496a
commit
bbbadfddc9
@ -43,10 +43,14 @@ namespace TCLAP {
|
||||
class Arg
|
||||
{
|
||||
private:
|
||||
|
||||
static bool _ignoreRest;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
static char _delimiter;
|
||||
|
||||
/**
|
||||
* The single char flag used to identify the argument.
|
||||
* This value (preceded by a dash {-}), can be used to identify
|
||||
@ -98,21 +102,26 @@ class Arg
|
||||
*/
|
||||
Visitor* _visitor;
|
||||
|
||||
/**
|
||||
* Performs the special handling described by the Vistitor.
|
||||
*/
|
||||
void _checkWithVisitor() const;
|
||||
|
||||
/**
|
||||
* Whether this argument can be ignored, if desired.
|
||||
*/
|
||||
bool _ignoreable;
|
||||
|
||||
/**
|
||||
* Performs the special handling described by the Vistitor.
|
||||
*/
|
||||
void _checkWithVisitor() const;
|
||||
|
||||
public:
|
||||
|
||||
static void beginIgnoring() { Arg::_ignoreRest = true; }
|
||||
static bool ignoreRest() { return Arg::_ignoreRest; }
|
||||
|
||||
/**
|
||||
* Sets the delimiter for all arguments.
|
||||
*/
|
||||
static void setDelimiter( char c ) { Arg::_delimiter = c; }
|
||||
|
||||
/**
|
||||
* Primary constructor.
|
||||
*/
|
||||
@ -143,7 +152,7 @@ class Arg
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Arg();
|
||||
virtual ~Arg();
|
||||
|
||||
/**
|
||||
* Processes the argument.
|
||||
@ -224,6 +233,12 @@ class Arg
|
||||
*/
|
||||
virtual string longID( const string& valueId = "val" ) const;
|
||||
|
||||
/**
|
||||
* Trims a value off of the flag.
|
||||
*/
|
||||
virtual void trimFlag( string& flag, string& value ) const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,13 @@ class ArgException
|
||||
};
|
||||
|
||||
string error() { return ( _errorText ); };
|
||||
string argId() { return ( _argId ); };
|
||||
string argId()
|
||||
{
|
||||
if ( _argId == "undefined" )
|
||||
return " ";
|
||||
else
|
||||
return ( "Argument: " + _argId );
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
|
@ -51,10 +51,11 @@ class CmdLine
|
||||
string _version;
|
||||
int _maxLength;
|
||||
int _numRequired;
|
||||
char _delimiter;
|
||||
|
||||
public:
|
||||
CmdLine(char* progName,
|
||||
const string& message,
|
||||
CmdLine(const string& message,
|
||||
const char delimiter = ' ',
|
||||
const string& version = "none" );
|
||||
|
||||
void add( Arg& a );
|
||||
|
@ -41,7 +41,7 @@ class MultiArg : public Arg
|
||||
|
||||
string _typeDesc;
|
||||
|
||||
void _extractValue(int i, vector<string>& args);
|
||||
void _extractValue( const string& val );
|
||||
|
||||
public:
|
||||
|
||||
@ -87,27 +87,40 @@ bool MultiArg<T>::processArg(int *i, vector<string>& args)
|
||||
if ( _ignoreable && Arg::ignoreRest() )
|
||||
return false;
|
||||
|
||||
if ( argMatches( args[*i] ) )
|
||||
string flag = args[*i];
|
||||
string value = "";
|
||||
|
||||
trimFlag( flag, value );
|
||||
|
||||
if ( argMatches( flag ) )
|
||||
{
|
||||
if ( Arg::_delimiter != ' ' && value == "" )
|
||||
throw( ArgException( "Couldn't find delimiter for this argument!",
|
||||
toString() ) );
|
||||
|
||||
if ( value == "" )
|
||||
{
|
||||
(*i)++;
|
||||
if ( *i < args.size() )
|
||||
{
|
||||
_extractValue( *i, args );
|
||||
return true;
|
||||
}
|
||||
if ( (unsigned int)*i < args.size() )
|
||||
_extractValue( args[*i] );
|
||||
else
|
||||
throw( ArgException("Missing a value for this argument!",
|
||||
toString() ) );
|
||||
}
|
||||
else
|
||||
_extractValue( value );
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void MultiArg<T>::_extractValue(int i, vector<string>& args)
|
||||
void MultiArg<T>::_extractValue( const string& val )
|
||||
{
|
||||
T temp;
|
||||
istringstream is(args[i]);
|
||||
istringstream is(val);
|
||||
is >> temp;
|
||||
if ( is.fail() )
|
||||
throw( ArgException("Couldn't read argument value!", toString()));
|
||||
|
@ -83,7 +83,7 @@ class UnlabeledValueArg : public ValueArg<T>
|
||||
* \param i - Pointer the the current argument in the list.
|
||||
* \param args - Mutable list of strings.
|
||||
*/
|
||||
virtual bool processArg(int* i, vector<string>& args );
|
||||
virtual bool processArg(int* i, vector<string>& args);
|
||||
|
||||
/**
|
||||
* Overrides shortID for specific behavior.
|
||||
@ -128,7 +128,7 @@ bool UnlabeledValueArg<T>::processArg(int *i, vector<string>& args)
|
||||
if ( _alreadySet )
|
||||
return false;
|
||||
|
||||
_extractValue( *i, args );
|
||||
_extractValue( args[*i] );
|
||||
_alreadySet = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -63,13 +63,12 @@ class ValueArg : public Arg
|
||||
string _typeDesc;
|
||||
|
||||
/**
|
||||
* Extracts the string at position i from the args list.
|
||||
* Extracts the value from the string.
|
||||
* Attempts to parse string as type T, if this fails an exception
|
||||
* is thrown.
|
||||
* \param i - The index of the argument to extract.
|
||||
* \param args - Mutable list of strings.
|
||||
* \param val - string value to be parsed.
|
||||
*/
|
||||
void _extractValue( int i, vector<string>& args );
|
||||
void _extractValue( const string& val );
|
||||
|
||||
public:
|
||||
|
||||
@ -118,7 +117,7 @@ class ValueArg : public Arg
|
||||
* \param args - Mutable list of strings. Passed
|
||||
* in from main().
|
||||
*/
|
||||
virtual bool processArg(int* i, vector<string>& args );
|
||||
virtual bool processArg(int* i, vector<string>& args);
|
||||
|
||||
/**
|
||||
* Returns the value of the argument.
|
||||
@ -178,26 +177,34 @@ bool ValueArg<T>::processArg(int *i, vector<string>& args)
|
||||
|
||||
string flag = args[*i];
|
||||
|
||||
string value = "";
|
||||
trimFlag( flag, value );
|
||||
|
||||
if ( argMatches( flag ) )
|
||||
{
|
||||
if ( _alreadySet )
|
||||
throw( ArgException("Argument already set!", toString()) );
|
||||
|
||||
(*i)++;
|
||||
if (*i < args.size() )
|
||||
if ( Arg::_delimiter != ' ' && value == "" )
|
||||
throw( ArgException( "Couldn't find delimiter for this argument!",
|
||||
toString() ) );
|
||||
|
||||
if ( value == "" )
|
||||
{
|
||||
_extractValue( *i, args);
|
||||
|
||||
_alreadySet = true;
|
||||
|
||||
_checkWithVisitor();
|
||||
|
||||
return true;
|
||||
}
|
||||
(*i)++;
|
||||
if ( (unsigned int)*i < args.size() )
|
||||
_extractValue( args[*i] );
|
||||
else
|
||||
throw( ArgException("Missing a value for this argument!",
|
||||
toString() ) );
|
||||
}
|
||||
else
|
||||
_extractValue( value );
|
||||
|
||||
_alreadySet = true;
|
||||
_checkWithVisitor();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@ -206,9 +213,9 @@ bool ValueArg<T>::processArg(int *i, vector<string>& args)
|
||||
* Implementation of _extractValue.
|
||||
*/
|
||||
template<class T>
|
||||
void ValueArg<T>::_extractValue(int i, vector<string>& args)
|
||||
void ValueArg<T>::_extractValue( const string& val )
|
||||
{
|
||||
istringstream is(args[i]);
|
||||
istringstream is(val);
|
||||
is >> _value;
|
||||
if ( is.fail() )
|
||||
throw( ArgException("Couldn't read argument value!", toString() ) );
|
||||
@ -232,6 +239,5 @@ string ValueArg<T>::longID(const string& val) const
|
||||
return Arg::longID( _typeDesc );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user