source: libcfa/src/parseconfig.hfa@ d8db0af

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

Allowed config format to be specified

  • 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
20static inline void ?{}( config_entry & this ) {}
21
[58ebd786]22forall(T & | { bool parse( const char *, T & ); })
[4df8fef5]23static inline void ?{}( config_entry & this, const char * key, T & variable ) {
24 this.key = key;
25 this.variable = (void *)&variable;
[4cc6c7d]26 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
[ad8072c]27 this.validate = (bool (*)(void *))(bool (*)(T &))0p;
[e54654e]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;
[4df8fef5]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;
[4cc6c7d]42 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
[ad8072c]43 this.validate = (bool (*)(void *))(bool (*)(T &))0p;
[e54654e]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;
[4df8fef5]52}
53
[930609e2]54
55// *********************************** exceptions ***********************************
56
57
58EHM_EXCEPTION(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
[d8db0af]69void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format );
[16f9aca]70
[b1eeb3aa]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
[930609e2]79
80// *********************************** validation ***********************************
81
82
[c58c65a]83forall(T | Relational( T ))
[930609e2]84bool is_nonnegative( T & );
85
[c58c65a]86forall(T | Relational( T ))
[930609e2]87bool is_positive( T & );
88
[c58c65a]89forall(T | Relational( T ))
[930609e2]90bool is_nonpositive( T & );
91
[c58c65a]92forall(T | Relational( T ))
[930609e2]93bool is_negative( T & );
94
95
[16f9aca]96// Local Variables: //
97// mode: c //
98// tab-width: 4 //
99// End: //
Note: See TracBrowser for help on using the repository browser.