source: libcfa/src/parseconfig.hfa @ e1e506b

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

Added exception for when there are missing config entries

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