15 #ifndef TCLAP_SWITCH_ARG_H 16 #define TCLAP_SWITCH_ARG_H 31 class SwitchArg :
public Arg
55 const std::string& name,
56 const std::string& desc,
75 const std::string& name,
76 const std::string& desc,
77 CmdLineInterface& parser,
109 const std::string& name,
110 const std::string& desc,
113 :
Arg(flag, name, desc, false, false, v),
117 inline SwitchArg::SwitchArg(
const std::string& flag,
118 const std::string&
name,
119 const std::string& desc,
120 CmdLineInterface& parser,
123 : Arg(flag, name, desc, false, false, v),
129 inline bool SwitchArg::getValue() {
return _value; }
131 inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches )
134 if ( combinedSwitches[0] != Arg::flagStartString()[0] )
138 if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) ==
139 Arg::nameStartString() )
144 for (
unsigned int i = 1; i < combinedSwitches.length(); i++ )
145 if ( combinedSwitches[i] == _flag[0] )
151 combinedSwitches[i] = Arg::blankChar();
160 inline bool SwitchArg::processArg(
int *i, std::vector<std::string>&
args)
162 if ( _ignoreable && Arg::ignoreRest() )
165 if ( argMatches( args[*i] ) || combinedSwitchesMatch( args[*i] ) )
171 if ( argMatches( args[*i] ) )
174 if ( _alreadySet || ( !ret && combinedSwitchesMatch( args[*i] ) ) )
175 throw(CmdLineParseException(
"Argument already set!", toString()));
179 if ( _value ==
true )
SwitchArg(const std::string &flag, const std::string &name, const std::string &desc, bool def=false, Visitor *v=NULL)
virtual bool processArg(int *i, std::vector< std::string > &args)
bool combinedSwitchesMatch(std::string &combined)
Arg(const std::string &flag, const std::string &name, const std::string &desc, bool req, bool valreq, Visitor *v=NULL)