mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
unordered_map for locale, and const functions where possible
This commit is contained in:
+4
-4
@@ -77,16 +77,16 @@ String identity(const String& key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
String SubLocale::tr(const String& key, DefaultLocaleFun def) {
|
||||
map<String,String>::const_iterator it = translations.find(canonical_name_form(key));
|
||||
String SubLocale::tr(const String& key, DefaultLocaleFun def) const {
|
||||
auto it = translations.find(canonical_name_form(key));
|
||||
if (it == translations.end()) {
|
||||
return def(key);
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
String SubLocale::tr(const String& subcat, const String& key, DefaultLocaleFun def) {
|
||||
map<String,String>::const_iterator it = translations.find(subcat + _("_") + canonical_name_form(key));
|
||||
String SubLocale::tr(const String& subcat, const String& key, DefaultLocaleFun def) const {
|
||||
auto it = translations.find(subcat + _("_") + canonical_name_form(key));
|
||||
if (it == translations.end()) {
|
||||
return def(key);
|
||||
} else {
|
||||
|
||||
+4
-4
@@ -19,14 +19,14 @@ DECLARE_POINTER_TYPE(SubLocaleValidator);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Locale class
|
||||
|
||||
/// Translations of the texts of a game/stylesheet/symbolfont
|
||||
/// Translations of the texts of a locale category or game/stylesheet/symbolfont
|
||||
class SubLocale : public IntrusivePtrBase<SubLocale> {
|
||||
public:
|
||||
map<String,String> translations;
|
||||
unordered_map<String,String> translations;
|
||||
|
||||
/// Translate a key, if not found, apply the default function to the key
|
||||
String tr(const String& key, DefaultLocaleFun def);
|
||||
String tr(const String& subcat, const String& key, DefaultLocaleFun def);
|
||||
String tr(const String& key, DefaultLocaleFun def) const;
|
||||
String tr(const String& subcat, const String& key, DefaultLocaleFun def) const;
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
+10
-1
@@ -94,7 +94,8 @@ public:
|
||||
/// Reads a intrusive_ptr from the input stream
|
||||
template <typename T> void handle(intrusive_ptr<T>&);
|
||||
/// Reads a map from the input stream
|
||||
template <typename V> void handle(map<String,V>&);
|
||||
template <typename V> void handle(map<String, V>&);
|
||||
template <typename V> void handle(unordered_map<String, V>&);
|
||||
/// Reads an IndexMap from the input stream, reads only keys that already exist in the map
|
||||
template <typename K, typename V> void handle(IndexMap<K,V>&);
|
||||
template <typename K, typename V> void handle(DelayedIndexMaps<K,V>&);
|
||||
@@ -239,6 +240,14 @@ void Reader::handle(map<String, V>& m) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
void Reader::handle(unordered_map<String, V>& m) {
|
||||
while (enterAnyBlock()) {
|
||||
handle_greedy(m[key]);
|
||||
exitBlock();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
void Reader::handle(IndexMap<K,V>& m) {
|
||||
for (typename IndexMap<K,V>::iterator it = m.begin() ; it != m.end() ; ++it) {
|
||||
|
||||
+11
-3
@@ -57,6 +57,7 @@ public:
|
||||
template <typename T> void handle(const intrusive_ptr<T>&);
|
||||
/// Write a map to the output stream
|
||||
template <typename K, typename V> void handle(const map<K,V>&);
|
||||
template <typename K, typename V> void handle(const unordered_map<K, V>&);
|
||||
/// Write an IndexMap to the output stream
|
||||
template <typename K, typename V> void handle(const IndexMap<K,V>&);
|
||||
template <typename K, typename V> void handle(const DelayedIndexMaps<K,V>&);
|
||||
@@ -111,15 +112,22 @@ void Writer::handle(const intrusive_ptr<T>& pointer) {
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
void Writer::handle(const map<K,V>& m) {
|
||||
for (typename map<K,V>::const_iterator it = m.begin() ; it != m.end() ; ++it) {
|
||||
void Writer::handle(const map<K, V>& m) {
|
||||
for (auto it = m.begin(); it != m.end(); ++it) {
|
||||
handle(it->first.c_str(), it->second);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
void Writer::handle(const unordered_map<K, V>& m) {
|
||||
for (auto it = m.begin(); it != m.end(); ++it) {
|
||||
handle(it->first.c_str(), it->second);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
void Writer::handle(const IndexMap<K,V>& m) {
|
||||
for (typename IndexMap<K,V>::const_iterator it = m.begin() ; it != m.end() ; ++it) {
|
||||
for (auto it = m.begin() ; it != m.end() ; ++it) {
|
||||
handle(get_key_name(*it).c_str(), *it);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user