#pragma once #include // *********************************** initial declarations *********************************** 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 = 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 = 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 *********************************** EHM_EXCEPTION(Validation_Failure)( const char * key; void * variable; ); void ?{}( Validation_Failure & this, config_entry & entry ); // *********************************** main code *********************************** void parse_config( const char * config_file, config_entry entries[], size_t num_entries ); 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: //