11#ifndef TCLAP_VALUE_ARGUMENT_H
12#define TCLAP_VALUE_ARGUMENT_H
27#if defined(HAVE_SSTREAM)
29#elif defined(HAVE_STRSTREAM)
32#error "Need a stringstream (sstream or strstream) to compile!"
37template<
class T>
class ValueArg;
39namespace VALUE_ARG_HELPER {
81#if defined(HAVE_SSTREAM)
82 std::istringstream is(val);
83#elif defined(HAVE_STRSTREAM)
84 std::istrstream is(val.c_str());
86#error "Need a stringstream (sstream or strstream) to compile!"
92 if ( is.peek() != EOF )
103 if ( valuesRead > 1 )
218 const std::string& name,
219 const std::string& desc,
222 const std::string& typeDesc,
251 const std::string& name,
252 const std::string& desc,
255 const std::string& typeDesc,
282 const std::string& name,
283 const std::string& desc,
312 const std::string& name,
313 const std::string& desc,
328 virtual bool processArg(
int* i, std::vector<std::string>& args);
339 virtual std::string
shortID(
const std::string& val =
"val")
const;
345 virtual std::string
longID(
const std::string& val =
"val")
const;
355 const std::string& name,
356 const std::string& desc,
359 const std::string& typeDesc,
361:
Arg(flag, name, desc, req, true, v),
363 _typeDesc( typeDesc ),
369 const std::string& name,
370 const std::string& desc,
373 const std::string& typeDesc,
376:
Arg(flag, name, desc, req, true, v),
378 _typeDesc( typeDesc ),
386 const std::string& name,
387 const std::string& desc,
392:
Arg(flag, name, desc, req, true, v),
394 _typeDesc( constraint->shortID() ),
395 _constraint( constraint )
400 const std::string& name,
401 const std::string& desc,
407:
Arg(flag, name, desc, req, true, v),
409 _typeDesc( constraint->shortID() ),
410 _constraint( constraint )
431 if ( _hasBlanks( args[*i] ) )
434 std::string flag = args[*i];
436 std::string value =
"";
437 trimFlag( flag, value );
439 if ( argMatches( flag ) )
446 "Couldn't find delimiter for this argument!",
452 if (
static_cast<unsigned int>(*i) < args.size() )
453 _extractValue( args[*i] );
459 _extractValue( value );
496 val +
"'", toString() ) );
500 "More than one valid value parsed from string '" +
501 val +
"'", toString() ) );
503 if ( _constraint != NULL )
504 if ( ! _constraint->check( _value ) )
506 "' does not meet constraint: " +
507 _constraint->description(),
A virtual base class that defines the essential data for all arguments.
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.
The basic labeled argument that parses a value.
virtual std::string longID(const std::string &val="val") const
Specialization of longID.
T _value
The value parsed from the command line.
T & getValue()
Returns the value of the argument.
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
std::string _typeDesc
A human readable description of the type to be parsed.
Constraint< T > * _constraint
A Constraint this Arg must conform to.
ValueArg(const std::string &flag, const std::string &name, const std::string &desc, bool req, T value, const std::string &typeDesc, Visitor *v=NULL)
Labeled ValueArg constructor.
void _extractValue(const std::string &val)
Extracts the value from the string.
virtual std::string shortID(const std::string &val="val") const
Specialization of shortID.
A base class that defines the interface for visitors.