source: libcfa/src/parseconfig.hfa @ 80ae121

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

Added exception that will be used to signal failed validation

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[16f9aca]1#pragma once
2
[80ae121]3
4// *********************************** exceptions ***********************************
5
6
7EHM_EXCEPTION(Validation_Failure)(
8        const char * key;
9        void * variable;
10);
11
12void ?{}( Validation_Failure & this, config_entry & entry );
13
14
15// *********************************** main code ***********************************
16
17
[4df8fef5]18struct config_entry {
19        const char * key;
20        void * variable;
[58ebd78]21        bool (*parse)( const char *, void * );
[e54654e]22        bool (*validate)( void * );
[4df8fef5]23};
24
25static inline void ?{}( config_entry & this ) {}
26
[58ebd78]27forall(T & | { bool parse( const char *, T & ); })
[4df8fef5]28static inline void ?{}( config_entry & this, const char * key, T & variable ) {
29        this.key      = key;
30        this.variable = (void *)&variable;
[4cc6c7d]31        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
[e54654e]32        this.validate = 0p;
33}
34
35forall(T & | { bool parse( const char *, T & ); })
36static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) {
37        this.key      = key;
38        this.variable = (void *)&variable;
39        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
40        this.validate = (bool (*)(void *))(bool (*)(T &))validate;
[4df8fef5]41}
42
43forall(T &)
44static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) {
45        this.key      = key;
46        this.variable = (void *)&variable;
[4cc6c7d]47        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
[e54654e]48        this.validate = 0p;
49}
50
51forall(T &)
52static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) {
53        this.key      = key;
54        this.variable = (void *)&variable;
55        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
56        this.validate = (bool (*)(void *))(bool (*)(T &))validate;
[4df8fef5]57}
58
59void parse_config( const char * config_file, config_entry entries[], size_t num_entries );
[16f9aca]60
[b1eeb3aa]61bool parse( const char *, const char * & );
62bool parse( const char *, int & );
63bool parse( const char *, unsigned & );
64bool parse( const char *, unsigned long & );
65bool parse( const char *, unsigned long long & );
66bool parse( const char *, float & );
67bool parse( const char *, double & );
68
[16f9aca]69// Local Variables: //
70// mode: c //
71// tab-width: 4 //
72// End: //
Note: See TracBrowser for help on using the repository browser.