--- scim_global_config.cpp 2007-06-20 11:32:52.139361000 +0800 +++ scim_global_config.cpp.new 2007-06-20 11:35:06.063490000 +0800 @@ -62,7 +62,7 @@ public: }; -static GlobalConfigRepository __config_repository; +static GlobalConfigRepository *__config_repository; static String __trim_blank (const String &str) @@ -128,8 +128,11 @@ __parse_config (std::ifstream &is, KeyVa static void __initialize_config () { - __config_repository.sys.clear (); - __config_repository.usr.clear (); + if (!__config_repository) + __config_repository = new GlobalConfigRepository(); + + __config_repository->sys.clear (); + __config_repository->usr.clear (); String sys_conf_file = String (SCIM_SYSCONFDIR) + String (SCIM_PATH_DELIM_STRING) + @@ -147,27 +150,27 @@ __initialize_config () std::ifstream usr_is (usr_conf_file.c_str ()); if (sys_is) { - __parse_config (sys_is, __config_repository.sys); - __config_repository.initialized = true; + __parse_config (sys_is, __config_repository->sys); + __config_repository->initialized = true; } if (usr_is) { - __parse_config (usr_is, __config_repository.usr); - __config_repository.initialized = true; + __parse_config (usr_is, __config_repository->usr); + __config_repository->initialized = true; } } String scim_global_config_read (const String &key, const String &defVal) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized) { - KeyValueRepository::iterator it = __config_repository.usr.find (key); + if (__config_repository->initialized) { + KeyValueRepository::iterator it = __config_repository->usr.find (key); - if (it == __config_repository.usr.end ()) { - it = __config_repository.sys.find (key); - if (it == __config_repository.sys.end ()) + if (it == __config_repository->usr.end ()) { + it = __config_repository->sys.find (key); + if (it == __config_repository->sys.end ()) return defVal; } @@ -180,14 +183,14 @@ scim_global_config_read (const String &k int scim_global_config_read (const String &key, int defVal) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized) { - KeyValueRepository::iterator it = __config_repository.usr.find (key); + if (__config_repository->initialized) { + KeyValueRepository::iterator it = __config_repository->usr.find (key); - if (it == __config_repository.usr.end ()) { - it = __config_repository.sys.find (key); - if (it == __config_repository.sys.end ()) + if (it == __config_repository->usr.end ()) { + it = __config_repository->sys.find (key); + if (it == __config_repository->sys.end ()) return defVal; } @@ -201,14 +204,14 @@ scim_global_config_read (const String &k bool scim_global_config_read (const String &key, bool defVal) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized) { - KeyValueRepository::iterator it = __config_repository.usr.find (key); + if (__config_repository->initialized) { + KeyValueRepository::iterator it = __config_repository->usr.find (key); - if (it == __config_repository.usr.end ()) { - it = __config_repository.sys.find (key); - if (it == __config_repository.sys.end ()) + if (it == __config_repository->usr.end ()) { + it = __config_repository->sys.find (key); + if (it == __config_repository->sys.end ()) return defVal; } @@ -226,14 +229,14 @@ scim_global_config_read (const String &k double scim_global_config_read (const String &key, double defVal) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized) { - KeyValueRepository::iterator it = __config_repository.usr.find (key); + if (__config_repository->initialized) { + KeyValueRepository::iterator it = __config_repository->usr.find (key); - if (it == __config_repository.usr.end ()) { - it = __config_repository.sys.find (key); - if (it == __config_repository.sys.end ()) + if (it == __config_repository->usr.end ()) { + it = __config_repository->sys.find (key); + if (it == __config_repository->sys.end ()) return defVal; } @@ -247,14 +250,14 @@ scim_global_config_read (const String &k std::vector scim_global_config_read (const String &key, const std::vector &defVal) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized) { - KeyValueRepository::iterator it = __config_repository.usr.find (key); + if (__config_repository->initialized) { + KeyValueRepository::iterator it = __config_repository->usr.find (key); - if (it == __config_repository.usr.end ()) { - it = __config_repository.sys.find (key); - if (it == __config_repository.sys.end ()) + if (it == __config_repository->usr.end ()) { + it = __config_repository->sys.find (key); + if (it == __config_repository->sys.end ()) return defVal; } @@ -271,14 +274,14 @@ scim_global_config_read (const String &k std::vector scim_global_config_read (const String &key, const std::vector &defVal) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized) { - KeyValueRepository::iterator it = __config_repository.usr.find (key); + if (__config_repository->initialized) { + KeyValueRepository::iterator it = __config_repository->usr.find (key); - if (it == __config_repository.usr.end ()) { - it = __config_repository.sys.find (key); - if (it == __config_repository.sys.end ()) + if (it == __config_repository->usr.end ()) { + it = __config_repository->sys.find (key); + if (it == __config_repository->sys.end ()) return defVal; } @@ -301,97 +304,97 @@ scim_global_config_read (const String &k void scim_global_config_write (const String &key, const String &val) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized && key.length ()) { - __config_repository.usr [key] = val; - __config_repository.updated [key] = "updated"; + if (__config_repository->initialized && key.length ()) { + __config_repository->usr [key] = val; + __config_repository->updated [key] = "updated"; } } void scim_global_config_write (const String &key, int val) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized && key.length ()) { + if (__config_repository->initialized && key.length ()) { char buf [80]; snprintf (buf, 80, "%d", val); - __config_repository.usr [key] = String (buf); - __config_repository.updated [key] = "updated"; + __config_repository->usr [key] = String (buf); + __config_repository->updated [key] = "updated"; } } void scim_global_config_write (const String &key, bool val) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized && key.length ()) { - __config_repository.usr [key] = (val ? "true" : "false"); - __config_repository.updated [key] = "updated"; + if (__config_repository->initialized && key.length ()) { + __config_repository->usr [key] = (val ? "true" : "false"); + __config_repository->updated [key] = "updated"; } } void scim_global_config_write (const String &key, double val) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized && key.length ()) { + if (__config_repository->initialized && key.length ()) { char buf [80]; snprintf (buf, 80, "%lf", val); - __config_repository.usr [key] = String (buf); - __config_repository.updated [key] = "updated"; + __config_repository->usr [key] = String (buf); + __config_repository->updated [key] = "updated"; } } void scim_global_config_write (const String &key, const std::vector &val) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized && key.length ()) { - __config_repository.usr [key] = scim_combine_string_list (val, ','); - __config_repository.updated [key] = "updated"; + if (__config_repository->initialized && key.length ()) { + __config_repository->usr [key] = scim_combine_string_list (val, ','); + __config_repository->updated [key] = "updated"; } } void scim_global_config_write (const String &key, const std::vector &val) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized && key.length ()) { + if (__config_repository->initialized && key.length ()) { std::vector strvec; char buf [80]; for (size_t i = 0; i < val.size (); ++i) { snprintf (buf, 80, "%d", val [i]); strvec.push_back (buf); } - __config_repository.usr [key] = scim_combine_string_list (strvec, ','); - __config_repository.updated [key] = "updated"; + __config_repository->usr [key] = scim_combine_string_list (strvec, ','); + __config_repository->updated [key] = "updated"; } } void scim_global_config_reset (const String &key) { - if (!__config_repository.initialized) __initialize_config (); + if (!__config_repository) __initialize_config (); - if (__config_repository.initialized && key.length ()) { - __config_repository.usr.erase (key); - __config_repository.updated [key] = "erased"; + if (__config_repository->initialized && key.length ()) { + __config_repository->usr.erase (key); + __config_repository->updated [key] = "erased"; } } bool scim_global_config_flush () { - if (!__config_repository.initialized) + if (!__config_repository) return false; - if (!__config_repository.updated.size ()) + if (!__config_repository->updated.size ()) return true; String usr_conf_dir = scim_get_home_dir () + @@ -408,27 +411,27 @@ scim_global_config_flush () return false; } - KeyValueRepository backup_usr = __config_repository.usr; + KeyValueRepository backup_usr = __config_repository->usr; // Reload all configuration. __initialize_config (); - for (KeyValueRepository::iterator it = __config_repository.updated.begin (); - it != __config_repository.updated.end (); ++it) { + for (KeyValueRepository::iterator it = __config_repository->updated.begin (); + it != __config_repository->updated.end (); ++it) { if (it->second == "updated") - __config_repository.usr [it->first] = backup_usr [it->first]; + __config_repository->usr [it->first] = backup_usr [it->first]; else if (it->second == "erased") - __config_repository.usr.erase (it->first); + __config_repository->usr.erase (it->first); } std::ofstream usr_os (usr_conf_file.c_str ()); if (usr_os) { - for (KeyValueRepository::iterator it = __config_repository.usr.begin (); - it != __config_repository.usr.end (); ++it) { + for (KeyValueRepository::iterator it = __config_repository->usr.begin (); + it != __config_repository->usr.end (); ++it) { usr_os << it->first << " = " << it->second << "\n"; } - __config_repository.updated.clear (); + __config_repository->updated.clear (); return true; }