Implement basic library class that other libraries inherit from for performance.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-02-15 18:51:21 +01:00
parent a47f60cdf7
commit d6ea16b467
11 changed files with 87 additions and 195 deletions

View File

@@ -1,36 +1 @@
#include "ItemLibrary.hpp"
bool CreatureLib::Library::ItemLibrary::TryGetItem(const std::string& name,
const CreatureLib::Library::Item*& item) const {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = this->_items.find(key);
if (find == this->_items.end()) {
item = nullptr;
return false;
}
item = find->second;
return true;
}
const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::GetItem(const std::string& name) const {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return this->_items.at(key);
}
const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::operator[](const std::string& name) const {
return this->GetItem(name);
}
void CreatureLib::Library::ItemLibrary::LoadItem(const std::string& name, const CreatureLib::Library::Item* item) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
this->_items.insert({key, item});
}
void CreatureLib::Library::ItemLibrary::DeleteItem(const std::string& name) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
this->_items.erase(key);
}