source: libcfa/src/parseconfig.hfa @ f62e741

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

Used more modern built-in EHM

  • 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;
[58ebd78]16        bool (*parse)( const char *, void * );
[e54654e]17        bool (*validate)( void * );
[4df8fef5]18};
19
20static inline void ?{}( config_entry & this ) {}
21
[58ebd78]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
[d322f62]58exception Validation_Failure {
[930609e2]59        const char * key;
60        void * variable;
[d322f62]61};
[930609e2]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.