Go to the documentation of this file.
24 #ifndef TCLAP_SWITCH_ARG_H
25 #define TCLAP_SWITCH_ARG_H
39 class SwitchArg :
public Arg
69 const std::string& name,
70 const std::string& desc,
89 const std::string& name,
90 const std::string& desc,
104 virtual bool processArg(
int* i, std::vector<std::string>& args);
117 virtual void reset();
124 bool lastCombined(std::string& combined);
129 void commonProcessing();
136 const std::string& name,
137 const std::string& desc,
140 :
Arg(flag, name, desc, false, false, v),
141 _value( default_val ),
142 _default( default_val )
146 const std::string& name,
147 const std::string& desc,
148 CmdLineInterface& parser,
151 : Arg(flag, name, desc, false, false, v),
152 _value( default_val ),
153 _default(default_val)
160 inline bool SwitchArg::lastCombined(std::string& combinedSwitches )
162 for (
unsigned int i = 1; i < combinedSwitches.length(); i++ )
172 if ( combinedSwitches.length() > 0 &&
182 if ( combinedSwitches.find_first_of(
Arg::delimiter() ) != std::string::npos )
187 for (
unsigned int i = 1; i < combinedSwitches.length(); i++ )
189 combinedSwitches[i] ==
_flag[0] &&
204 inline void SwitchArg::commonProcessing()
207 throw(CmdLineParseException(
208 "Mutually exclusive argument already set!",
toString()));
211 throw(CmdLineParseException(
"Argument already set!",
toString()));
241 throw(CmdLineParseException(
"Argument already set!",
249 return lastCombined( args[*i] );
The base class that manages the command line definition and passes along the parsing to the appropria...
SwitchArg(const std::string &flag, const std::string &name, const std::string &desc, bool def=false, Visitor *v=NULL)
SwitchArg constructor.
void _checkWithVisitor() const
Performs the special handling described by the Visitor.
bool getValue()
Returns bool, whether or not the switch has been set.
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
static const std::string flagStartString()
virtual std::string toString() const
Returns a simple string representation of the argument.
bool _ignoreable
Whether this argument can be ignored, if desired.
bool _value
The value of the switch.
static bool ignoreRest()
Whether to ignore the rest.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
static char blankChar()
The char used as a place holder when SwitchArgs are combined.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
bool combinedSwitchesMatch(std::string &combined)
Checks a string to see if any of the chars in the string match the flag for this Switch.
static const std::string nameStartString()
A base class that defines the interface for visitors.
bool _xorSet
Indicates that the arg was set as part of an XOR and not on the command line.
virtual bool argMatches(const std::string &s) const
A method that tests whether a string matches this argument.
static char delimiter()
The delimiter that separates an argument flag/name from the value.
bool _alreadySet
Indicates whether the argument has been set.
bool _default
Used to support the reset() method so that ValueArg can be reset to their constructed value.
std::string _flag
The single char flag used to identify the argument.
A virtual base class that defines the essential data for all arguments.