cmdline_parameters.h

00001 /*
00002  * cmdline_parameters.h
00003  * This file is part of dbPager Classes Library (DCL)
00004  *
00005  * Copyright (c) 2008 Dennis Prochko <wolfsoft@mail.ru>
00006  *
00007  * DCL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation version 3.
00010  *
00011  * DCL is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with DCL; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _CMDLINE_PARAMETERS_H_
00023 #define _CMDLINE_PARAMETERS_H_
00024 
00025 #include <vector>
00026 #include <string>
00027 
00028 #include <dcl/exception.h>
00029 
00030 namespace dbp {
00031 
00033 
00037 class cmdline_parameters_exception: public exception {
00038 public:
00040         cmdline_parameters_exception(const std::string &msg): exception(msg) { }
00041 };
00042 
00044 
00048 class cmdline_parameter {
00049 public:
00051         enum parameter_type {
00054           OPTION,
00057           OPTION_WITH_VALUE,
00059           COMMAND,        
00061           FILENAME
00062         };
00063         char short_name;                        
00064         std::string long_name;          
00065         std::string value_name;         
00066         std::string value;                      
00067         std::string description;        
00068         parameter_type type;            
00069 
00070         cmdline_parameter(): short_name(0), type(FILENAME) { };
00072         explicit cmdline_parameter(char short_name,
00073           const std::string &long_name, const std::string &description,
00074           const std::string &value_name = "",
00075           parameter_type type = OPTION): short_name(short_name),
00076           long_name(long_name), value_name(value_name), description(description),
00077           type(type) { };
00079         explicit cmdline_parameter(parameter_type type): short_name(0),
00080           type(type) { };
00082         explicit cmdline_parameter(const std::string &description,
00083           parameter_type type): short_name(0), description(description),
00084           type(type) { };
00086         bool operator==(const parameter_type p_type) const;
00088         bool operator==(const std::string &name) const;
00089 };
00090 
00091 
00093 
00097 class cmdline_parameters {
00098 public:
00100         typedef std::vector<cmdline_parameter> params;
00102         cmdline_parameters(): _pos(0) { };
00104         /*
00105                 Registers the command line parameter as known one.
00106                 
00107                 \param param the command line parameter
00108         */
00109         void add(const cmdline_parameter &param);
00111 
00121         bool parse(int argc, char* argv[], cmdline_parameter &param);
00123 
00127         params::const_iterator begin() const;
00129 
00133         params::const_iterator end() const;
00134 private:
00135         int _pos;
00136         params _params;
00137 };
00138 
00139 } // namespace
00140 
00141 #endif /*_CMDLINE_PARAMETERS_H_*/
00142 

 
Support This Project
SourceForge.net Logo