cmdline.h

Go to the documentation of this file.
00001 /* Command-line parser.
00002  *
00003  * PegSoft command-line parser library (c) 2004 PegSoft
00004  * Contact us at pegsoft@pegsoft.net
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software (the COPYING file); if not, write to the
00017  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
00018  * USA.
00019  *
00020  */
00021 
00027 #ifndef CMDLINE_CMDLINE_H
00028 #define CMDLINE_CMDLINE_H
00029 
00030 /*************************************************************************/
00031 
00032 #include <map>
00033 #include <string>
00034 
00035 /*************************************************************************/
00036 
00038 
00039 namespace cmdline
00040 {
00041 
00042 /*************************************************************************/
00043 
00045 
00052 class CmdLineParser
00053 {
00054     public:
00056         typedef std::multimap<std::string, std::string> ParamsList;
00058         typedef std::map<std::string, std::string> VarsList;
00059 
00061         CmdLineParser() : m_error(), m_progname(), m_params(), m_vars(),
00062                 m_argc(0), m_argv(0), m_envp(0) { }
00064 
00077         CmdLineParser(int argc, char const *const *argv,
00078                 char const *const *envp = NULL): m_error(), m_progname(),
00079                 m_params(), m_vars(), m_argc(argc), m_argv(argv),
00080                 m_envp(envp) {}
00082         CmdLineParser(CmdLineParser const &clp) : m_error(clp.m_error),
00083                 m_progname(clp.m_progname), m_params(clp.m_params),
00084                 m_vars(clp.m_vars), m_argc(clp.m_argc), m_argv(clp.m_argv),
00085                 m_envp(clp.m_envp) { }
00087         virtual ~CmdLineParser() { }
00088 
00090 
00099         virtual bool parse();
00100         
00102         int argc() const { return m_argc; }
00104         char const *const *argv() const { return m_argv; }
00106         char const *const *envp() const { return m_envp; }
00107         
00109 
00114         std::string const &error() const { return m_error; }
00116         char const *c_error() const { return m_error.c_str(); }
00117         
00119 
00124         std::string const program() const { return std::string(m_argv[0]); }
00126         char const *c_program() const { return m_argv[0]; }
00128 
00132         std::string const &progname() const { return m_progname; }
00134         char const *c_progname() const { return m_progname.c_str(); }
00135         
00137 
00142         ParamsList const &params() const { return m_params; }
00143         
00145 
00148         VarsList const &vars() const { return m_vars; }
00149     protected:
00151 
00158         virtual bool eval() { return true; };
00159         
00161         std::string m_error;
00163         std::string m_progname;
00165         ParamsList m_params;
00167         VarsList m_vars;
00168     private:
00169         int m_argc;
00170         char const *const *m_argv;
00171         char const *const *m_envp;
00172 };
00173 
00174 /*************************************************************************/
00175 
00176 } /* namespace cmdline */
00177 
00178 /*************************************************************************/
00179 
00180 #endif /* CMDLINE_CMDLINE_H */

Generated on Fri Apr 18 22:03:27 2008 for Epona API by  doxygen 1.5.3