| 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(). |
| 18 | * - Call read_args() with your main routine's arguments.\ |
| 19 | * The vector returned by read_args() contains all error \ |
| 20 | * messages. When it's empty, everything is fine! |
| 21 | * - Call get_help() if you want nice formatted help output. \ |
| 22 | * (You want!!!) |
| 23 | * Sould be easy to use..... Enjoy. |
| 24 | */ |
| 25 | class argument_reader{ |
| 26 | |
| 27 | public: |
| 28 | argument_reader(string n_name); |
| 29 | |
| 30 | void add_param (string shortname, |
| 31 | string longname, |
| 32 | string description, |
| 33 | int * status, |
| 34 | string * target=NULL, |
| 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: |
| 46 | class parameter{ |
| 47 | public: |
| 48 | parameter (string shortname, string longname,string description, int * status, |
| 49 | string * target=NULL, string placeholder=string("<string>")); |
| 50 | string shortname; |
| 51 | string longname; |
| 52 | int * status; |
| 53 | string * target; |
| 54 | string description; |
| 55 | string placeholder; |
| 56 | }; |
| 57 | |
| 58 | class free_parameter{ |
| 59 | public: |
| 60 | free_parameter (string placeholder,string description, |
| 61 | int * status, string * target); |
| 62 | int * status; |
| 63 | string * target; |
| 64 | string description; |
| 65 | string placeholder; |
| 66 | }; |
| 67 | |
| 68 | vector<parameter>arguments; |
| 69 | vector<free_parameter>free_arguments; |
| 70 | |
| 71 | string progname; |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | #endif |