00001 #ifndef CONF_HH
00002 #define CONF_HH
00003
00004 #include <vector>
00005 #include <deque>
00006 #include <string>
00007 #include <map>
00008
00033 namespace conf {
00034
00036 struct Option {
00037 Option() : short_name(0), required(false), needs_argument(false),
00038 specified(false) { }
00039 unsigned char short_name;
00040 std::string long_name;
00041 std::string value;
00042 bool required;
00043 bool needs_argument;
00044 bool specified;
00045 std::string help;
00046
00048 std::string name;
00049
00050 int get_int() const;
00051 float get_float() const;
00052 double get_double() const;
00053 const std::string &get_str() const;
00054 const char *get_c_str() const;
00055 };
00056
00061 class Config {
00062 public:
00063
00065 Config();
00066
00068 Config& operator()(std::string usage);
00069
00079 Config& operator()(unsigned char short_name,
00080 std::string long_name,
00081 std::string type = "",
00082 std::string default_value = "",
00083 std::string help = "");
00084
00090 void parse(int argc, char *argv[], bool override = true);
00091
00105 void read(FILE *file, bool override = false);
00106
00108 void check_required() const;
00109
00111 std::string help_string() const;
00112
00114 const Option& operator[](unsigned char short_name) const;
00115
00117 const Option& operator[](std::string long_name) const;
00118
00120 typedef std::map<unsigned char, int> ShortMap;
00121
00123 typedef std::map<std::string, int> LongMap;
00124
00125 std::string usage_line;
00126 std::vector<Option> options;
00127 ShortMap short_map;
00128 LongMap long_map;
00129 std::vector<std::string> arguments;
00130 int longest_name_length;
00131
00132 private:
00134 void parse_aux(std::deque<std::string> &argument_queue, bool override);
00135 };
00136
00137 };
00138
00139 #endif