Go to the documentation of this file.
26 #ifndef TCLAP_VALUE_ARGUMENT_H
27 #define TCLAP_VALUE_ARGUMENT_H
46 class ValueArg :
public Arg
111 const std::string& name,
112 const std::string& desc,
115 const std::string& typeDesc,
144 const std::string& name,
145 const std::string& desc,
148 const std::string& typeDesc,
175 const std::string& name,
176 const std::string& desc,
205 const std::string& name,
206 const std::string& desc,
221 virtual bool processArg(
int* i, std::vector<std::string>& args);
236 operator const T&()
const {
return getValue(); }
242 virtual std::string
shortID(
const std::string& val =
"val")
const;
248 virtual std::string
longID(
const std::string& val =
"val")
const;
250 virtual void reset() ;
257 ValueArg& operator=(
const ValueArg<T>& rhs);
266 const std::string& name,
267 const std::string& desc,
270 const std::string& typeDesc,
272 :
Arg(flag, name, desc, req, true, v),
275 _typeDesc( typeDesc ),
281 const std::string& name,
282 const std::string& desc,
285 const std::string& typeDesc,
288 :
Arg(flag, name, desc, req, true, v),
291 _typeDesc( typeDesc ),
299 const std::string& name,
300 const std::string& desc,
305 :
Arg(flag, name, desc, req, true, v),
308 _typeDesc(
Constraint<T>::shortID(constraint) ),
309 _constraint( constraint )
314 const std::string& name,
315 const std::string& desc,
321 :
Arg(flag, name, desc, req, true, v),
324 _typeDesc(
Constraint<T>::shortID(constraint) ),
326 _constraint( constraint )
340 if ( _hasBlanks( args[*i] ) )
343 std::string flag = args[*i];
345 std::string value =
"";
346 trimFlag( flag, value );
348 if ( argMatches( flag ) )
354 " already set!", toString()));
367 if (
static_cast<unsigned int>(*i) < args.size() )
368 _extractValue( args[*i] );
374 _extractValue( value );
390 static_cast<void>(val);
400 static_cast<void>(val);
413 if ( _constraint != NULL )
414 if ( ! _constraint->check( _value ) )
415 throw( CmdLineParseException(
"Value '" + val +
416 +
"' does not meet constraint: "
417 + _constraint->description(),
The base class that manages the command line definition and passes along the parsing to the appropria...
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
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.
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,...
virtual std::string shortID(const std::string &val="val") const
Specialization of shortID.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)
T _value
The value parsed from the command line.
static bool ignoreRest()
Whether to ignore the rest.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
A value like argument value type is a value that can be set using operator>>.
Constraint< T > * _constraint
A Constraint this Arg must conform to.
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
std::string error() const
Returns the error text.
A base class that defines the interface for visitors.
T _default
Used to support the reset() method so that ValueArg can be reset to their constructed value.
std::string _typeDesc
A human readable description of the type to be parsed.
static char delimiter()
The delimiter that separates an argument flag/name from the value.
The interface that defines the interaction between the Arg and Constraint.
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
virtual std::string longID(const std::string &val="val") const
Specialization of longID.
const T & getValue() const
Returns the value of the argument.
A virtual base class that defines the essential data for all arguments.
void _extractValue(const std::string &val)
Extracts the value from the string.