25#ifndef TCLAP_MULTI_ARG_H
26#define TCLAP_MULTI_ARG_H
46 using iterator =
typename container_type::iterator;
98 MultiArg(
const std::string &flag,
const std::string &name,
99 const std::string &desc,
bool req, std::string typeDesc,
120 MultiArg(
const std::string &flag,
const std::string &name,
121 const std::string &desc,
bool req, std::string typeDesc,
139 MultiArg(
const std::string &flag,
const std::string &name,
140 const std::string &desc,
bool req,
const Constraint<T> *constraint,
159 MultiArg(
const std::string &flag,
const std::string &name,
160 const std::string &desc,
bool req,
const Constraint<T> *constraint,
171 bool processArg(
int *i, std::vector<std::string> &args)
override;
195 [[nodiscard]] std::string
shortID(
196 const std::string &val =
"val")
const override;
202 [[nodiscard]] std::string
longID(
203 const std::string &val =
"val")
const override;
207 void reset()
override;
216 void _extractNextValue(
int *index, std::vector<std::string> &args);
221 const std::string &desc,
bool req,
222 std::string typeDesc,
Visitor *v)
223 :
Arg(flag, name, desc, req, true, v),
225 _typeDesc(std::move(typeDesc)),
226 _constraint(nullptr),
233 const std::string &desc,
bool req,
236 :
Arg(flag, name, desc, req, true, v),
238 _typeDesc(std::move(typeDesc)),
239 _constraint(nullptr),
250 const std::string &desc,
bool req,
252 :
Arg(flag, name, desc, req, true, v),
254 _typeDesc(
Constraint<T>::shortID(constraint)),
255 _constraint(constraint),
262 const std::string &desc,
bool req,
265 :
Arg(flag, name, desc, req, true, v),
267 _typeDesc(
Constraint<T>::shortID(constraint)),
268 _constraint(constraint),
276 if (_hasBlanks(args[*i]))
return false;
278 std::string flag = args[*i];
279 std::string value =
"";
281 trimFlag(flag, value);
282 const bool hasAttachedValue = flag != args[*i];
284 if (!argMatches(flag))
return false;
286 if (this->getDelimiter() !=
' ' && !hasAttachedValue)
290 if (!hasAttachedValue) {
291 _extractNextValue(i, args);
293 _extractValue(value);
305 std::vector<std::string> &args) {
307 if (
static_cast<unsigned int>(*index) < args.size())
308 _extractValue(args[*index]);
316 static_cast<void>(val);
325 static_cast<void>(val);
326 return Arg::longID(
"<" + _typeDesc +
">") +
" (accepted multiple times)";
336 _values.push_back(tmp);
341 if (_constraint !=
nullptr && !_constraint->check(_values.back()))
344 "' does not meet constraint: " + _constraint->description(),
350 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...
typename DefaultArgTrait< T >::ValueCategory ValueCategory
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.
const_iterator end() const noexcept
Returns the end of the values parsed from the command line.
typename container_type::const_iterator const_iterator
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.
std::string shortID(const std::string &val="val") const override
Returns the a short id string.
std::string longID(const std::string &val="val") const override
Returns the a long id string.
bool processArg(int *i, std::vector< std::string > &args) override
Handles the processing of the argument.
MultiArg & operator=(const MultiArg< T > &rhs)=delete
MultiArg(const std::string &flag, const std::string &name, const std::string &desc, bool req, std::string typeDesc, Visitor *v=nullptr)
Constructor.
const_iterator begin() const noexcept
Returns an iterator over the values parsed from the command line.
bool allowMore() override
Used for MultiArgs to determine whether args can still be set.
void reset() override
Clears the Arg object and allows it to be reused by new command lines.
const std::vector< T > & getValue() const noexcept
Returns a vector of type T containing the values parsed from the command line.
bool _allowMore
Used by MultiArg to decide whether to keep parsing for this arg.
MultiArg(const MultiArg< T > &rhs)=delete
Prevent accidental copying.
typename container_type::iterator iterator
std::vector< T > _values
The list of values parsed from the CmdLine.
const Constraint< T > * _constraint
A constraint that the values of this Arg must conform to.
std::vector< T > container_type
A base class that defines the interface for visitors.
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)