25#ifndef TCLAP_VALUE_ARG_H
26#define TCLAP_VALUE_ARG_H
105 ValueArg(
const std::string &flag,
const std::string &name,
106 const std::string &desc,
bool req, T value,
107 std::string typeDesc,
Visitor *v =
nullptr);
130 ValueArg(
const std::string &flag,
const std::string &name,
131 const std::string &desc,
bool req, T value,
154 ValueArg(
const std::string &flag,
const std::string &name,
155 const std::string &desc,
bool req, T value,
177 ValueArg(
const std::string &flag,
const std::string &name,
178 const std::string &desc,
bool req, T value,
190 bool processArg(
int *i, std::vector<std::string> &args)
override;
201 operator const T &()
const noexcept {
return getValue(); }
207 [[nodiscard]] std::string
shortID(
208 const std::string &val =
"val")
const override;
214 [[nodiscard]] std::string
longID(
215 const std::string &val =
"val")
const override;
217 void reset()
override;
226 void _extractNextValue(
int *index, std::vector<std::string> &args);
234 const std::string &desc,
bool req, T val,
235 std::string typeDesc,
Visitor *v)
236 :
Arg(flag, name, desc, req, true, v),
239 _typeDesc(std::move(typeDesc)),
240 _constraint(nullptr) {}
244 const std::string &desc,
bool req, T val,
247 :
Arg(flag, name, desc, req, true, v),
250 _typeDesc(std::move(typeDesc)),
251 _constraint(nullptr) {
257 const std::string &desc,
bool req, T val,
259 :
Arg(flag, name, desc, req, true, v),
262 _typeDesc(
Constraint<T>::shortID(constraint)),
263 _constraint(constraint) {}
267 const std::string &desc,
bool req, T val,
270 :
Arg(flag, name, desc, req, true, v),
273 _typeDesc(
Constraint<T>::shortID(constraint)),
274 _constraint(constraint) {
283 if (_hasBlanks(args[*i]))
return false;
285 std::string flag = args[*i];
287 std::string value =
"";
288 trimFlag(flag, value);
289 const bool hasAttachedValue = flag != args[*i];
291 if (!argMatches(flag))
return false;
297 if (this->getDelimiter() !=
' ' && !hasAttachedValue)
301 if (!hasAttachedValue) {
302 _extractNextValue(i, args);
304 _extractValue(value);
315 std::vector<std::string> &args) {
317 if (
static_cast<unsigned int>(*index) < args.size())
318 _extractValue(args[*index]);
350 if (_constraint !=
nullptr && !_constraint->check(_value))
353 +
"' does not meet constraint: " + _constraint->description(),
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.
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.
The basic labeled argument that parses a value.
ValueArg(const ValueArg< T > &rhs)=delete
Prevent accidental copying.
T _default
Used to support the reset() method so that ValueArg can be reset to their constructed value.
bool processArg(int *i, std::vector< std::string > &args) override
Handles the processing of the argument.
ValueArg & operator=(const ValueArg< T > &rhs)=delete
T _value
The value parsed from the command line.
const Constraint< T > * _constraint
A Constraint this Arg must conform to.
void reset() override
Clears the Arg object and allows it to be reused by new command lines.
std::string longID(const std::string &val="val") const override
Specialization of longID.
std::string shortID(const std::string &val="val") const override
Specialization of shortID.
std::string _typeDesc
A human readable description of the type to be parsed.
void _extractValue(const std::string &val)
Extracts the value from the string.
ValueArg(const std::string &flag, const std::string &name, const std::string &desc, bool req, T value, std::string typeDesc, Visitor *v=nullptr)
Labeled ValueArg constructor.
const T & getValue() const noexcept
Returns the value of the argument.
A base class that defines the interface for visitors.
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)