From: <geo...@us...> - 2014-01-13 18:44:14
|
Revision: 6638 http://sourceforge.net/p/freeorion/code/6638 Author: geoffthemedio Date: 2014-01-13 18:44:11 +0000 (Mon, 13 Jan 2014) Log Message: ----------- -Changed stringtable data to be stored in a map, indexed by filename from which it is looked up when getting a UserString. Consequently, if the stringtable is changed while the program is running, future UserString lookups will use the newly-specified stringtable. -Added an as-yet-unused function FlushLoadedStringTables, which clears the stored stingtable data so that it will be reloaded on the next lookup. This could be useful to refresh the stored strings after a stringtable edit while the program is running. Modified Paths: -------------- trunk/FreeOrion/util/i18n.cpp trunk/FreeOrion/util/i18n.h Modified: trunk/FreeOrion/util/i18n.cpp =================================================================== --- trunk/FreeOrion/util/i18n.cpp 2014-01-13 08:56:22 UTC (rev 6637) +++ trunk/FreeOrion/util/i18n.cpp 2014-01-13 18:44:11 UTC (rev 6638) @@ -17,17 +17,31 @@ return option_filename; } - const StringTable_& GetStringTable() { - static std::auto_ptr<StringTable_> string_table( - new StringTable_(GetStringTableFileName())); - return *string_table; + std::map<std::string, const StringTable_*> stringtables; + + void FlushLoadedStringTables() + { stringtables.clear(); } + + const StringTable_& GetStringTable(std::string stringtable_filename = "") { + // get option-configured stringtable if no filename specified + if (stringtable_filename.empty()) + stringtable_filename = GetStringTableFileName(); + + // attempt to find requested stringtable... + std::map<std::string, const StringTable_*>::const_iterator it = + stringtables.find(stringtable_filename); + if (it != stringtables.end()) + return *(it->second); + + // if already loaded, load, store, and return + const StringTable_* table = new StringTable_(stringtable_filename); + stringtables[stringtable_filename] = table; + + return *table; } - const StringTable_& GetDefaultStringTable() { - static std::auto_ptr<StringTable_> default_string_table( - new StringTable_(GetDefaultStringTableFileName())); - return *default_string_table; - } + const StringTable_& GetDefaultStringTable() + { return GetStringTable(GetDefaultStringTableFileName()); } } const std::string& UserString(const std::string& str) { Modified: trunk/FreeOrion/util/i18n.h =================================================================== --- trunk/FreeOrion/util/i18n.h 2014-01-13 08:56:22 UTC (rev 6637) +++ trunk/FreeOrion/util/i18n.h 2014-01-13 18:44:11 UTC (rev 6638) @@ -15,6 +15,10 @@ /** Returns a language-specific list of strings for the key-string \a str_list */ FO_COMMON_API void UserStringList(const std::string& str_list, std::list<std::string>& strings); +/** Clears all loaded strings, so that subsequent UserString lookups will cause + * the stringtable(s) to be reloaded. */ +FO_COMMON_API void FlushLoadedStringTables(); + /** Placeholder for non local translations, evaluates to a non operation */ #define UserStringNop(key) key |