1 | #pragma once |
---|
2 | |
---|
3 | struct cfa_option { |
---|
4 | char short_name; |
---|
5 | const char * long_name; |
---|
6 | const char * help; |
---|
7 | void * variable; |
---|
8 | bool (*parse)(const char *, void * ); |
---|
9 | }; |
---|
10 | |
---|
11 | extern cfa_option last_option; |
---|
12 | |
---|
13 | static inline void ?{}( cfa_option & this ) {} |
---|
14 | |
---|
15 | forall(dtype T | { bool parse(const char *, T & ); }) |
---|
16 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) { |
---|
17 | this.short_name = short_name; |
---|
18 | this.long_name = long_name; |
---|
19 | this.help = help; |
---|
20 | this.variable = (void*)&variable; |
---|
21 | this.parse = (bool (*)(const char *, void * ))parse; |
---|
22 | } |
---|
23 | |
---|
24 | forall(dtype T) |
---|
25 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) { |
---|
26 | this.short_name = short_name; |
---|
27 | this.long_name = long_name; |
---|
28 | this.help = help; |
---|
29 | this.variable = (void*)&variable; |
---|
30 | this.parse = (bool (*)(const char *, void * ))parse; |
---|
31 | } |
---|
32 | |
---|
33 | void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left ); |
---|
34 | |
---|
35 | bool parse_yesno (const char *, bool & ); |
---|
36 | bool parse_settrue (const char *, bool & ); |
---|
37 | bool parse_setfalse(const char *, bool & ); |
---|
38 | |
---|
39 | bool parse(const char *, const char * & ); |
---|
40 | bool parse(const char *, unsigned & ); |
---|
41 | bool parse(const char *, size_t & ); |
---|
42 | bool parse(const char *, int & ); |
---|