00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef TCLAP_MULTI_SWITCH_ARG_H
00026 #define TCLAP_MULTI_SWITCH_ARG_H
00027
00028 #include <string>
00029 #include <vector>
00030
00031 #include <tclap/SwitchArg.h>
00032
00033 namespace TCLAP {
00034
00039 class MultiSwitchArg : public SwitchArg
00040 {
00041 protected:
00042
00046 int _value;
00047
00048
00049 public:
00050
00064 MultiSwitchArg(const std::string& flag,
00065 const std::string& name,
00066 const std::string& desc,
00067 int init = 0,
00068 Visitor* v = NULL);
00069
00070
00085 MultiSwitchArg(const std::string& flag,
00086 const std::string& name,
00087 const std::string& desc,
00088 CmdLineInterface& parser,
00089 int init = 0,
00090 Visitor* v = NULL);
00091
00092
00101 virtual bool processArg(int* i, std::vector<std::string>& args);
00102
00106 int getValue();
00107
00111 std::string shortID(const std::string& val) const;
00112
00116 std::string longID(const std::string& val) const;
00117 };
00118
00120
00122 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00123 const std::string& name,
00124 const std::string& desc,
00125 int init,
00126 Visitor* v )
00127 : SwitchArg(flag, name, desc, false, v),
00128 _value( init )
00129 { }
00130
00131 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00132 const std::string& name,
00133 const std::string& desc,
00134 CmdLineInterface& parser,
00135 int init,
00136 Visitor* v )
00137 : SwitchArg(flag, name, desc, false, v),
00138 _value( init )
00139 {
00140 parser.add( this );
00141 }
00142
00143 inline int MultiSwitchArg::getValue() { return _value; }
00144
00145 inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
00146 {
00147 if ( _ignoreable && Arg::ignoreRest() )
00148 return false;
00149
00150 if ( argMatches( args[*i] ))
00151 {
00152
00153 _alreadySet = true;
00154
00155
00156 ++_value;
00157
00158 _checkWithVisitor();
00159
00160 return true;
00161 }
00162 else if ( combinedSwitchesMatch( args[*i] ) )
00163 {
00164
00165 _alreadySet = true;
00166
00167
00168 ++_value;
00169
00170
00171 while ( combinedSwitchesMatch( args[*i] ) )
00172 ++_value;
00173
00174 _checkWithVisitor();
00175
00176 return false;
00177 }
00178 else
00179 return false;
00180 }
00181
00182 std::string MultiSwitchArg::shortID(const std::string& val) const
00183 {
00184 std::string id = Arg::shortID() + " ... ";
00185
00186 return id;
00187 }
00188
00189 std::string MultiSwitchArg::longID(const std::string& val) const
00190 {
00191 std::string id = Arg::longID() + " (accepted multiple times)";
00192
00193 return id;
00194 }
00195
00197
00199
00200 }
00201
00202 #endif