unlabeled_multi_arg.hpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Ifdefs
00013 *****************************************************************************/
00014 
00015 #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
00016 #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
00017 
00018 #include <string>
00019 #include <vector>
00020 
00021 #include "multi_arg.hpp"
00022 #include "optional_unlabeled_tracker.hpp"
00023 
00024 namespace ecl {
00025 
00031 template<class T>
00032 class UnlabeledMultiArg : public MultiArg<T>
00033 {
00034 
00035         // If compiler has two stage name lookup (as gcc >= 3.4 does)
00036         // this is requried to prevent undef. symbols
00037         using MultiArg<T>::_ignoreable;
00038         using MultiArg<T>::_hasBlanks;
00039         using MultiArg<T>::_extractValue;
00040         using MultiArg<T>::_typeDesc;
00041         using MultiArg<T>::_name;
00042         using MultiArg<T>::_description;
00043         using MultiArg<T>::_alreadySet;
00044         using MultiArg<T>::toString;
00045 
00046         public:
00047 
00065                 UnlabeledMultiArg( const std::string& name,
00066                                            const std::string& desc,
00067                                                    bool req,
00068                                            const std::string& typeDesc,
00069                                                    bool ignoreable = false,
00070                                            Visitor* v = NULL );
00089                 UnlabeledMultiArg( const std::string& name,
00090                                            const std::string& desc,
00091                                                    bool req,
00092                                            const std::string& typeDesc,
00093                                                    CmdLineInterface& parser,
00094                                                    bool ignoreable = false,
00095                                            Visitor* v = NULL );
00096 
00112                 UnlabeledMultiArg( const std::string& name,
00113                                                    const std::string& desc,
00114                                                    bool req,
00115                                                    Constraint<T>* constraint,
00116                                                    bool ignoreable = false,
00117                                                    Visitor* v = NULL );
00118 
00135                 UnlabeledMultiArg( const std::string& name,
00136                                                    const std::string& desc,
00137                                                    bool req,
00138                                                    Constraint<T>* constraint,
00139                                                    CmdLineInterface& parser,
00140                                                    bool ignoreable = false,
00141                                                    Visitor* v = NULL );
00142 
00151                 virtual bool processArg(int* i, std::vector<std::string>& args);
00152 
00157                 virtual std::string shortID(const std::string& val="val") const;
00158 
00163                 virtual std::string longID(const std::string& val="val") const;
00164 
00169                 virtual bool operator==(const Arg& a) const;
00170 
00175                 virtual void addToList( std::list<Arg*>& argList ) const;
00176 };
00177 
00178 template<class T>
00179 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00180                                                         const std::string& desc,
00181                                                                                 bool req,
00182                                                             const std::string& typeDesc,
00183                                                                                 bool ignoreable,
00184                                                             Visitor* v)
00185 : MultiArg<T>("", name, desc,  req, typeDesc, v)
00186 {
00187         _ignoreable = ignoreable;
00188         OptionalUnlabeledTracker::check(true, toString());
00189 }
00190 
00191 template<class T>
00192 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00193                                                         const std::string& desc,
00194                                                                                 bool req,
00195                                                             const std::string& typeDesc,
00196                                                                                 CmdLineInterface& parser,
00197                                                                                 bool ignoreable,
00198                                                             Visitor* v)
00199 : MultiArg<T>("", name, desc,  req, typeDesc, v)
00200 {
00201         _ignoreable = ignoreable;
00202         OptionalUnlabeledTracker::check(true, toString());
00203         parser.add( this );
00204 }
00205 
00206 
00207 template<class T>
00208 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00209                                                         const std::string& desc,
00210                                                                                 bool req,
00211                                                             Constraint<T>* constraint,
00212                                                                                 bool ignoreable,
00213                                                             Visitor* v)
00214 : MultiArg<T>("", name, desc,  req, constraint, v)
00215 {
00216         _ignoreable = ignoreable;
00217         OptionalUnlabeledTracker::check(true, toString());
00218 }
00219 
00220 template<class T>
00221 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
00222                                                         const std::string& desc,
00223                                                                                 bool req,
00224                                                             Constraint<T>* constraint,
00225                                                                                 CmdLineInterface& parser,
00226                                                                                 bool ignoreable,
00227                                                             Visitor* v)
00228 : MultiArg<T>("", name, desc,  req, constraint, v)
00229 {
00230         _ignoreable = ignoreable;
00231         OptionalUnlabeledTracker::check(true, toString());
00232         parser.add( this );
00233 }
00234 
00235 
00236 template<class T>
00237 bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
00238 {
00239 
00240         if ( _hasBlanks( args[*i] ) )
00241                 return false;
00242 
00243         // never ignore an unlabeled multi arg
00244 
00245 
00246         // always take the first value, regardless of the start string
00247         _extractValue( args[(*i)] );
00248 
00249         /*
00250         // continue taking args until we hit the end or a start string
00251         while ( (unsigned int)(*i)+1 < args.size() &&
00252                         args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
00253             args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 )
00254                 _extractValue( args[++(*i)] );
00255         */
00256 
00257         _alreadySet = true;
00258 
00259         return true;
00260 }
00261 
00262 template<class T>
00263 std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
00264 {
00265         std::string id = "<" + _typeDesc + "> ...";
00266 
00267         return id;
00268 }
00269 
00270 template<class T>
00271 std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
00272 {
00273         std::string id = "<" + _typeDesc + ">  (accepted multiple times)";
00274 
00275         return id;
00276 }
00277 
00278 template<class T>
00279 bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
00280 {
00281         if ( _name == a.getName() || _description == a.getDescription() )
00282                 return true;
00283         else
00284                 return false;
00285 }
00286 
00287 template<class T>
00288 void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
00289 {
00290         argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
00291 }
00292 
00293 }; // namespace ecl
00294 
00295 #endif


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:17