source: libcfa/src/parseconfig.hfa@ 9b33337

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

Removed default parser argument

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[16f9aca]1#pragma once
2
[c58c65a]3#include <math.trait.hfa>
[80ae121]4
5
[930609e2]6// *********************************** initial declarations ***********************************
[80ae121]7
8
[4df8fef5]9struct config_entry {
10 const char * key;
11 void * variable;
[58ebd786]12 bool (*parse)( const char *, void * );
[e54654e]13 bool (*validate)( void * );
[4df8fef5]14};
15
[a3f2a3e]16bool null_validator( void * ) { return true; }
17
[4df8fef5]18static inline void ?{}( config_entry & this ) {}
19
[58ebd786]20forall(T & | { bool parse( const char *, T & ); })
[4df8fef5]21static inline void ?{}( config_entry & this, const char * key, T & variable ) {
22 this.key = key;
23 this.variable = (void *)&variable;
[4cc6c7d]24 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
[c166f4e]25 this.validate = null_validator;
[e54654e]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;
[4df8fef5]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;
[4cc6c7d]40 this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
[c166f4e]41 this.validate = null_validator;
[e54654e]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;
[4df8fef5]50}
51
[ca83227]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
[930609e2]60
61// *********************************** exceptions ***********************************
62
63
[3be4078]64exception Missing_Config_Entries {
[dcf792a]65 unsigned int num_missing;
[3be4078]66};
[e1e506b]67
[b0f225f]68[ void ] msg( * Missing_Config_Entries ex );
[e1e506b]69
[dcf792a]70exception Parse_Failure {
71 * char failed_key;
72 * char failed_value;
73};
[6d8e1ab]74
[b0f225f]75[ void ] msg( * Parse_Failure ex );
[6d8e1ab]76
[dcf792a]77exception Validation_Failure {
78 * char failed_key;
79 * char failed_value;
80};
[930609e2]81
[b0f225f]82[ void ] msg( * Validation_Failure ex );
[930609e2]83
84
85// *********************************** main code ***********************************
86
87
[81e0c61]88[ * KVPairs ] parse_tabular_config_format( [] const char config_file, size_t num_entries );
[ca83227]89
90[ void ] parse_config(
91 [] const char config_file,
92 [] config_entry entries,
93 size_t num_entries,
[a3cadfc]94 KVPairs * (*parser)(const char [], size_t) // TODO: add sensible default parser when resolver bug is fixed
[ca83227]95);
[16f9aca]96
[b1eeb3aa]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
[930609e2]105
106// *********************************** validation ***********************************
107
108
[c58c65a]109forall(T | Relational( T ))
[b0f225f]110[ bool ] is_nonnegative( & T );
[930609e2]111
[c58c65a]112forall(T | Relational( T ))
[b0f225f]113[ bool ] is_positive( & T );
[930609e2]114
[c58c65a]115forall(T | Relational( T ))
[b0f225f]116[ bool ] is_nonpositive( & T );
[930609e2]117
[c58c65a]118forall(T | Relational( T ))
[b0f225f]119[ bool ] is_negative( & T );
[930609e2]120
121
[16f9aca]122// Local Variables: //
123// mode: c //
124// tab-width: 4 //
125// End: //
Note: See TracBrowser for help on using the repository browser.