MultiSwitchArg.h

Go to the documentation of this file.
00001 
00002 /****************************************************************************** 
00003 *
00004 *  file:  MultiSwitchArg.h
00005 *
00006 *  Copyright (c) 2003, Michael E. Smoot .
00007 *  Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
00008 *  Copyright (c) 2005, Michael E. Smoot, Daniel Aarno, Erik Zeek.
00009 *  All rights reverved.
00010 *
00011 *  See the file COPYING in the top directory of this distribution for
00012 *  more information.
00013 *
00014 *  THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017 *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019 *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020 *  DEALINGS IN THE SOFTWARE.
00021 *
00022 *****************************************************************************/
00023 
00024 
00025 #ifndef TCLAP_MULTI_SWITCH_ARG_H
00026 #define TCLAP_MULTI_SWITCH_ARG_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <tclap/SwitchArg.h>
00032 
00033 namespace TCLAP {
00034 
00039 class MultiSwitchArg : public SwitchArg
00040 {
00041     protected:
00042 
00046         int _value;
00047 
00048 
00049     public:
00050 
00064         MultiSwitchArg(const std::string& flag, 
00065                 const std::string& name,
00066                 const std::string& desc,
00067                 int init = 0,
00068                 Visitor* v = NULL);
00069 
00070 
00085         MultiSwitchArg(const std::string& flag, 
00086                 const std::string& name,
00087                 const std::string& desc,
00088                 CmdLineInterface& parser,
00089                 int init = 0,
00090                 Visitor* v = NULL);
00091 
00092 
00101         virtual bool processArg(int* i, std::vector<std::string>& args); 
00102 
00106         int getValue();
00107 
00111         std::string shortID(const std::string& val) const;
00112 
00116         std::string longID(const std::string& val) const;
00117 };
00118 
00120 //BEGIN MultiSwitchArg.cpp
00122 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00123                     const std::string& name,
00124                     const std::string& desc,
00125                     int init,
00126                     Visitor* v )
00127 : SwitchArg(flag, name, desc, false, v),
00128 _value( init )
00129 { }
00130 
00131 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00132                     const std::string& name, 
00133                     const std::string& desc, 
00134                     CmdLineInterface& parser,
00135                     int init,
00136                     Visitor* v )
00137 : SwitchArg(flag, name, desc, false, v),
00138 _value( init )
00139 { 
00140     parser.add( this );
00141 }
00142 
00143 inline int MultiSwitchArg::getValue() { return _value; }
00144 
00145 inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
00146 {
00147     if ( _ignoreable && Arg::ignoreRest() )
00148         return false;
00149 
00150     if ( argMatches( args[*i] ))
00151     {
00152         // so the isSet() method will work
00153         _alreadySet = true;
00154 
00155         // Matched argument: increment value.
00156         ++_value;
00157 
00158         _checkWithVisitor();
00159 
00160         return true;
00161     }
00162     else if ( combinedSwitchesMatch( args[*i] ) )
00163     {
00164         // so the isSet() method will work
00165         _alreadySet = true;
00166 
00167         // Matched argument: increment value.
00168         ++_value;
00169 
00170         // Check for more in argument and increment value.
00171         while ( combinedSwitchesMatch( args[*i] ) ) 
00172             ++_value;
00173 
00174         _checkWithVisitor();
00175 
00176         return false;
00177     }
00178     else
00179         return false;
00180 }
00181 
00182 std::string MultiSwitchArg::shortID(const std::string& val) const
00183 {
00184     std::string id = Arg::shortID() + " ... ";
00185 
00186     return id;
00187 }
00188 
00189 std::string MultiSwitchArg::longID(const std::string& val) const
00190 {
00191     std::string id = Arg::longID() + "  (accepted multiple times)";
00192 
00193     return id;
00194 }
00195 
00197 //END MultiSwitchArg.cpp
00199 
00200 } //namespace TCLAP
00201 
00202 #endif

Generated on Thu Dec 14 23:01:53 2006 for tclap by  doxygen 1.5.1