#pragma once #include // *********************************** initial declarations *********************************** enum config_format { TABULAR_CONFIG }; struct config_entry { const char * key; void * variable; bool (*parse)( const char *, void * ); bool (*validate)( void * ); }; static inline void ?{}( config_entry & this ) {} forall(T & | { bool parse( const char *, T & ); }) static inline void ?{}( config_entry & this, const char * key, T & variable ) { this.key = key; this.variable = (void *)&variable; this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; this.validate = (bool (*)(void *))(bool (*)(T &))0p; } forall(T & | { bool parse( const char *, T & ); }) static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) { this.key = key; this.variable = (void *)&variable; this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; this.validate = (bool (*)(void *))(bool (*)(T &))validate; } forall(T &) static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) { this.key = key; this.variable = (void *)&variable; this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; this.validate = (bool (*)(void *))(bool (*)(T &))0p; } forall(T &) static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) { this.key = key; this.variable = (void *)&variable; this.parse = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse; this.validate = (bool (*)(void *))(bool (*)(T &))validate; } // *********************************** exceptions *********************************** exception Parse_Failure {}; void ?{}( Parse_Failure & this ); exception Validation_Failure {}; void ?{}( Validation_Failure & this ); // *********************************** main code *********************************** void parse_config( const char * config_file, config_entry entries[], size_t num_entries, config_format format ); bool parse( const char *, const char * & ); bool parse( const char *, int & ); bool parse( const char *, unsigned & ); bool parse( const char *, unsigned long & ); bool parse( const char *, unsigned long long & ); bool parse( const char *, float & ); bool parse( const char *, double & ); // *********************************** validation *********************************** forall(T | Relational( T )) bool is_nonnegative( T & ); forall(T | Relational( T )) bool is_positive( T & ); forall(T | Relational( T )) bool is_nonpositive( T & ); forall(T | Relational( T )) bool is_negative( T & ); // Local Variables: // // mode: c // // tab-width: 4 // // End: //