632a71a2 |
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 wonderful commandline parser. |
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 | * Usage:\n |
15 | * - Create an instance. |
16 | * - Add Parameters/switches with add_param(). |
17 | * - Add Arguments with add_argument(). |
ad324d29 |
18 | * - Call read_args() with your main routine's arguments. |
19 | * The vector returned by read_args() contains all error |
632a71a2 |
20 | * messages. When it's empty, everything is fine! |
ad324d29 |
21 | * - Call get_help() if you want nice formatted help output. |
632a71a2 |
22 | * (You want!!!) |
23 | * Sould be easy to use..... Enjoy. |
24 | */ |
25 | class argument_reader{ |
26 | |
27 | public: |
ad324d29 |
28 | argument_reader(string name); |
632a71a2 |
29 | |
ad324d29 |
30 | void add_param (string shortname, |
31 | string longname, |
32 | string description, |
33 | int *status, |
34 | string *target=NULL, |
632a71a2 |
35 | string placeholder=string("<string>") |
36 | ); |
37 | |
38 | vector<string> read_args(int argc, char ** args); |
39 | |
40 | void get_help(vector<string> & target); |
41 | vector<string> get_help(); |
42 | |
43 | void add_argument(string placeholder, string description, int * status, string * target); |
44 | |
45 | private: |
ad324d29 |
46 | /*! |
47 | *\brief Container for one command line option. |
48 | */ |
49 | class opt_t{ |
632a71a2 |
50 | public: |
ad324d29 |
51 | opt_t (string shortname, string longname,string description, int * status, |
632a71a2 |
52 | string * target=NULL, string placeholder=string("<string>")); |
53 | string shortname; |
54 | string longname; |
55 | int * status; |
56 | string * target; |
57 | string description; |
58 | string placeholder; |
59 | }; |
60 | |
ad324d29 |
61 | /*! |
62 | *\brief Container for one command line argument. |
63 | */ |
64 | class arg_t{ |
632a71a2 |
65 | public: |
ad324d29 |
66 | arg_t (string placeholder,string description, |
632a71a2 |
67 | int * status, string * target); |
68 | int * status; |
69 | string * target; |
70 | string description; |
71 | string placeholder; |
72 | }; |
ad324d29 |
73 | vector<opt_t>opt_v; |
74 | vector<arg_t>arg_v; |
75 | string app_name; |
632a71a2 |
76 | |
ad324d29 |
77 | }; // class argument_reader |
632a71a2 |
78 | |
79 | |
80 | #endif |