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
Line 
1#pragma once
2
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
18struct config_entry {
19        const char * key;
20        void * variable;
21        bool (*parse)( const char *, void * );
22        bool (*validate)( void * );
23};
24
25static inline void ?{}( config_entry & this ) {}
26
27forall(T & | { bool parse( const char *, T & ); })
28static inline void ?{}( config_entry & this, const char * key, T & variable ) {
29        this.key      = key;
30        this.variable = (void *)&variable;
31        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
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;
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;
47        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
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;
57}
58
59void parse_config( const char * config_file, config_entry entries[], size_t num_entries );
60
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
69// Local Variables: //
70// mode: c //
71// tab-width: 4 //
72// End: //
Note: See TracBrowser for help on using the repository browser.