Implement basic library class that other libraries inherit from for performance.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user