source: libcfa/src/parseconfig.hfa @ a75cd3d

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since a75cd3d was a75cd3d, checked in by Jacob Prud'homme <jafprudhomme@…>, 3 years ago

Added message function for exceptions I've created

Also removed constructor declarations from header file, as they are unnecessary

  • Property mode set to 100644
File size: 3.0 KB
Line 
1#pragma once
2
3#include <math.trait.hfa>
4
5
6// *********************************** initial declarations ***********************************
7
8
9enum config_format {
10        TABULAR_CONFIG
11};
12
13struct config_entry {
14        const char * key;
15        void * variable;
16        bool (*parse)( const char *, void * );
17        bool (*validate)( void * );
18};
19
20bool null_validator( void * ) { return true; }
21
22static inline void ?{}( config_entry & this ) {}
23
24forall(T & | { bool parse( const char *, T & ); })
25static inline void ?{}( config_entry & this, const char * key, T & variable ) {
26        this.key      = key;
27        this.variable = (void *)&variable;
28        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
29        this.validate = null_validator;
30}
31
32forall(T & | { bool parse( const char *, T & ); })
33static 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;
38}
39
40forall(T &)
41static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) {
42        this.key      = key;
43        this.variable = (void *)&variable;
44        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
45        this.validate = null_validator;
46}
47
48forall(T &)
49static 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;
54}
55
56
57// *********************************** exceptions ***********************************
58
59
60exception Missing_Config_Entries {
61        unsigned int num_missing;
62};
63
64void msg( Missing_Config_Entries * ex );
65
66exception Parse_Failure {
67        * char failed_key;
68        * char failed_value;
69};
70
71void msg( Parse_Failure * ex );
72
73exception Validation_Failure {
74        * char failed_key;
75        * char failed_value;
76};
77
78void msg( Validation_Failure * ex );
79
80
81// *********************************** main code ***********************************
82
83
84void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format );
85
86bool parse( const char *, const char * & );
87bool parse( const char *, int & );
88bool parse( const char *, unsigned & );
89bool parse( const char *, unsigned long & );
90bool parse( const char *, unsigned long long & );
91bool parse( const char *, float & );
92bool parse( const char *, double & );
93
94
95// *********************************** validation ***********************************
96
97
98forall(T | Relational( T ))
99bool is_nonnegative( T & );
100
101forall(T | Relational( T ))
102bool is_positive( T & );
103
104forall(T | Relational( T ))
105bool is_nonpositive( T & );
106
107forall(T | Relational( T ))
108bool is_negative( T & );
109
110
111// Local Variables: //
112// mode: c //
113// tab-width: 4 //
114// End: //
Note: See TracBrowser for help on using the repository browser.