11 #ifndef TCLAP_MULTIPLE_ARGUMENT_H
12 #define TCLAP_MULTIPLE_ARGUMENT_H
27 #if defined(HAVE_SSTREAM)
29 #elif defined(HAVE_STRSTREAM)
32 #error "Need a stringstream (sstream or strstream) to compile!"
37 template<
class T>
class MultiArg;
39 namespace MULTI_ARG_HELPER {
80 #if defined(HAVE_SSTREAM)
81 std::istringstream is(val);
82 #elif defined(HAVE_STRSTREAM)
83 std::istrstream is(val.c_str());
85 #error "Need a stringstream (sstream or strstream) to compile!"
92 if ( is.peek() != EOF )
103 if ( valuesRead > 1 )
205 const std::string& name,
206 const std::string& desc,
208 const std::string& typeDesc,
230 const std::string& name,
231 const std::string& desc,
233 const std::string& typeDesc,
253 const std::string& name,
254 const std::string& desc,
276 const std::string& name,
277 const std::string& desc,
291 virtual bool processArg(
int* i, std::vector<std::string>& args);
303 virtual std::string
shortID(
const std::string& val=
"val")
const;
309 virtual std::string
longID(
const std::string& val=
"val")
const;
323 const std::string& name,
324 const std::string& desc,
326 const std::string& typeDesc,
328 :
Arg( flag, name, desc, req, true, v ),
329 _typeDesc( typeDesc ),
338 const std::string& name,
339 const std::string& desc,
341 const std::string& typeDesc,
344 :
Arg( flag, name, desc, req, true, v ),
345 _typeDesc( typeDesc ),
358 const std::string& name,
359 const std::string& desc,
363 :
Arg( flag, name, desc, req, true, v ),
364 _typeDesc( constraint->shortID() ),
365 _constraint( constraint ),
373 const std::string& name,
374 const std::string& desc,
379 :
Arg( flag, name, desc, req, true, v ),
380 _typeDesc( constraint->shortID() ),
381 _constraint( constraint ),
397 if ( _hasBlanks( args[*i] ) )
400 std::string flag = args[*i];
401 std::string value =
"";
403 trimFlag( flag, value );
405 if ( argMatches( flag ) )
409 "Couldn't find delimiter for this argument!",
416 if (
static_cast<unsigned int>(*i) < args.size() )
417 _extractValue( args[*i] );
423 _extractValue( value );
459 std::string
id =
Arg::longID(_typeDesc) +
" (accepted multiple times)";
473 if ( _values.size() > 1 )
492 "from string '" + val +
"'", toString() ) );
496 "parsed from string '" + val +
"'",
498 if ( _constraint != NULL )
499 if ( ! _constraint->check( _values.back() ) )
501 "' does not meet constraint: " +
502 _constraint->description(),
509 bool am = _allowMore;
A virtual base class that defines the essential data for all arguments.
bool _acceptsMultipleValues
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
static bool ignoreRest()
Whether to ignore the rest.
static char delimiter()
The delimiter that separates an argument flag/name from the value.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
The base class that manages the command line definition and passes along the parsing to the appropria...
virtual void add(Arg &a)=0
Adds an argument to the list of arguments to be parsed.
Thrown from CmdLine when the arguments on the command line are not properly specified,...
The interface that defines the interaction between the Arg and Constraint.
An argument that allows multiple values of type T to be specified.
std::string _typeDesc
The description of type T to be used in the usage.
void _extractValue(const std::string &val)
Extracts the value from the string.
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
MultiArg(const std::string &flag, const std::string &name, const std::string &desc, bool req, const std::string &typeDesc, Visitor *v=NULL)
Constructor.
virtual bool isRequired() const
Once we've matched the first value, then the arg is no longer required.
std::vector< T > _values
The list of values parsed from the CmdLine.
virtual std::string shortID(const std::string &val="val") const
Returns the a short id string.
virtual std::string longID(const std::string &val="val") const
Returns the a long id string.
Constraint< T > * _constraint
A list of constraint on this Arg.
const std::vector< T > & getValue()
Returns a vector of type T containing the values parsed from the command line.
A base class that defines the interface for visitors.