1 | #pragma once |
---|
2 | |
---|
3 | #include <math.trait.hfa> |
---|
4 | |
---|
5 | |
---|
6 | // *********************************** initial declarations *********************************** |
---|
7 | |
---|
8 | |
---|
9 | enum config_format { |
---|
10 | TABULAR_CONFIG |
---|
11 | }; |
---|
12 | |
---|
13 | struct config_entry { |
---|
14 | const char * key; |
---|
15 | void * variable; |
---|
16 | bool (*parse)( const char *, void * ); |
---|
17 | bool (*validate)( void * ); |
---|
18 | }; |
---|
19 | |
---|
20 | static inline void ?{}( config_entry & this ) {} |
---|
21 | |
---|
22 | forall(T & | { bool parse( const char *, T & ); }) |
---|
23 | static inline void ?{}( config_entry & this, const char * key, T & variable ) { |
---|
24 | this.key = key; |
---|
25 | this.variable = (void *)&variable; |
---|
26 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
27 | this.validate = (bool (*)(void *))(bool (*)(T &))0p; |
---|
28 | } |
---|
29 | |
---|
30 | forall(T & | { bool parse( const char *, T & ); }) |
---|
31 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) { |
---|
32 | this.key = key; |
---|
33 | this.variable = (void *)&variable; |
---|
34 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
35 | this.validate = (bool (*)(void *))(bool (*)(T &))validate; |
---|
36 | } |
---|
37 | |
---|
38 | forall(T &) |
---|
39 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) { |
---|
40 | this.key = key; |
---|
41 | this.variable = (void *)&variable; |
---|
42 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
43 | this.validate = (bool (*)(void *))(bool (*)(T &))0p; |
---|
44 | } |
---|
45 | |
---|
46 | forall(T &) |
---|
47 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) { |
---|
48 | this.key = key; |
---|
49 | this.variable = (void *)&variable; |
---|
50 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; |
---|
51 | this.validate = (bool (*)(void *))(bool (*)(T &))validate; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | // *********************************** exceptions *********************************** |
---|
56 | |
---|
57 | |
---|
58 | EHM_EXCEPTION(Validation_Failure)( |
---|
59 | const char * key; |
---|
60 | void * variable; |
---|
61 | ); |
---|
62 | |
---|
63 | void ?{}( Validation_Failure & this, config_entry & entry ); |
---|
64 | |
---|
65 | |
---|
66 | // *********************************** main code *********************************** |
---|
67 | |
---|
68 | |
---|
69 | void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format ); |
---|
70 | |
---|
71 | bool parse( const char *, const char * & ); |
---|
72 | bool parse( const char *, int & ); |
---|
73 | bool parse( const char *, unsigned & ); |
---|
74 | bool parse( const char *, unsigned long & ); |
---|
75 | bool parse( const char *, unsigned long long & ); |
---|
76 | bool parse( const char *, float & ); |
---|
77 | bool parse( const char *, double & ); |
---|
78 | |
---|
79 | |
---|
80 | // *********************************** validation *********************************** |
---|
81 | |
---|
82 | |
---|
83 | forall(T | Relational( T )) |
---|
84 | bool is_nonnegative( T & ); |
---|
85 | |
---|
86 | forall(T | Relational( T )) |
---|
87 | bool is_positive( T & ); |
---|
88 | |
---|
89 | forall(T | Relational( T )) |
---|
90 | bool is_nonpositive( T & ); |
---|
91 | |
---|
92 | forall(T | Relational( T )) |
---|
93 | bool is_negative( T & ); |
---|
94 | |
---|
95 | |
---|
96 | // Local Variables: // |
---|
97 | // mode: c // |
---|
98 | // tab-width: 4 // |
---|
99 | // End: // |
---|