| [16f9aca] | 1 | #pragma once
|
|---|
| 2 |
|
|---|
| [c58c65a] | 3 | #include <math.trait.hfa>
|
|---|
| [80ae121] | 4 |
|
|---|
| 5 |
|
|---|
| [930609e2] | 6 | // *********************************** initial declarations ***********************************
|
|---|
| [80ae121] | 7 |
|
|---|
| 8 |
|
|---|
| [d8db0af] | 9 | enum config_format {
|
|---|
| 10 | TABULAR_CONFIG
|
|---|
| 11 | };
|
|---|
| 12 |
|
|---|
| [4df8fef5] | 13 | struct config_entry {
|
|---|
| 14 | const char * key;
|
|---|
| 15 | void * variable;
|
|---|
| [58ebd786] | 16 | bool (*parse)( const char *, void * );
|
|---|
| [e54654e] | 17 | bool (*validate)( void * );
|
|---|
| [4df8fef5] | 18 | };
|
|---|
| 19 |
|
|---|
| [a3f2a3e] | 20 | bool null_validator( void * ) { return true; }
|
|---|
| 21 |
|
|---|
| [4df8fef5] | 22 | static inline void ?{}( config_entry & this ) {}
|
|---|
| 23 |
|
|---|
| [58ebd786] | 24 | forall(T & | { bool parse( const char *, T & ); })
|
|---|
| [4df8fef5] | 25 | static inline void ?{}( config_entry & this, const char * key, T & variable ) {
|
|---|
| 26 | this.key = key;
|
|---|
| 27 | this.variable = (void *)&variable;
|
|---|
| [4cc6c7d] | 28 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
|
|---|
| [c166f4e] | 29 | this.validate = null_validator;
|
|---|
| [e54654e] | 30 | }
|
|---|
| 31 |
|
|---|
| 32 | forall(T & | { bool parse( const char *, T & ); })
|
|---|
| 33 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) {
|
|---|
| 34 | this.key = key;
|
|---|
| 35 | this.variable = (void *)&variable;
|
|---|
| 36 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
|
|---|
| 37 | this.validate = (bool (*)(void *))(bool (*)(T &))validate;
|
|---|
| [4df8fef5] | 38 | }
|
|---|
| 39 |
|
|---|
| 40 | forall(T &)
|
|---|
| 41 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) {
|
|---|
| 42 | this.key = key;
|
|---|
| 43 | this.variable = (void *)&variable;
|
|---|
| [4cc6c7d] | 44 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
|
|---|
| [c166f4e] | 45 | this.validate = null_validator;
|
|---|
| [e54654e] | 46 | }
|
|---|
| 47 |
|
|---|
| 48 | forall(T &)
|
|---|
| 49 | static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) {
|
|---|
| 50 | this.key = key;
|
|---|
| 51 | this.variable = (void *)&variable;
|
|---|
| 52 | this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
|
|---|
| 53 | this.validate = (bool (*)(void *))(bool (*)(T &))validate;
|
|---|
| [4df8fef5] | 54 | }
|
|---|
| 55 |
|
|---|
| [930609e2] | 56 |
|
|---|
| 57 | // *********************************** exceptions ***********************************
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| [3be4078] | 60 | exception Missing_Config_Entries {
|
|---|
| [dcf792a] | 61 | unsigned int num_missing;
|
|---|
| [3be4078] | 62 | };
|
|---|
| [e1e506b] | 63 |
|
|---|
| [a75cd3d] | 64 | void msg( Missing_Config_Entries * ex );
|
|---|
| [e1e506b] | 65 |
|
|---|
| [dcf792a] | 66 | exception Parse_Failure {
|
|---|
| 67 | * char failed_key;
|
|---|
| 68 | * char failed_value;
|
|---|
| 69 | };
|
|---|
| [6d8e1ab] | 70 |
|
|---|
| [a75cd3d] | 71 | void msg( Parse_Failure * ex );
|
|---|
| [6d8e1ab] | 72 |
|
|---|
| [dcf792a] | 73 | exception Validation_Failure {
|
|---|
| 74 | * char failed_key;
|
|---|
| 75 | * char failed_value;
|
|---|
| 76 | };
|
|---|
| [930609e2] | 77 |
|
|---|
| [a75cd3d] | 78 | void msg( Validation_Failure * ex );
|
|---|
| [930609e2] | 79 |
|
|---|
| 80 |
|
|---|
| 81 | // *********************************** main code ***********************************
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| [d8db0af] | 84 | void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format );
|
|---|
| [16f9aca] | 85 |
|
|---|
| [b1eeb3aa] | 86 | bool parse( const char *, const char * & );
|
|---|
| 87 | bool parse( const char *, int & );
|
|---|
| 88 | bool parse( const char *, unsigned & );
|
|---|
| 89 | bool parse( const char *, unsigned long & );
|
|---|
| 90 | bool parse( const char *, unsigned long long & );
|
|---|
| 91 | bool parse( const char *, float & );
|
|---|
| 92 | bool parse( const char *, double & );
|
|---|
| 93 |
|
|---|
| [930609e2] | 94 |
|
|---|
| 95 | // *********************************** validation ***********************************
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| [c58c65a] | 98 | forall(T | Relational( T ))
|
|---|
| [930609e2] | 99 | bool is_nonnegative( T & );
|
|---|
| 100 |
|
|---|
| [c58c65a] | 101 | forall(T | Relational( T ))
|
|---|
| [930609e2] | 102 | bool is_positive( T & );
|
|---|
| 103 |
|
|---|
| [c58c65a] | 104 | forall(T | Relational( T ))
|
|---|
| [930609e2] | 105 | bool is_nonpositive( T & );
|
|---|
| 106 |
|
|---|
| [c58c65a] | 107 | forall(T | Relational( T ))
|
|---|
| [930609e2] | 108 | bool is_negative( T & );
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| [16f9aca] | 111 | // Local Variables: //
|
|---|
| 112 | // mode: c //
|
|---|
| 113 | // tab-width: 4 //
|
|---|
| 114 | // End: //
|
|---|