add class dictionary to avoid storing strings all the time

This commit is contained in:
Konstantin Käfer
2014-06-27 15:53:12 +02:00
parent 6d9de75732
commit e989478b27
2 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
#include <llmr/style/class_dictionary.hpp>
namespace llmr {
ClassID ClassDictionary::Lookup(const std::string &class_name) {
auto it = store.find(class_name);
if (it == store.end()) {
// Insert the class name into the store.
ClassID id = ClassID(uint32_t(ClassID::Named) + offset++);
store.emplace(class_name, id);
return id;
} else {
return it->second;
}
}
ClassID ClassDictionary::Normalize(ClassID id) {
if (id >= ClassID::Named) {
return ClassID::Named;
} else {
return id;
}
}
std::unordered_map<std::string, ClassID> ClassDictionary::store = { { "", ClassID::Default } };
uint32_t ClassDictionary::offset = 0;
}