ad324d29 |
1 | #ifndef ARGUMENT_READER_H |
2 | #define ARGUMENT_READER_H |
3 | |
4 | #include <vector> |
5 | #include <string> |
6 | |
7 | using namespace std; |
8 | |
9 | /*! |
040533c5 |
10 | *\brief Hachti's even more wonderful configuration manager. |
ad324d29 |
11 | * |
12 | * This class is designed to do all the work with the parameters passed to |
13 | * the main() routine of a program.\n |
040533c5 |
14 | * Additionally, it is able to interpret configuration files. |
ad324d29 |
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 | */ |
ca5fce3a |
26 | class configuration_manager{ |
ad324d29 |
27 | |
28 | public: |
ca5fce3a |
29 | configuration_manager(string name); |
ad324d29 |
30 | |
ca5fce3a |
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 | ); |
ad324d29 |
48 | |
ca5fce3a |
49 | void add_argument (string longname, |
50 | string description, |
51 | int *status, |
52 | string *target=NULL, |
53 | string placeholder=string("<string>") |
54 | ); |
55 | |
ad324d29 |
56 | vector<string> read_args(int argc, char ** args); |
040533c5 |
57 | vector<string> read_file(string filename); |
ad324d29 |
58 | |
040533c5 |
59 | void get_help (vector<string> & target); |
ad324d29 |
60 | vector<string> get_help(); |
61 | |
ad324d29 |
62 | private: |
63 | /*! |
ca5fce3a |
64 | *\brief Container for an option switch |
ad324d29 |
65 | */ |
ca5fce3a |
66 | class opt_switch_t{ |
ad324d29 |
67 | public: |
ca5fce3a |
68 | opt_switch_t (string shortname, string longname,string description, int * status |
ad324d29 |
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 | }; |
ca5fce3a |
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 | }; |
ad324d29 |
93 | |
94 | /*! |
ca5fce3a |
95 | *\brief Container for a commandline argument |
ad324d29 |
96 | */ |
ca5fce3a |
97 | class cmd_arg_t{ |
ad324d29 |
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 | }; |
ca5fce3a |
106 | |
107 | vector<opt_switch_t>option_switches; |
108 | vector<opt_value_t>option_values; |
109 | vector<cmd_arg_t>cmd_args; |
ad324d29 |
110 | string app_name; |
111 | |
ca5fce3a |
112 | }; // class configuration_manager |
ad324d29 |
113 | |
114 | |
115 | #endif |