source: libcfa/src/parseconfig.hfa@ a3f2a3e

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

Simplified validation logic

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[16f9aca]1#pragma once
2
[c58c65a]3#include <math.trait.hfa>
[80ae121]4
5
[930609e2]6// *********************************** initial declarations ***********************************
[80ae121]7
8
[d8db0af]9enum config_format {
10 TABULAR_CONFIG
11};
12
[4df8fef5]13struct 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]20bool null_validator( void * ) { return true; }
21
[4df8fef5]22static inline void ?{}( config_entry & this ) {}
23
[58ebd786]24forall(T & | { bool parse( const char *, T & ); })
[4df8fef5]25static 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;
[a3f2a3e]29 this.validate = null_validation;
[e54654e]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;
[4df8fef5]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;
[4cc6c7d]44 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
[a3f2a3e]45 this.validate = null_validation;
[e54654e]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;
[4df8fef5]54}
55
[930609e2]56
57// *********************************** exceptions ***********************************
58
59
[6d8e1ab]60exception Parse_Failure {};
61
62void ?{}( Parse_Failure & this );
63
64exception Validation_Failure {};
[930609e2]65
[6d8e1ab]66void ?{}( Validation_Failure & this );
[930609e2]67
68
69// *********************************** main code ***********************************
70
71
[d8db0af]72void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format );
[16f9aca]73
[b1eeb3aa]74bool parse( const char *, const char * & );
75bool parse( const char *, int & );
76bool parse( const char *, unsigned & );
77bool parse( const char *, unsigned long & );
78bool parse( const char *, unsigned long long & );
79bool parse( const char *, float & );
80bool parse( const char *, double & );
81
[930609e2]82
83// *********************************** validation ***********************************
84
85
[c58c65a]86forall(T | Relational( T ))
[930609e2]87bool is_nonnegative( T & );
88
[c58c65a]89forall(T | Relational( T ))
[930609e2]90bool is_positive( T & );
91
[c58c65a]92forall(T | Relational( T ))
[930609e2]93bool is_nonpositive( T & );
94
[c58c65a]95forall(T | Relational( T ))
[930609e2]96bool is_negative( T & );
97
98
[16f9aca]99// Local Variables: //
100// mode: c //
101// tab-width: 4 //
102// End: //
Note: See TracBrowser for help on using the repository browser.