25#ifndef TCLAP_MULTI_ARG_H
26#define TCLAP_MULTI_ARG_H
44 typedef typename container_type::iterator
iterator;
95 MultiArg(
const std::string &flag,
const std::string &name,
96 const std::string &desc,
bool req,
const std::string &typeDesc,
117 MultiArg(
const std::string &flag,
const std::string &name,
118 const std::string &desc,
bool req,
const std::string &typeDesc,
136 MultiArg(
const std::string &flag,
const std::string &name,
137 const std::string &desc,
bool req,
const Constraint<T> *constraint,
156 MultiArg(
const std::string &flag,
const std::string &name,
157 const std::string &desc,
bool req,
const Constraint<T> *constraint,
168 virtual bool processArg(
int *i, std::vector<std::string> &args);
192 virtual std::string
shortID(
const std::string &val =
"val")
const;
198 virtual std::string
longID(
const std::string &val =
"val")
const;
202 virtual void reset();
205 void _extractNextValue(
int *index, std::vector<std::string> &args);
216 const std::string &desc,
bool req,
217 const std::string &typeDesc,
Visitor *v)
218 :
Arg(flag, name, desc, req, true, v),
219 _values(std::vector<T>()),
228 const std::string &desc,
bool req,
231 :
Arg(flag, name, desc, req, true, v),
232 _values(std::vector<T>()),
245 const std::string &desc,
bool req,
247 :
Arg(flag, name, desc, req, true, v),
248 _values(std::vector<T>()),
249 _typeDesc(
Constraint<T>::shortID(constraint)),
250 _constraint(constraint),
257 const std::string &desc,
bool req,
260 :
Arg(flag, name, desc, req, true, v),
261 _values(std::vector<T>()),
262 _typeDesc(
Constraint<T>::shortID(constraint)),
263 _constraint(constraint),
271 if (_hasBlanks(args[*i]))
return false;
273 std::string flag = args[*i];
274 std::string value =
"";
276 trimFlag(flag, value);
277 const bool hasAttachedValue = flag != args[*i];
279 if (!argMatches(flag))
return false;
281 if (this->getDelimiter() !=
' ' && !hasAttachedValue)
283 "Couldn't find delimiter for this argument!", toString()));
285 if (!hasAttachedValue) {
286 _extractNextValue(i, args);
288 _extractValue(value);
300 std::vector<std::string> &args) {
302 if (
static_cast<unsigned int>(*index) < args.size())
303 _extractValue(args[*index]);
314 static_cast<void>(val);
323 static_cast<void>(val);
324 return Arg::longID(
"<" + _typeDesc +
">") +
" (accepted multiple times)";
332 _values.push_back(tmp);
337 if (_constraint != NULL && !_constraint->check(_values.back()))
340 "' does not meet constraint: " + _constraint->description(),
346 bool am = _allowMore;
Interface that allows adding an Arg to a "container".
virtual ArgContainer & add(Arg &a)=0
Adds an argument.
std::string error() const
Returns the error text.
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
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.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
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.
const std::vector< T > & getValue() const
Returns a vector of type T containing the values parsed from the command line.
void _extractValue(const std::string &val)
Extracts the value from the string.
container_type::iterator iterator
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
container_type::const_iterator const_iterator
const_iterator end() const
Returns the end of the values parsed from the command line.
MultiArg(const std::string &flag, const std::string &name, const std::string &desc, bool req, const std::string &typeDesc, Visitor *v=NULL)
Constructor.
const_iterator begin() const
Returns an iterator over the values parsed from the command line.
bool _allowMore
Used by MultiArg to decide whether to keep parsing for this arg.
std::vector< T > _values
The list of values parsed from the CmdLine.
virtual bool allowMore()
Used for MultiArgs to determine whether args can still be set.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
virtual std::string shortID(const std::string &val="val") const
Returns the a short id string.
std::vector< T > container_type
const Constraint< T > * _constraint
A constraint that the values of this Arg must conform to.
virtual std::string longID(const std::string &val="val") const
Returns the a long id string.
A base class that defines the interface for visitors.
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)
A value like argument value type is a value that can be set using operator>>.