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 | */ |
26 | class argument_reader{ |
27 | |
28 | public: |
29 | argument_reader(string name); |
30 | |
040533c5 |
31 | void add_param (string shortname, |
ad324d29 |
32 | string longname, |
33 | string description, |
34 | int *status, |
040533c5 |
35 | bool allow_commandline=true, |
36 | bool allow_config_file=true, |
ad324d29 |
37 | string *target=NULL, |
38 | string placeholder=string("<string>") |
39 | ); |
40 | |
41 | vector<string> read_args(int argc, char ** args); |
040533c5 |
42 | vector<string> read_file(string filename); |
ad324d29 |
43 | |
040533c5 |
44 | void get_help (vector<string> & target); |
ad324d29 |
45 | vector<string> get_help(); |
46 | |
47 | void add_argument(string placeholder, string description, int * status, string * target); |
48 | |
49 | private: |
50 | /*! |
51 | *\brief Container for one command line option. |
52 | */ |
53 | class opt_t{ |
54 | public: |
55 | opt_t (string shortname, string longname,string description, int * status, |
56 | string * target=NULL, string placeholder=string("<string>")); |
57 | string shortname; |
58 | string longname; |
59 | int * status; |
60 | string * target; |
61 | string description; |
62 | string placeholder; |
63 | }; |
64 | |
65 | /*! |
66 | *\brief Container for one command line argument. |
67 | */ |
68 | class arg_t{ |
69 | public: |
70 | arg_t (string placeholder,string description, |
71 | int * status, string * target); |
72 | int * status; |
73 | string * target; |
74 | string description; |
75 | string placeholder; |
76 | }; |
77 | vector<opt_t>opt_v; |
78 | vector<arg_t>arg_v; |
79 | string app_name; |
80 | |
81 | }; // class argument_reader |
82 | |
83 | |
84 | #endif |