00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H
00025 #define TCLAP_UNLABELED_VALUE_ARGUMENT_H
00026
00027 #include <string>
00028 #include <vector>
00029
00030 #include <tclap/ValueArg.h>
00031 #include <tclap/OptionalUnlabeledTracker.h>
00032
00033
00034 namespace TCLAP {
00035
00042 template<class T>
00043 class UnlabeledValueArg : public ValueArg<T>
00044 {
00045
00046
00047
00048 #ifndef __BORLANDC__
00049 using ValueArg<T>::_ignoreable;
00050 using ValueArg<T>::_hasBlanks;
00051 using ValueArg<T>::_extractValue;
00052 using ValueArg<T>::_typeDesc;
00053 using ValueArg<T>::_name;
00054 using ValueArg<T>::_description;
00055 using ValueArg<T>::_alreadySet;
00056 using ValueArg<T>::toString;
00057 #endif
00058 public:
00059
00081 UnlabeledValueArg( const std::string& name,
00082 const std::string& desc,
00083 bool req,
00084 T value,
00085 const std::string& typeDesc,
00086 bool ignoreable = false,
00087 Visitor* v = NULL);
00088
00111 UnlabeledValueArg( const std::string& name,
00112 const std::string& desc,
00113 bool req,
00114 T value,
00115 const std::string& typeDesc,
00116 CmdLineInterface& parser,
00117 bool ignoreable = false,
00118 Visitor* v = NULL );
00119
00139 UnlabeledValueArg( const std::string& name,
00140 const std::string& desc,
00141 bool req,
00142 T value,
00143 Constraint<T>* constraint,
00144 bool ignoreable = false,
00145 Visitor* v = NULL );
00146
00147
00168 UnlabeledValueArg( const std::string& name,
00169 const std::string& desc,
00170 bool req,
00171 T value,
00172 Constraint<T>* constraint,
00173 CmdLineInterface& parser,
00174 bool ignoreable = false,
00175 Visitor* v = NULL);
00176
00185 virtual bool processArg(int* i, std::vector<std::string>& args);
00186
00190 virtual std::string shortID(const std::string& val="val") const;
00191
00195 virtual std::string longID(const std::string& val="val") const;
00196
00200 virtual bool operator==(const Arg& a ) const;
00201
00206 virtual void addToList( std::list<Arg*>& argList ) const;
00207
00208 };
00209
00213 template<class T>
00214 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00215 const std::string& desc,
00216 bool req,
00217 T val,
00218 const std::string& typeDesc,
00219 bool ignoreable,
00220 Visitor* v)
00221 : ValueArg<T>("", name, desc, req, val, typeDesc, v)
00222 {
00223 _ignoreable = ignoreable;
00224
00225 OptionalUnlabeledTracker::check(req, toString());
00226
00227 }
00228
00229 template<class T>
00230 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00231 const std::string& desc,
00232 bool req,
00233 T val,
00234 const std::string& typeDesc,
00235 CmdLineInterface& parser,
00236 bool ignoreable,
00237 Visitor* v)
00238 : ValueArg<T>("", name, desc, req, val, typeDesc, v)
00239 {
00240 _ignoreable = ignoreable;
00241 OptionalUnlabeledTracker::check(req, toString());
00242 parser.add( this );
00243 }
00244
00248 template<class T>
00249 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00250 const std::string& desc,
00251 bool req,
00252 T val,
00253 Constraint<T>* constraint,
00254 bool ignoreable,
00255 Visitor* v)
00256 : ValueArg<T>("", name, desc, req, val, constraint, v)
00257 {
00258 _ignoreable = ignoreable;
00259 OptionalUnlabeledTracker::check(req, toString());
00260 }
00261
00262 template<class T>
00263 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00264 const std::string& desc,
00265 bool req,
00266 T val,
00267 Constraint<T>* constraint,
00268 CmdLineInterface& parser,
00269 bool ignoreable,
00270 Visitor* v)
00271 : ValueArg<T>("", name, desc, req, val, constraint, v)
00272 {
00273 _ignoreable = ignoreable;
00274 OptionalUnlabeledTracker::check(req, toString());
00275 parser.add( this );
00276 }
00277
00281 template<class T>
00282 bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
00283 {
00284
00285 if ( _alreadySet )
00286 return false;
00287
00288 if ( _hasBlanks( args[*i] ) )
00289 return false;
00290
00291
00292
00293
00294 if ( _ignoreable && Arg::ignoreRest() )
00295 return false;
00296
00297 if (args[*i].find_first_of( Arg::flagStartString() ) == 0)
00298 return false;
00299
00300
00301
00302
00303 _extractValue( args[*i] );
00304 _alreadySet = true;
00305 return true;
00306 }
00307
00311 template<class T>
00312 std::string UnlabeledValueArg<T>::shortID(const std::string&) const
00313 {
00314 std::string id = "<" + _typeDesc + ">";
00315
00316 return id;
00317 }
00318
00322 template<class T>
00323 std::string UnlabeledValueArg<T>::longID(const std::string&) const
00324 {
00325
00326
00327
00328 std::string id = "<" + _typeDesc + ">";
00329
00330 return id;
00331 }
00332
00336 template<class T>
00337 bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
00338 {
00339 if ( _name == a.getName() || _description == a.getDescription() )
00340 return true;
00341 else
00342 return false;
00343 }
00344
00345 template<class T>
00346 void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
00347 {
00348 argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
00349 }
00350
00351 }
00352 #endif