cmdline_parameters.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00106
00107
00108
00109 void add(const cmdline_parameter ¶m);
00111
00121 bool parse(int argc, char* argv[], cmdline_parameter ¶m);
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 }
00140
00141 #endif
00142