| 1 | #ifndef ARGREAD_H |
| 2 | #define ARGREAD_H |
| 3 | |
| 4 | #include <vector> |
| 5 | #include <string> |
| 6 | |
| 7 | using namespace std; |
| 8 | |
| 9 | #ifndef NULL |
| 10 | #define NULL (void*)0 |
| 11 | #endif |
| 12 | |
| 13 | class argreader{ |
| 14 | public: |
| 15 | argreader(string n_name); |
| 16 | |
| 17 | /*! |
| 18 | *\brief add a parameter to be looked for |
| 19 | *\param shortname A character for the short form. For example the 'h' in -h |
| 20 | *\param longname The double dash longname. For example 'input_file=' in --input_file= or |
| 21 | * 'ignore_errors' in --ignore--errors |
| 22 | *\param description A parameter description. |
| 23 | *\param status Pointer to an integer. Will be set to 1 if arg found. |
| 24 | *\target Pointer to a value should be read. If no value is needed, pass NULL. |
| 25 | *\placeholder A placeholder for the documentation. For example "<filename>" in -f<filename> |
| 26 | */ |
| 27 | void add_param (string shortname, string longname, string description, int * status, |
| 28 | string * target=NULL, string placeholder=string("<string>")); |
| 29 | |
| 30 | /*! |
| 31 | * Read in the args passed to main(). |
| 32 | *\returns empty vector on success or the error messages to be output. |
| 33 | */ |
| 34 | vector<string> read_args(int argc, char ** args); |
| 35 | |
| 36 | |
| 37 | vector<string> & get_free_args(); |
| 38 | |
| 39 | void get_help(vector<string> & ); |
| 40 | vector<string> get_help(); |
| 41 | |
| 42 | void add_free_param(string placeholder, string description, int * status, string * target); |
| 43 | |
| 44 | |
| 45 | |
| 46 | private: |
| 47 | class parameter{ |
| 48 | public: |
| 49 | parameter (string shortname, string longname,string description, int * status, |
| 50 | string * target=NULL, string placeholder=string("<string>")); |
| 51 | string shortname; |
| 52 | string longname; |
| 53 | int * status; |
| 54 | string * target; |
| 55 | string description; |
| 56 | string placeholder; |
| 57 | }; |
| 58 | |
| 59 | class free_parameter{ |
| 60 | public: |
| 61 | free_parameter (string placeholder,string description, |
| 62 | int * status, string * target); |
| 63 | int * status; |
| 64 | string * target; |
| 65 | string description; |
| 66 | string placeholder; |
| 67 | }; |
| 68 | |
| 69 | vector<parameter>arguments; |
| 70 | vector<free_parameter>free_arguments; |
| 71 | |
| 72 | string progname; |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | #endif |