source: libcfa/src/parseconfig.hfa @ d0fcc82

ADTast-experimentalpthread-emulation
Last change on this file since d0fcc82 was a3cadfc, checked in by Jacob Prud'homme <jafprudhomme@…>, 3 years ago

Removed default parser argument

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#pragma once
2
3#include <math.trait.hfa>
4
5
6// *********************************** initial declarations ***********************************
7
8
9struct config_entry {
10        const char * key;
11        void * variable;
12        bool (*parse)( const char *, void * );
13        bool (*validate)( void * );
14};
15
16bool null_validator( void * ) { return true; }
17
18static inline void ?{}( config_entry & this ) {}
19
20forall(T & | { bool parse( const char *, T & ); })
21static inline void ?{}( config_entry & this, const char * key, T & variable ) {
22        this.key      = key;
23        this.variable = (void *)&variable;
24        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
25        this.validate = null_validator;
26}
27
28forall(T & | { bool parse( const char *, T & ); })
29static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(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 = (bool (*)(void *))(bool (*)(T &))validate;
34}
35
36forall(T &)
37static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, 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 = null_validator;
42}
43
44forall(T &)
45static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) {
46        this.key      = key;
47        this.variable = (void *)&variable;
48        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
49        this.validate = (bool (*)(void *))(bool (*)(T &))validate;
50}
51
52// TODO: Replace KVPairs with vector2 when it's fully functional
53struct KVPairs {
54        size_t size, max_size;
55        * [ * char, * char ] data;
56};
57
58[ void ] add_kv_pair( & KVPairs kv_pairs, [] char key, [] char value );
59
60
61// *********************************** exceptions ***********************************
62
63
64exception Missing_Config_Entries {
65        unsigned int num_missing;
66};
67
68[ void ] msg( * Missing_Config_Entries ex );
69
70exception Parse_Failure {
71        * char failed_key;
72        * char failed_value;
73};
74
75[ void ] msg( * Parse_Failure ex );
76
77exception Validation_Failure {
78        * char failed_key;
79        * char failed_value;
80};
81
82[ void ] msg( * Validation_Failure ex );
83
84
85// *********************************** main code ***********************************
86
87
88[ * KVPairs ] parse_tabular_config_format( [] const char config_file, size_t num_entries );
89
90[ void ] parse_config(
91        [] const char config_file,
92        [] config_entry entries,
93        size_t num_entries,
94        KVPairs * (*parser)(const char [], size_t)  // TODO: add sensible default parser when resolver bug is fixed
95);
96
97bool parse( const char *, const char * & );
98bool parse( const char *, int & );
99bool parse( const char *, unsigned & );
100bool parse( const char *, unsigned long & );
101bool parse( const char *, unsigned long long & );
102bool parse( const char *, float & );
103bool parse( const char *, double & );
104
105
106// *********************************** validation ***********************************
107
108
109forall(T | Relational( T ))
110[ bool ] is_nonnegative( & T );
111
112forall(T | Relational( T ))
113[ bool ] is_positive( & T );
114
115forall(T | Relational( T ))
116[ bool ] is_nonpositive( & T );
117
118forall(T | Relational( T ))
119[ bool ] is_negative( & T );
120
121
122// Local Variables: //
123// mode: c //
124// tab-width: 4 //
125// End: //
Note: See TracBrowser for help on using the repository browser.