$search
00001 00011 /***************************************************************************** 00012 ** Ifdefs 00013 *****************************************************************************/ 00014 00015 #ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H 00016 #define TCLAP_UNLABELED_VALUE_ARGUMENT_H 00017 00018 #include <string> 00019 #include <vector> 00020 00021 #include "value_arg.hpp" 00022 #include "optional_unlabeled_tracker.hpp" 00023 00024 00025 namespace ecl { 00026 00033 template<class T> 00034 class UnlabeledValueArg : public ValueArg<T> 00035 { 00036 00037 // If compiler has two stage name lookup (as gcc >= 3.4 does) 00038 // this is requried to prevent undef. symbols 00039 using ValueArg<T>::_ignoreable; 00040 using ValueArg<T>::_hasBlanks; 00041 using ValueArg<T>::_extractValue; 00042 using ValueArg<T>::_typeDesc; 00043 using ValueArg<T>::_name; 00044 using ValueArg<T>::_description; 00045 using ValueArg<T>::_alreadySet; 00046 using ValueArg<T>::toString; 00047 00048 public: 00049 00071 UnlabeledValueArg( const std::string& name, 00072 const std::string& desc, 00073 bool req, 00074 T value, 00075 const std::string& typeDesc, 00076 bool ignoreable = false, 00077 Visitor* v = NULL); 00078 00101 UnlabeledValueArg( const std::string& name, 00102 const std::string& desc, 00103 bool req, 00104 T value, 00105 const std::string& typeDesc, 00106 CmdLineInterface& parser, 00107 bool ignoreable = false, 00108 Visitor* v = NULL ); 00109 00129 UnlabeledValueArg( const std::string& name, 00130 const std::string& desc, 00131 bool req, 00132 T value, 00133 Constraint<T>* constraint, 00134 bool ignoreable = false, 00135 Visitor* v = NULL ); 00136 00137 00158 UnlabeledValueArg( const std::string& name, 00159 const std::string& desc, 00160 bool req, 00161 T value, 00162 Constraint<T>* constraint, 00163 CmdLineInterface& parser, 00164 bool ignoreable = false, 00165 Visitor* v = NULL); 00166 00175 virtual bool processArg(int* i, std::vector<std::string>& args); 00176 00180 virtual std::string shortID(const std::string& val="val") const; 00181 00185 virtual std::string longID(const std::string& val="val") const; 00186 00190 virtual bool operator==(const Arg& a ) const; 00191 00196 virtual void addToList( std::list<Arg*>& argList ) const; 00197 00198 }; 00199 00203 template<class T> 00204 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 00205 const std::string& desc, 00206 bool req, 00207 T value, 00208 const std::string& typeDesc, 00209 bool ignoreable, 00210 Visitor* v) 00211 : ValueArg<T>("", name, desc, req, value, typeDesc, v) 00212 { 00213 _ignoreable = ignoreable; 00214 00215 OptionalUnlabeledTracker::check(req, toString()); 00216 00217 } 00218 00219 template<class T> 00220 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 00221 const std::string& desc, 00222 bool req, 00223 T value, 00224 const std::string& typeDesc, 00225 CmdLineInterface& parser, 00226 bool ignoreable, 00227 Visitor* v) 00228 : ValueArg<T>("", name, desc, req, value, typeDesc, v) 00229 { 00230 _ignoreable = ignoreable; 00231 OptionalUnlabeledTracker::check(req, toString()); 00232 parser.add( this ); 00233 } 00234 00238 template<class T> 00239 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 00240 const std::string& desc, 00241 bool req, 00242 T value, 00243 Constraint<T>* constraint, 00244 bool ignoreable, 00245 Visitor* v) 00246 : ValueArg<T>("", name, desc, req, value, constraint, v) 00247 { 00248 _ignoreable = ignoreable; 00249 OptionalUnlabeledTracker::check(req, toString()); 00250 } 00251 00252 template<class T> 00253 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 00254 const std::string& desc, 00255 bool req, 00256 T value, 00257 Constraint<T>* constraint, 00258 CmdLineInterface& parser, 00259 bool ignoreable, 00260 Visitor* v) 00261 : ValueArg<T>("", name, desc, req, value, constraint, v) 00262 { 00263 _ignoreable = ignoreable; 00264 OptionalUnlabeledTracker::check(req, toString()); 00265 parser.add( this ); 00266 } 00267 00271 template<class T> 00272 bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args) 00273 { 00274 00275 if ( _alreadySet ) 00276 return false; 00277 00278 if ( _hasBlanks( args[*i] ) ) 00279 return false; 00280 00281 // never ignore an unlabeled arg 00282 00283 _extractValue( args[*i] ); 00284 _alreadySet = true; 00285 return true; 00286 } 00287 00291 template<class T> 00292 std::string UnlabeledValueArg<T>::shortID(const std::string& val) const 00293 { 00294 std::string id = "<" + _typeDesc + ">"; 00295 00296 return id; 00297 } 00298 00302 template<class T> 00303 std::string UnlabeledValueArg<T>::longID(const std::string& val) const 00304 { 00305 // Ideally we would like to be able to use RTTI to return the name 00306 // of the type required for this argument. However, g++ at least, 00307 // doesn't appear to return terribly useful "names" of the types. 00308 std::string id = "<" + _typeDesc + ">"; 00309 00310 return id; 00311 } 00312 00316 template<class T> 00317 bool UnlabeledValueArg<T>::operator==(const Arg& a ) const 00318 { 00319 if ( _name == a.getName() || _description == a.getDescription() ) 00320 return true; 00321 else 00322 return false; 00323 } 00324 00325 template<class T> 00326 void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const 00327 { 00328 argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) ); 00329 } 00330 00331 }; // namespace ecl 00332 00333 #endif