| 1 | #ifndef ARGUMENT_READER_H |
| 2 | #define ARGUMENT_READER_H |
| 3 | |
| 4 | #include <vector> |
| 5 | #include <string> |
| 6 | |
| 7 | using namespace std; |
| 8 | |
| 9 | /*! |
| 10 | *\brief Hachti's even more wonderful configuration manager. |
| 11 | * |
| 12 | * This class is designed to do all the work with the parameters passed to |
| 13 | * the main() routine of a program.\n |
| 14 | * Additionally, it is able to interpret configuration files. |
| 15 | * Usage:\n |
| 16 | * - Create an instance. |
| 17 | * - Add Parameters/switches with add_param(). |
| 18 | * - Add Arguments with add_argument(). |
| 19 | * - Call read_args() with your main routine's arguments. |
| 20 | * The vector returned by read_args() contains all error |
| 21 | * messages. When it's empty, everything is fine! |
| 22 | * - Call get_help() if you want nice formatted help output. |
| 23 | * (You want!!!) |
| 24 | * Sould be easy to use..... Enjoy. |
| 25 | */ |
| 26 | class configuration_manager{ |
| 27 | |
| 28 | public: |
| 29 | configuration_manager(string name); |
| 30 | |
| 31 | void add_option_switch (string shortname, |
| 32 | string longname, |
| 33 | string description, |
| 34 | int *status, |
| 35 | bool allow_commandline=true, |
| 36 | bool allow_config_file=true |
| 37 | ); |
| 38 | |
| 39 | void add_option_value (string shortname, |
| 40 | string longname, |
| 41 | string description, |
| 42 | int *status, |
| 43 | bool allow_commandline=true, |
| 44 | bool allow_config_file=true, |
| 45 | string *target=NULL, |
| 46 | string placeholder=string("<string>") |
| 47 | ); |
| 48 | |
| 49 | void add_argument (string longname, |
| 50 | string description, |
| 51 | int *status, |
| 52 | string *target=NULL, |
| 53 | string placeholder=string("<string>") |
| 54 | ); |
| 55 | |
| 56 | vector<string> read_args(int argc, char ** args); |
| 57 | vector<string> read_file(string filename); |
| 58 | |
| 59 | void get_help (vector<string> & target); |
| 60 | vector<string> get_help(); |
| 61 | |
| 62 | private: |
| 63 | /*! |
| 64 | *\brief Container for an option switch |
| 65 | */ |
| 66 | class opt_switch_t{ |
| 67 | public: |
| 68 | opt_switch_t (string shortname, string longname,string description, int * status |
| 69 | string * target=NULL, string placeholder=string("<string>")); |
| 70 | string shortname; |
| 71 | string longname; |
| 72 | int * status; |
| 73 | string * target; |
| 74 | string description; |
| 75 | string placeholder; |
| 76 | }; |
| 77 | /*! |
| 78 | *\brief Container for an option value |
| 79 | */ |
| 80 | class opt_value_t{ |
| 81 | public: |
| 82 | switch_t (string shortname, string longname,string description, int * status |
| 83 | string * target=NULL, string placeholder=string("<string>")); |
| 84 | string shortname; |
| 85 | string longname; |
| 86 | int * status; |
| 87 | string * target; |
| 88 | string description; |
| 89 | string placeholder; |
| 90 | bool allow_conffile; |
| 91 | bool allow_cmdline; |
| 92 | }; |
| 93 | |
| 94 | /*! |
| 95 | *\brief Container for a commandline argument |
| 96 | */ |
| 97 | class cmd_arg_t{ |
| 98 | public: |
| 99 | arg_t (string placeholder,string description, |
| 100 | int * status, string * target); |
| 101 | int * status; |
| 102 | string * target; |
| 103 | string description; |
| 104 | string placeholder; |
| 105 | }; |
| 106 | |
| 107 | vector<opt_switch_t>option_switches; |
| 108 | vector<opt_value_t>option_values; |
| 109 | vector<cmd_arg_t>cmd_args; |
| 110 | string app_name; |
| 111 | |
| 112 | }; // class configuration_manager |
| 113 | |
| 114 | |
| 115 | #endif |