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,39 +1 @@
#include "SpeciesLibrary.hpp"
bool CreatureLib::Library::SpeciesLibrary::TryGetSpecies(
const std::string& name, const CreatureLib::Library::CreatureSpecies*& outSpecies) const {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = _species.find(key);
if (find == _species.end()) {
outSpecies = nullptr;
return false;
}
outSpecies = find->second;
return true;
}
const CreatureLib::Library::CreatureSpecies*
CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return _species.at(key);
}
const CreatureLib::Library::CreatureSpecies*
CreatureLib::Library::SpeciesLibrary::operator[](const std::string& name) const {
return GetSpecies(name);
}
void CreatureLib::Library::SpeciesLibrary::LoadSpecies(const std::string& name,
const CreatureLib::Library::CreatureSpecies* species) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
_species.insert({key, species});
}
void CreatureLib::Library::SpeciesLibrary::DeleteSpecies(const std::string& name) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
_species.erase(key);
}