multi_switch_arg.hpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Ifdefs
00013 *****************************************************************************/
00014 
00015 #ifndef TCLAP_MULTI_SWITCH_ARG_H
00016 #define TCLAP_MULTI_SWITCH_ARG_H
00017 
00018 #include <string>
00019 #include <vector>
00020 
00021 #include "switch_arg.hpp"
00022 
00023 namespace ecl {
00024 
00029 class MultiSwitchArg : public SwitchArg
00030 {
00031         protected:
00032 
00036                 int _value;
00037 
00038 
00039         public:
00040 
00054                 MultiSwitchArg(const std::string& flag,
00055                                 const std::string& name,
00056                                 const std::string& desc,
00057                                 int init = 0,
00058                                 Visitor* v = NULL);
00059 
00060 
00075                 MultiSwitchArg(const std::string& flag,
00076                                 const std::string& name,
00077                                 const std::string& desc,
00078                                 CmdLineInterface& parser,
00079                                 int init = 0,
00080                                 Visitor* v = NULL);
00081 
00082 
00091                 virtual bool processArg(int* i, std::vector<std::string>& args);
00092 
00096                 int getValue();
00097 
00101                 std::string shortID(const std::string& val) const;
00102 
00106                 std::string longID(const std::string& val) const;
00107 };
00108 
00110 //BEGIN MultiSwitchArg.cpp
00112 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00113                                         const std::string& name,
00114                                         const std::string& desc,
00115                                         int init,
00116                                         Visitor* v )
00117 : SwitchArg(flag, name, desc, false, v),
00118 _value( init )
00119 { }
00120 
00121 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00122                                         const std::string& name,
00123                                         const std::string& desc,
00124                                         CmdLineInterface& parser,
00125                                         int init,
00126                                         Visitor* v )
00127 : SwitchArg(flag, name, desc, false, v),
00128 _value( init )
00129 {
00130         parser.add( this );
00131 }
00132 
00133 inline int MultiSwitchArg::getValue() { return _value; }
00134 
00135 inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
00136 {
00137         if ( _ignoreable && Arg::ignoreRest() )
00138                 return false;
00139 
00140         if ( argMatches( args[*i] ))
00141         {
00142                 // so the isSet() method will work
00143                 _alreadySet = true;
00144 
00145                 // Matched argument: increment value.
00146                 ++_value;
00147 
00148                 _checkWithVisitor();
00149 
00150                 return true;
00151         }
00152         else if ( combinedSwitchesMatch( args[*i] ) )
00153         {
00154                 // so the isSet() method will work
00155                 _alreadySet = true;
00156 
00157                 // Matched argument: increment value.
00158                 ++_value;
00159 
00160                 // Check for more in argument and increment value.
00161                 while ( combinedSwitchesMatch( args[*i] ) )
00162                         ++_value;
00163 
00164                 _checkWithVisitor();
00165 
00166                 return false;
00167         }
00168         else
00169                 return false;
00170 }
00171 
00172 inline std::string MultiSwitchArg::shortID(const std::string& val) const
00173 {
00174         std::string id = Arg::shortID() + " ... " + val;
00175 
00176         return id;
00177 }
00178 
00179 inline std::string MultiSwitchArg::longID(const std::string& val) const
00180 {
00181         std::string id = Arg::longID() + "  (accepted multiple times) " + val;
00182 
00183         return id;
00184 }
00185 
00187 //END MultiSwitchArg.cpp
00189 
00190 }; // namespace ecl
00191 
00192 #endif


ecl_command_line
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:37