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,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user