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