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 using ValueArg<T>::_ignoreable;
00049 using ValueArg<T>::_hasBlanks;
00050 using ValueArg<T>::_extractValue;
00051 using ValueArg<T>::_typeDesc;
00052 using ValueArg<T>::_name;
00053 using ValueArg<T>::_description;
00054 using ValueArg<T>::_alreadySet;
00055 using ValueArg<T>::toString;
00056
00057 public:
00058
00080 UnlabeledValueArg( const std::string& name,
00081 const std::string& desc,
00082 bool req,
00083 T value,
00084 const std::string& typeDesc,
00085 bool ignoreable = false,
00086 Visitor* v = NULL);
00087
00110 UnlabeledValueArg( const std::string& name,
00111 const std::string& desc,
00112 bool req,
00113 T value,
00114 const std::string& typeDesc,
00115 CmdLineInterface& parser,
00116 bool ignoreable = false,
00117 Visitor* v = NULL );
00118
00138 UnlabeledValueArg( const std::string& name,
00139 const std::string& desc,
00140 bool req,
00141 T value,
00142 Constraint<T>* constraint,
00143 bool ignoreable = false,
00144 Visitor* v = NULL );
00145
00146
00167 UnlabeledValueArg( const std::string& name,
00168 const std::string& desc,
00169 bool req,
00170 T value,
00171 Constraint<T>* constraint,
00172 CmdLineInterface& parser,
00173 bool ignoreable = false,
00174 Visitor* v = NULL);
00175
00184 virtual bool processArg(int* i, std::vector<std::string>& args);
00185
00189 virtual std::string shortID(const std::string& val="val") const;
00190
00194 virtual std::string longID(const std::string& val="val") const;
00195
00199 virtual bool operator==(const Arg& a ) const;
00200
00205 virtual void addToList( std::list<Arg*>& argList ) const;
00206
00207 };
00208
00212 template<class T>
00213 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00214 const std::string& desc,
00215 bool req,
00216 T val,
00217 const std::string& typeDesc,
00218 bool ignoreable,
00219 Visitor* v)
00220 : ValueArg<T>("", name, desc, req, val, typeDesc, v)
00221 {
00222 _ignoreable = ignoreable;
00223
00224 OptionalUnlabeledTracker::check(req, toString());
00225
00226 }
00227
00228 template<class T>
00229 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00230 const std::string& desc,
00231 bool req,
00232 T val,
00233 const std::string& typeDesc,
00234 CmdLineInterface& parser,
00235 bool ignoreable,
00236 Visitor* v)
00237 : ValueArg<T>("", name, desc, req, val, typeDesc, v)
00238 {
00239 _ignoreable = ignoreable;
00240 OptionalUnlabeledTracker::check(req, toString());
00241 parser.add( this );
00242 }
00243
00247 template<class T>
00248 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00249 const std::string& desc,
00250 bool req,
00251 T val,
00252 Constraint<T>* constraint,
00253 bool ignoreable,
00254 Visitor* v)
00255 : ValueArg<T>("", name, desc, req, val, constraint, v)
00256 {
00257 _ignoreable = ignoreable;
00258 OptionalUnlabeledTracker::check(req, toString());
00259 }
00260
00261 template<class T>
00262 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
00263 const std::string& desc,
00264 bool req,
00265 T val,
00266 Constraint<T>* constraint,
00267 CmdLineInterface& parser,
00268 bool ignoreable,
00269 Visitor* v)
00270 : ValueArg<T>("", name, desc, req, val, constraint, v)
00271 {
00272 _ignoreable = ignoreable;
00273 OptionalUnlabeledTracker::check(req, toString());
00274 parser.add( this );
00275 }
00276
00280 template<class T>
00281 bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
00282 {
00283
00284 if ( _alreadySet )
00285 return false;
00286
00287 if ( _hasBlanks( args[*i] ) )
00288 return false;
00289
00290
00291
00292 _extractValue( args[*i] );
00293 _alreadySet = true;
00294 return true;
00295 }
00296
00300 template<class T>
00301 std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
00302 {
00303 static_cast<void>(val);
00304 return std::string("<") + _typeDesc + ">";
00305 }
00306
00310 template<class T>
00311 std::string UnlabeledValueArg<T>::longID(const std::string& val) const
00312 {
00313 static_cast<void>(val);
00314
00315
00316
00317
00318 return std::string("<") + _typeDesc + ">";
00319 }
00320
00324 template<class T>
00325 bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
00326 {
00327 if ( _name == a.getName() || _description == a.getDescription() )
00328 return true;
00329 else
00330 return false;
00331 }
00332
00333 template<class T>
00334 void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
00335 {
00336 argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
00337 }
00338
00339 }
00340 #endif