conf.hh

Go to the documentation of this file.
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     long 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 
00096     void default_parse(int argc, char *argv[]);
00097 
00099     void check_required() const;
00100 
00102     void print_help(FILE *file = stdout, int exit_value = 0) const;
00103 
00105     std::string help_string() const;
00106 
00108     const Option& operator[](unsigned char short_name) const;
00109 
00111     const Option& operator[](std::string long_name) const;
00112 
00114     typedef std::map<unsigned char, int> ShortMap;
00115 
00117     typedef std::map<std::string, int> LongMap;
00118 
00119     std::string usage_line; 
00120     std::vector<Option> options; 
00121     ShortMap short_map; 
00122     LongMap long_map; 
00123     std::vector<std::string> arguments; 
00124     int longest_name_length; 
00125 
00126   private:
00128     void parse_aux(std::deque<std::string> &argument_queue, bool override);
00129   };
00130 
00131 };
00132 
00133 #endif /* CONF_HH */

Generated on Mon Jan 8 15:51:03 2007 for bit by  doxygen 1.4.6