25#ifndef TCLAP_SWITCH_ARG_H
26#define TCLAP_SWITCH_ARG_H
66 SwitchArg(
const std::string &flag,
const std::string &name,
67 const std::string &desc,
bool def =
false,
Visitor *v =
nullptr);
82 SwitchArg(
const std::string &flag,
const std::string &name,
83 const std::string &desc,
ArgContainer &parser,
bool def =
false,
94 bool processArg(
int *i, std::vector<std::string> &args)
override;
112 operator bool() const noexcept {
return _value; }
114 void reset()
override;
117 bool isCombinedSwitchToken(
const std::string &token)
const;
123 bool lastCombined(std::string &combined);
128 void commonProcessing();
135 const std::string &desc,
bool default_val,
137 :
Arg(flag, name, desc, false, false, v),
139 _default(default_val) {}
144 :
Arg(flag, name, desc, false, false, v),
146 _default(default_val) {
150inline bool SwitchArg::lastCombined(std::string &combinedSwitches) {
156 if (!isCombinedSwitchToken(combinedSwitches))
return false;
158 for (
unsigned int i = 1; i < combinedSwitches.length(); i++) {
174inline bool SwitchArg::isCombinedSwitchToken(
const std::string &token)
const {
181 if (token.find_first_of(this->getDelimiter()) != std::string::npos)
187inline void SwitchArg::commonProcessing() {
189 throw(CmdLineParseException(
"Argument already set!",
toString()));
218 return lastCombined(args[*i]);
Interface that allows adding an Arg to a "container".
virtual ArgContainer & add(Arg &a)=0
Adds an argument.
A virtual base class that defines the essential data for all arguments.
static std::string flagStartString()
void _checkWithVisitor() const
Performs the special handling described by the Visitor.
std::string _setBy
Indicates the value specified to set this flag (like -a or –all).
static constexpr char blankChar() noexcept
The char used as a place holder when SwitchArgs are combined.
bool _alreadySet
Indicates whether the argument has been set.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
bool matchesShortFlag(const std::string &flag) const
virtual bool argMatches(const std::string &s) const
A method that tests whether a string matches this argument.
static std::string nameStartString()
virtual std::string toString() const
Returns a simple string representation of the argument.
Thrown from CmdLine when the arguments on the command line are not properly specified,...
A simple switch argument.
bool _value
The value of the switch.
void reset() override
Clears the Arg object and allows it to be reused by new command lines.
bool processArg(int *i, std::vector< std::string > &args) override
Handles the processing of the argument.
bool getValue() const noexcept
Returns the default value, toggled when the switch occurs.
bool _default
Used to support the reset() method so that ValueArg can be reset to their constructed value.
bool combinedSwitchesMatch(std::string &combined)
Checks a string to see if any of the chars in the string match the flag for this Switch.
SwitchArg(const std::string &flag, const std::string &name, const std::string &desc, bool def=false, Visitor *v=nullptr)
SwitchArg constructor.
A base class that defines the interface for visitors.