Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cmdlineparser.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           cmdlineparser.h  -  description
00003                              -------------------
00004     begin                : Wed Oct 2003
00005     copyright            : (C) 2003 by Peter Haase
00006     email                : p.haase@tuhh.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00034 #ifndef CMDLINE_PARSER_HEADER
00035 #define CMDLINE_PARSER_HEADER
00036 
00037 
00038 #include <string>
00039 #include <map>
00040 #include <stdexcept>
00041 #include <vector>
00042 
00043 
00044 namespace simth
00045 {
00046 
00047 
00071 class CmdLineParser
00072 {
00073 
00074  public:
00075 
00078   CmdLineParser();
00079 
00082   void addOption(const std::string& optName, const std::string& shortOptName, const std::string& description);
00083 
00084   //Not needed yet:
00085   //void addValueOption(...);
00086 
00095   std::vector<std::string> parseAndValidate(int argc, char *argv[]);
00096  
00101   bool isOptionSet(const std::string& shortOptName,const std::string& longOptName) const;  
00102   
00103   //Not needed yet:
00104   //std::string getParsedValue(std::string longOptName,std::string shortOptName) const;
00105      
00108   std::string optionList( ) const;
00109 
00111   class InvalidOption : public std::runtime_error
00112   {
00113     public:
00114       InvalidOption(const std::string& s)
00115           : std::runtime_error(s)
00116     { }
00117   };
00118 
00119  private:
00120   
00127   class CmdLineOption
00128   {
00129 
00130     public:
00131   
00134       CmdLineOption();
00135 
00138       CmdLineOption(const std::string& shortName, const std::string& longName, const std::string& description);
00139   
00141       std::string longName() const {return longName_;} 
00143       std::string shortName() const {return shortName_;}
00145       std::string description() const {return descr_;} 
00148       void setOption(bool flag=true) {isSet_=flag;}
00150       bool isSet() const {return isSet_;}
00151 
00152     private:
00153 
00154       std::string shortName_; 
00155       std::string longName_;
00156       std::string descr_;
00157       bool isSet_; 
00158  
00159   };
00160 
00161 
00162   //Keeps options that take no value: 
00163   std::map<std::string,CmdLineOption> optList;
00164   std::map<std::string,std::string> longOptList;
00165   std::map<std::string,std::string> shortOptList;
00166   
00167   typedef std::map<std::string,CmdLineOption>::const_iterator const_iter;
00168 
00169   //Not needed yet
00170   //Keeps options with possible values
00171   //std::map<std::string,std::string> valOptList;
00172 
00173 };
00174 
00175 
00176 }  //end namespace simth
00177 
00178 #endif
00179 
00180 
00181 
00182 
00183 
00184 

Generated on Mon Apr 24 21:19:19 2006 for simthetic by  doxygen 1.4.1