source: libcfa/src/parseconfig.hfa @ 247d4ac

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

Removed error for unknown config format

Since we're using an enum, we can only use the options we explicitly provided

  • Property mode set to 100644
File size: 2.8 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
20static inline void ?{}( config_entry & this ) {}
21
22forall(T & | { bool parse( const char *, T & ); })
23static 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
30forall(T & | { bool parse( const char *, T & ); })
31static 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
38forall(T &)
39static 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
46forall(T &)
47static 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
58exception Parse_Failure {};
59
60void ?{}( Parse_Failure & this );
61
62exception Validation_Failure {};
63
64void ?{}( Validation_Failure & this );
65
66
67// *********************************** main code ***********************************
68
69
70void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format );
71
72bool parse( const char *, const char * & );
73bool parse( const char *, int & );
74bool parse( const char *, unsigned & );
75bool parse( const char *, unsigned long & );
76bool parse( const char *, unsigned long long & );
77bool parse( const char *, float & );
78bool parse( const char *, double & );
79
80
81// *********************************** validation ***********************************
82
83
84forall(T | Relational( T ))
85bool is_nonnegative( T & );
86
87forall(T | Relational( T ))
88bool is_positive( T & );
89
90forall(T | Relational( T ))
91bool is_nonpositive( T & );
92
93forall(T | Relational( T ))
94bool is_negative( T & );
95
96
97// Local Variables: //
98// mode: c //
99// tab-width: 4 //
100// End: //
Note: See TracBrowser for help on using the repository browser.