source: libcfa/src/parseconfig.hfa@ 5241ec2

ADT ast-experimental enum forall-pointer-decay jacob/cs343-translation pthread-emulation qualifiedEnum
Last change on this file since 5241ec2 was d322f62, checked in by Jacob Prud'homme <jafprudhomme@…>, 4 years ago

Used more modern built-in EHM

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