1 | #pragma once |
---|
2 | |
---|
3 | |
---|
4 | // *********************************** exceptions *********************************** |
---|
5 | |
---|
6 | |
---|
7 | EHM_EXCEPTION(Validation_Failure)( |
---|
8 | const char * key; |
---|
9 | void * variable; |
---|
10 | ); |
---|
11 | |
---|
12 | void ?{}( Validation_Failure & this, config_entry & entry ); |
---|
13 | |
---|
14 | |
---|
15 | // *********************************** main code *********************************** |
---|
16 | |
---|
17 | |
---|
18 | struct config_entry { |
---|
19 | const char * key; |
---|
20 | void * variable; |
---|
21 | bool (*parse)( const char *, void * ); |
---|
22 | bool (*validate)( void * ); |
---|
23 | }; |
---|
24 | |
---|
25 | static inline void ?{}( config_entry & this ) {} |
---|
26 | |
---|
27 | forall(T & | { bool parse( const char *, T & ); }) |
---|
28 | static inline void ?{}( config_entry & this, const char * key, T & variable ) { |
---|
29 | this.key = key; |
---|
30 | this.variable = (void *)&variable; |
---|
31 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
32 | this.validate = 0p; |
---|
33 | } |
---|
34 | |
---|
35 | forall(T & | { bool parse( const char *, T & ); }) |
---|
36 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) { |
---|
37 | this.key = key; |
---|
38 | this.variable = (void *)&variable; |
---|
39 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
40 | this.validate = (bool (*)(void *))(bool (*)(T &))validate; |
---|
41 | } |
---|
42 | |
---|
43 | forall(T &) |
---|
44 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) { |
---|
45 | this.key = key; |
---|
46 | this.variable = (void *)&variable; |
---|
47 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
48 | this.validate = 0p; |
---|
49 | } |
---|
50 | |
---|
51 | forall(T &) |
---|
52 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) { |
---|
53 | this.key = key; |
---|
54 | this.variable = (void *)&variable; |
---|
55 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
56 | this.validate = (bool (*)(void *))(bool (*)(T &))validate; |
---|
57 | } |
---|
58 | |
---|
59 | void parse_config( const char * config_file, config_entry entries[], size_t num_entries ); |
---|
60 | |
---|
61 | bool parse( const char *, const char * & ); |
---|
62 | bool parse( const char *, int & ); |
---|
63 | bool parse( const char *, unsigned & ); |
---|
64 | bool parse( const char *, unsigned long & ); |
---|
65 | bool parse( const char *, unsigned long long & ); |
---|
66 | bool parse( const char *, float & ); |
---|
67 | bool parse( const char *, double & ); |
---|
68 | |
---|
69 | // Local Variables: // |
---|
70 | // mode: c // |
---|
71 | // tab-width: 4 // |
---|
72 | // End: // |
---|