source: libcfa/src/parseconfig.hfa @ 930609e2

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

Added some basic examples of validation functions

And rearranged the ordering of some declarations to avoid errors

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#pragma once
2
3#include <rational.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
16static inline void ?{}( config_entry & this ) {}
17
18forall(T & | { bool parse( const char *, T & ); })
19static inline void ?{}( config_entry & this, const char * key, T & variable ) {
20        this.key      = key;
21        this.variable = (void *)&variable;
22        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
23        this.validate = 0p;
24}
25
26forall(T & | { bool parse( const char *, T & ); })
27static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) {
28        this.key      = key;
29        this.variable = (void *)&variable;
30        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
31        this.validate = (bool (*)(void *))(bool (*)(T &))validate;
32}
33
34forall(T &)
35static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) {
36        this.key      = key;
37        this.variable = (void *)&variable;
38        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
39        this.validate = 0p;
40}
41
42forall(T &)
43static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) {
44        this.key      = key;
45        this.variable = (void *)&variable;
46        this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
47        this.validate = (bool (*)(void *))(bool (*)(T &))validate;
48}
49
50
51// *********************************** exceptions ***********************************
52
53
54EHM_EXCEPTION(Validation_Failure)(
55        const char * key;
56        void * variable;
57);
58
59void ?{}( Validation_Failure & this, config_entry & entry );
60
61
62// *********************************** main code ***********************************
63
64
65void parse_config( const char * config_file, config_entry entries[], size_t num_entries );
66
67bool parse( const char *, const char * & );
68bool parse( const char *, int & );
69bool parse( const char *, unsigned & );
70bool parse( const char *, unsigned long & );
71bool parse( const char *, unsigned long long & );
72bool parse( const char *, float & );
73bool parse( const char *, double & );
74
75
76// *********************************** validation ***********************************
77
78
79forall(T | arithmetic( T ))
80bool is_nonnegative( T & );
81
82forall(T | arithmetic( T ))
83bool is_positive( T & );
84
85forall(T | arithmetic( T ))
86bool is_nonpositive( T & );
87
88forall(T | arithmetic( T ))
89bool is_negative( T & );
90
91
92// Local Variables: //
93// mode: c //
94// tab-width: 4 //
95// End: //
Note: See TracBrowser for help on using the repository browser.