00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
00024 #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
00025
00026 #include <string>
00027 #include <vector>
00028
00029 #include <tclap/MultiArg.h>
00030 #include <tclap/OptionalUnlabeledTracker.h>
00031
00032 namespace TCLAP {
00033
00039 template<class T>
00040 class UnlabeledMultiArg : public MultiArg<T>
00041 {
00042
00043
00044
00045 using MultiArg<T>::_ignoreable;
00046 using MultiArg<T>::_hasBlanks;
00047 using MultiArg<T>::_extractValue;
00048 using MultiArg<T>::_typeDesc;
00049 using MultiArg<T>::_name;
00050 using MultiArg<T>::_description;
00051 using MultiArg<T>::_alreadySet;
00052 using MultiArg<T>::toString;
00053
00054 public:
00055
00073 UnlabeledMultiArg( const std::string& name,
00074 const std::string& desc,
00075 bool req,
00076 const std::string& typeDesc,
00077 bool ignoreable = false,
00078 Visitor* v = NULL );
00097 UnlabeledMultiArg( const std::string& name,
00098 const std::string& desc,
00099 bool req,
00100 const std::string& typeDesc,
00101 CmdLineInterface& parser,
00102 bool ignoreable = false,
00103 Visitor* v = NULL );
00104
00120 UnlabeledMultiArg( const std::string& name,
00121 const std::string& desc,
00122 bool req,
00123 Constraint<T>* constraint,
00124 bool ignoreable = false,
00125 Visitor* v = NULL );
00126
00143 UnlabeledMultiArg( const std::string& name,
00144 const std::string& desc,
00145 bool req,
00146 Constraint<T>* constraint,
00147 CmdLineInterface& parser,
00148 bool ignoreable = false,
00149 Visitor* v = NULL );
00150
00159 virtual bool processArg(int* i, std::vector<std::string>& args);
00160
00165 virtual std::string shortID(const std::string& val="val") const;
00166
00171 virtual std::string longID(const std::string& val="val") const;
00172
00177 virtual bool operator==(const Arg& a) const;
00178
00183 virtual void addToList( std::list<Arg*>& argList ) const;
00184 };
00185
00186 template<class T>
00187 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00188 const std::string& desc,
00189 bool req,
00190 const std::string& typeDesc,
00191 bool ignoreable,
00192 Visitor* v)
00193 : MultiArg<T>("", name, desc, req, typeDesc, v)
00194 {
00195 _ignoreable = ignoreable;
00196 OptionalUnlabeledTracker::check(true, toString());
00197 }
00198
00199 template<class T>
00200 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00201 const std::string& desc,
00202 bool req,
00203 const std::string& typeDesc,
00204 CmdLineInterface& parser,
00205 bool ignoreable,
00206 Visitor* v)
00207 : MultiArg<T>("", name, desc, req, typeDesc, v)
00208 {
00209 _ignoreable = ignoreable;
00210 OptionalUnlabeledTracker::check(true, toString());
00211 parser.add( this );
00212 }
00213
00214
00215 template<class T>
00216 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00217 const std::string& desc,
00218 bool req,
00219 Constraint<T>* constraint,
00220 bool ignoreable,
00221 Visitor* v)
00222 : MultiArg<T>("", name, desc, req, constraint, v)
00223 {
00224 _ignoreable = ignoreable;
00225 OptionalUnlabeledTracker::check(true, toString());
00226 }
00227
00228 template<class T>
00229 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00230 const std::string& desc,
00231 bool req,
00232 Constraint<T>* constraint,
00233 CmdLineInterface& parser,
00234 bool ignoreable,
00235 Visitor* v)
00236 : MultiArg<T>("", name, desc, req, constraint, v)
00237 {
00238 _ignoreable = ignoreable;
00239 OptionalUnlabeledTracker::check(true, toString());
00240 parser.add( this );
00241 }
00242
00243
00244 template<class T>
00245 bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
00246 {
00247
00248 if ( _hasBlanks( args[*i] ) )
00249 return false;
00250
00251
00252
00253
00254
00255 _extractValue( args[(*i)] );
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 _alreadySet = true;
00266
00267 return true;
00268 }
00269
00270 template<class T>
00271 std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
00272 {
00273 static_cast<void>(val);
00274 return std::string("<") + _typeDesc + "> ...";
00275 }
00276
00277 template<class T>
00278 std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
00279 {
00280 static_cast<void>(val);
00281 return std::string("<") + _typeDesc + "> (accepted multiple times)";
00282 }
00283
00284 template<class T>
00285 bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
00286 {
00287 if ( _name == a.getName() || _description == a.getDescription() )
00288 return true;
00289 else
00290 return false;
00291 }
00292
00293 template<class T>
00294 void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
00295 {
00296 argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
00297 }
00298
00299 }
00300
00301 #endif