source: libcfa/src/parseconfig.hfa@ 4a1bc44

ADT ast-experimental enum forall-pointer-decay jacob/cs343-translation pthread-emulation qualifiedEnum
Last change on this file since 4a1bc44 was a75cd3d, checked in by Jacob Prud'homme <jafprudhomme@…>, 4 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
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;
[c166f4e]29 this.validate = null_validator;
[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;
[c166f4e]45 this.validate = null_validator;
[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
[3be4078]60exception Missing_Config_Entries {
[dcf792a]61 unsigned int num_missing;
[3be4078]62};
[e1e506b]63
[a75cd3d]64void msg( Missing_Config_Entries * ex );
[e1e506b]65
[dcf792a]66exception Parse_Failure {
67 * char failed_key;
68 * char failed_value;
69};
[6d8e1ab]70
[a75cd3d]71void msg( Parse_Failure * ex );
[6d8e1ab]72
[dcf792a]73exception Validation_Failure {
74 * char failed_key;
75 * char failed_value;
76};
[930609e2]77
[a75cd3d]78void msg( Validation_Failure * ex );
[930609e2]79
80
81// *********************************** main code ***********************************
82
83
[d8db0af]84void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format );
[16f9aca]85
[b1eeb3aa]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
[930609e2]94
95// *********************************** validation ***********************************
96
97
[c58c65a]98forall(T | Relational( T ))
[930609e2]99bool is_nonnegative( T & );
100
[c58c65a]101forall(T | Relational( T ))
[930609e2]102bool is_positive( T & );
103
[c58c65a]104forall(T | Relational( T ))
[930609e2]105bool is_nonpositive( T & );
106
[c58c65a]107forall(T | Relational( T ))
[930609e2]108bool is_negative( T & );
109
110
[16f9aca]111// Local Variables: //
112// mode: c //
113// tab-width: 4 //
114// End: //
Note: See TracBrowser for help on using the repository browser.