diff -r c637b172d565 -r 6790dea720a8 config.h --- a/config.h Mon Mar 25 15:20:56 2013 +0200 +++ b/config.h Mon Mar 25 16:05:03 2013 +0200 @@ -23,34 +23,17 @@ #include "str.h" // ============================================================================= -// Determine configuration file. Use APPNAME if given. -#ifdef APPNAME - #define CONFIGFILE APPNAME ".ini" -#else // APPNAME - #define APPNAME "(unnamed application)" - #define CONFIGFILE "config.ini" -#endif // APPNAME - -#ifdef CONFIG_WITH_QT - #include -#endif // CONFIG_WITH_QT - -// ------------------------------- -#define CFGSECTNAME(X) CFGSECT_##X +#define CONFIGFILE APPNAME ".cfg" +#include #define MAX_INI_LINE 512 -#define NUM_CONFIG (sizeof config::pointers / sizeof *config::pointers) +#define NUM_CONFIG (g_pConfigPointers.size ()) -// ============================================================================= -enum configsection_e { -#define CFG(...) -#define SECT(A,B) CFGSECTNAME (A), - #include "cfgdef.h" -#undef CFG -#undef SECT - NUM_ConfigSections, - NO_CONFIG_SECTION = -1 -}; +#define cfg(T, NAME, DEFAULT) \ + T##config NAME (DEFAULT, #NAME, #T, #DEFAULT) + +#define extern_cfg(T, NAME) \ + extern T##config NAME // ============================================================================= enum configtype_e { @@ -64,8 +47,7 @@ // ========================================================= class config { public: - configsection_e sect; - const char* description, *name, *fullname, *typestring, *defaultstring; + const char* name, *typestring, *defaultstring; virtual configtype_e getType () { return CONFIG_none; @@ -77,13 +59,12 @@ static bool load (); static bool save (); static void reset (); - static config* pointers[]; - static const char* sections[]; - static const char* sectionNames[]; static str dirpath (); static str filepath (); }; +extern std::vector g_pConfigPointers; + // ============================================================================= #define DEFINE_UNARY_OPERATOR(T, OP) \ T operator OP () { \ @@ -130,17 +111,14 @@ #define IMPLEMENT_CONFIG(T) \ T value, defval; \ \ - T##config (const configsection_e _sect, const char* _description, \ - T _defval, const char* _name, const char* _fullname, const char* _typestring, \ + T##config (T _defval, const char* _name, const char* _typestring, \ const char* _defaultstring) \ { \ - sect = _sect; \ - description = _description; \ value = defval = _defval; \ name = _name; \ - fullname = _fullname; \ typestring = _typestring; \ defaultstring = _defaultstring; \ + g_pConfigPointers.push_back (this); \ } \ operator T () { \ return value; \ @@ -148,7 +126,7 @@ configtype_e getType () { \ return CONFIG_##T; \ } \ - void resetValue () { \ + virtual void resetValue () { \ value = defval; \ } @@ -235,12 +213,4 @@ DEFINE_ASSIGN_OPERATOR (bool, =) }; -// ============================================================================= -// Extern the configurations now -#define CFG(TYPE, SECT, NAME, DESCR, DEFAULT) extern TYPE##config SECT##_##NAME; -#define SECT(...) - #include "cfgdef.h" -#undef CFG -#undef SECT - #endif // __OPTIONS_H__ \ No newline at end of file