source: libcfa/src/parseconfig.hfa@ e54654e

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

Added ability to specify optional validation function

  • Property mode set to 100644
File size: 1.9 KB
Line 
1#pragma once
2
3struct config_entry {
4 const char * key;
5 void * variable;
6 bool (*parse)( const char *, void * );
7 bool (*validate)( void * );
8};
9
10static inline void ?{}( config_entry & this ) {}
11
12forall(T & | { bool parse( const char *, T & ); })
13static inline void ?{}( config_entry & this, const char * key, T & variable ) {
14 this.key = key;
15 this.variable = (void *)&variable;
16 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
17 this.validate = 0p;
18}
19
20forall(T & | { bool parse( const char *, T & ); })
21static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) {
22 this.key = key;
23 this.variable = (void *)&variable;
24 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
25 this.validate = (bool (*)(void *))(bool (*)(T &))validate;
26}
27
28forall(T &)
29static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) {
30 this.key = key;
31 this.variable = (void *)&variable;
32 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
33 this.validate = 0p;
34}
35
36forall(T &)
37static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) {
38 this.key = key;
39 this.variable = (void *)&variable;
40 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
41 this.validate = (bool (*)(void *))(bool (*)(T &))validate;
42}
43
44void parse_config( const char * config_file, config_entry entries[], size_t num_entries );
45
46bool parse( const char *, const char * & );
47bool parse( const char *, int & );
48bool parse( const char *, unsigned & );
49bool parse( const char *, unsigned long & );
50bool parse( const char *, unsigned long long & );
51bool parse( const char *, float & );
52bool parse( const char *, double & );
53
54// Local Variables: //
55// mode: c //
56// tab-width: 4 //
57// End: //
Note: See TracBrowser for help on using the repository browser.