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 
00052                 int _default;
00053 
00054         public:
00055 
00069                 MultiSwitchArg(const std::string& flag, 
00070                                 const std::string& name,
00071                                 const std::string& desc,
00072                                 int init = 0,
00073                                 Visitor* v = NULL);
00074 
00075 
00090                 MultiSwitchArg(const std::string& flag, 
00091                                 const std::string& name,
00092                                 const std::string& desc,
00093                                 CmdLineInterface& parser,
00094                                 int init = 0,
00095                                 Visitor* v = NULL);
00096 
00097 
00106                 virtual bool processArg(int* i, std::vector<std::string>& args); 
00107 
00111                 int getValue();
00112 
00116                 std::string shortID(const std::string& val) const;
00117 
00121                 std::string longID(const std::string& val) const;
00122                 
00123                 void reset();
00124 
00125 };
00126 
00128 //BEGIN MultiSwitchArg.cpp
00130 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00131                                         const std::string& name,
00132                                         const std::string& desc,
00133                                         int init,
00134                                         Visitor* v )
00135 : SwitchArg(flag, name, desc, false, v),
00136 _value( init ),
00137 _default( init )
00138 { }
00139 
00140 inline MultiSwitchArg::MultiSwitchArg(const std::string& flag,
00141                                         const std::string& name, 
00142                                         const std::string& desc, 
00143                                         CmdLineInterface& parser,
00144                                         int init,
00145                                         Visitor* v )
00146 : SwitchArg(flag, name, desc, false, v),
00147 _value( init ),
00148 _default( init )
00149 { 
00150         parser.add( this );
00151 }
00152 
00153 inline int MultiSwitchArg::getValue() { return _value; }
00154 
00155 inline bool MultiSwitchArg::processArg(int *i, std::vector<std::string>& args)
00156 {
00157         if ( _ignoreable && Arg::ignoreRest() )
00158                 return false;
00159 
00160         if ( argMatches( args[*i] ))
00161         {
00162                 // so the isSet() method will work
00163                 _alreadySet = true;
00164 
00165                 // Matched argument: increment value.
00166                 ++_value;
00167 
00168                 _checkWithVisitor();
00169 
00170                 return true;
00171         }
00172         else if ( combinedSwitchesMatch( args[*i] ) )
00173         {
00174                 // so the isSet() method will work
00175                 _alreadySet = true;
00176 
00177                 // Matched argument: increment value.
00178                 ++_value;
00179 
00180                 // Check for more in argument and increment value.
00181                 while ( combinedSwitchesMatch( args[*i] ) ) 
00182                         ++_value;
00183 
00184                 _checkWithVisitor();
00185 
00186                 return false;
00187         }
00188         else
00189                 return false;
00190 }
00191 
00192 inline std::string 
00193 MultiSwitchArg::shortID(const std::string& val) const
00194 {
00195         return Arg::shortID(val) + " ... ";
00196 }
00197 
00198 inline std::string 
00199 MultiSwitchArg::longID(const std::string& val) const
00200 {
00201         return Arg::longID(val) + "  (accepted multiple times)";
00202 }
00203 
00204 inline void
00205 MultiSwitchArg::reset()
00206 {
00207         MultiSwitchArg::_value = MultiSwitchArg::_default;
00208 }
00209 
00211 //END MultiSwitchArg.cpp
00213 
00214 } //namespace TCLAP
00215 
00216 #endif


mapstitch
Author(s): Philipp M. Scholl
autogenerated on Mon Oct 6 2014 02:09:53