23 #ifndef DtCmdLine_MULTIPLE_ARGUMENT_H
24 #define DtCmdLine_MULTIPLE_ARGUMENT_H
44 #if defined(HAVE_SSTREAM)
46 #elif defined(HAVE_STRSTREAM)
49 #error "Need a stringstream (sstream or strstream) to compile!"
52 #ifdef DtUSE_UTILITIES_NAMESPACE
53 namespace DtUSE_UTILITIES_NAMESPACE
61 namespace MULTI_ARG_HELPER {
103 #if defined(HAVE_SSTREAM)
104 std::istringstream is(val);
105 #elif defined(HAVE_STRSTREAM)
106 std::istrstream is(val.c_str());
108 #error "Need a stringstream (sstream or strstream) to compile!"
115 if ( is.peek() != EOF )
126 if ( valuesRead > 1 )
129 _values.push_back(temp);
151 std::vector<std::string> &_values;
166 _values.push_back( val );
180 class MultiArg :
public Arg
208 void _extractValue(
const std::string& val );
214 void _checkAllowed(
const std::string& val );
236 const std::string& name,
237 const std::string& desc,
239 const std::string& typeDesc,
261 const std::string& name,
262 const std::string& desc,
264 const std::string& typeDesc,
284 const std::string& name,
285 const std::string& desc,
287 const std::vector<T>& allowed,
307 const std::string& name,
308 const std::string& desc,
310 const std::vector<T>& allowed,
322 virtual bool processArg(
int* i, std::vector<std::string>& args);
328 const std::vector<T>& getValue()
const;
334 virtual std::string shortID(
const std::string& val=
"val")
const;
340 virtual std::string longID(
const std::string& val=
"val")
const;
346 virtual bool isRequired()
const;
362 for (
unsigned int i = 0; i < _allowed.size(); i++ )
365 #if defined(HAVE_SSTREAM)
366 std::ostringstream os;
367 #elif defined(HAVE_STRSTREAM)
370 #error "Need a stringstream (sstream or strstream) to compile!"
375 std::string temp( os.str() );
389 const std::string& name,
390 const std::string& desc,
392 const std::string& typeDesc,
394 :
Arg( flag, name, desc, req, true, v ),
395 _typeDesc( typeDesc )
400 const std::string& name,
401 const std::string& desc,
403 const std::string& typeDesc,
406 :
Arg( flag, name, desc, req, true, v ),
407 _typeDesc( typeDesc )
417 const std::string& name,
418 const std::string& desc,
420 const std::vector<T>& allowed,
422 :
Arg( flag, name, desc, req, true, v ),
430 const std::string& name,
431 const std::string& desc,
433 const std::vector<T>& allowed,
436 :
Arg( flag, name, desc, req, true, v ),
458 if ( _hasBlanks( args[*i] ) )
461 std::string flag = args[*i];
462 std::string value =
"";
464 trimFlag( flag, value );
466 if ( argMatches( flag ) )
470 "Couldn't find delimiter for this argument!",
476 if ( (
unsigned int)*i < args.size() )
477 _extractValue( args[*i] );
483 _extractValue( value );
499 if ( _allowed.size() > 0 )
500 if ( std::find(_allowed.begin(),_allowed.end(),_values.back())
503 "' in allowed list.", toString() ) );
523 std::string
id =
Arg::longID(_typeDesc) +
" (accepted multiple times)";
537 if ( _values.size() > 1 )
556 "from string '" + val +
"'", toString() ) );
560 "parsed from string '" + val +
"'",
562 _checkAllowed( val );
568 #ifdef DtUSE_UTILITIES_NAMESPACE
virtual std::string longID(const std::string &val="val") const
Returns the a long id string.
Definition: cmdMultiArg.h:521
A base class that defines the interface for visitors.
Definition: cmdVisitor.h:41
This file declares classes for VR-Link command line parsing utility.
Error_e
Definition: cmdMultiArg.h:63
std::vector< T > _values
The list of values parsed from the CmdLine.
Definition: cmdMultiArg.h:187
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
Definition: cmdArg.h:422
std::vector< T > _allowed
A list of allowed values.
Definition: cmdMultiArg.h:195
void _checkAllowed(const std::string &val)
Checks to see if parsed value is in allowed list.
Definition: cmdMultiArg.h:497
static char delimiter()
The delimiter that separates an argument flag/name from the value.
Definition: cmdArg.h:184
Thrown from CmdLine when the arguments on the command line are not properly specified, e.g.
Definition: cmdArgException.h:153
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
Definition: cmdArgException.h:131
MultiArg(const std::string &flag, const std::string &name, const std::string &desc, bool req, const std::string &typeDesc, Visitor *v=NULL)
Constructor.
Definition: cmdMultiArg.h:388
Definition: cmdMultiArg.h:63
std::string _typeDesc
The description of type T to be used in the usage.
Definition: cmdMultiArg.h:200
const std::vector< T > & getValue() const
Returns a vector of type T containing the values parsed from the command line.
Definition: cmdMultiArg.h:447
Definition: cmdMultiArg.h:63
static bool ignoreRest()
Whether to ignore the rest.
Definition: cmdArg.h:178
virtual std::string shortID(const std::string &val="val") const
Returns the a short id string.
Definition: cmdMultiArg.h:510
virtual bool isRequired() const
Once we've matched the first value, then the arg is no longer required.
Definition: cmdMultiArg.h:533
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
Definition: cmdArg.h:401
A virtual base class that defines the essential data for all arguments.
Definition: cmdArg.h:48
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
Definition: cmdMultiArg.h:453
virtual void add(Arg &a)=0
Adds an argument to the list of arguments to be parsed.
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition: cmdLineInterface.h:52
An argument that allows multiple values of type T to be specified.
Definition: cmdMultiArg.h:59
void allowedInit()
Common initialization code for constructors with allowed vectors.
Definition: cmdMultiArg.h:360
void _extractValue(const std::string &val)
Extracts the value from the string.
Definition: cmdMultiArg.h:548