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 = NULL);
82 SwitchArg(
const std::string &flag,
const std::string &name,
83 const std::string &desc,
ArgContainer &parser,
bool def =
false,
94 virtual bool processArg(
int *i, std::vector<std::string> &args);
114 virtual void reset();
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) {
151 for (
unsigned int i = 1; i < combinedSwitches.length(); i++)
158 if (!isCombinedSwitchToken(combinedSwitches))
return false;
160 for (
unsigned int i = 1; i < combinedSwitches.length(); i++) {
176inline bool SwitchArg::isCombinedSwitchToken(
const std::string &token)
const {
177 if (token.length() > 0 &&
185 if (token.find_first_of(this->getDelimiter()) != std::string::npos)
191inline void SwitchArg::commonProcessing() {
193 throw(CmdLineParseException(
"Argument already set!",
toString()));
223 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 char blankChar()
The char used as a place holder when SwitchArgs are combined.
void _checkWithVisitor() const
Performs the special handling described by the Visitor.
static const std::string nameStartString()
std::string _setBy
Indicates the value specified to set this flag (like -a or –all).
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.
virtual std::string toString() const
Returns a simple string representation of the argument.
static const std::string flagStartString()
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.
SwitchArg(const std::string &flag, const std::string &name, const std::string &desc, bool def=false, Visitor *v=NULL)
SwitchArg constructor.
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
bool getValue() const
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.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
A base class that defines the interface for visitors.