00001 #ifndef CONFIGCLASS_H
00002 #define CONFIGCLASS_H
00003
00004 #include "support.H"
00005
00006
00007
00008
00009
00010 extern void main_config(bool);
00011
00012 class ConfigInit {
00013 static int count;
00014 public:
00015 ConfigInit() { if (count++ == 0) main_config(true); }
00016 ~ConfigInit() { if (--count == 0) main_config(false); }
00017 };
00018
00019 static ConfigInit ConfigInitInstance;
00020
00021 class Config {
00022
00023 protected:
00024
00025 static Config* _instance;
00026
00027 static bool _replace;
00028 static bool _loaded;
00029
00030 static str_list* _no_warn;
00031
00032 public:
00033
00034
00035 static bool get_var_bool(Cstr_ptr& var, bool def=false, bool store=false);
00036 static int get_var_int (Cstr_ptr& var, int def=0, bool store=false);
00037 static str_ptr get_var_str (Cstr_ptr& var, Cstr_ptr& def=NULL_STR, bool store=false);
00038 static double get_var_dbl (Cstr_ptr& var, double def=0.0, bool store=false);
00039
00040 static void set_var_bool(Cstr_ptr& var, bool val);
00041 static void set_var_int (Cstr_ptr& var, int val);
00042 static void set_var_str (Cstr_ptr& var, Cstr_ptr& val);
00043 static void set_var_dbl (Cstr_ptr& var, double val);
00044
00045 static bool save_config(Cstr_ptr &f)
00046 {
00047 return ((_instance)?(_instance->save(f)):(false));
00048 }
00049 static bool load_config(Cstr_ptr &f,bool rep=true);
00050
00051 static Cstr_ptr& JOT_ROOT() { assert(_instance); return _instance->_jot_root; }
00052
00053 static void no_warn(Cstr_ptr &s) { if (!_no_warn) _no_warn = new str_list; (*_no_warn) += s; }
00054
00055 protected:
00056 static bool get_var_is_set(Cstr_ptr& var);
00057
00058 protected:
00059
00060 str_ptr _jot_root;
00061
00062 public:
00063
00064
00065 Config(Cstr_ptr& j);
00066 virtual ~Config();
00067
00068 protected:
00069
00070
00071 virtual bool load(Cstr_ptr &) { return false; }
00072 virtual bool save(Cstr_ptr &) { return false; }
00073
00074 };
00075
00076 #endif