2019-10-06 11:50:52 +00:00
|
|
|
#ifndef CREATURELIB_SPECIESLIBRARY_HPP
|
|
|
|
#define CREATURELIB_SPECIESLIBRARY_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "CreatureData/CreatureSpecies.hpp"
|
|
|
|
|
|
|
|
namespace CreatureLib::Library {
|
|
|
|
class SpeciesLibrary {
|
|
|
|
private:
|
|
|
|
std::unordered_map<std::string, const CreatureSpecies*> _species;
|
2019-11-28 11:55:22 +00:00
|
|
|
|
2019-10-06 11:50:52 +00:00
|
|
|
public:
|
2019-12-31 09:48:52 +00:00
|
|
|
SpeciesLibrary(size_t initialCapacity = 32)
|
|
|
|
: _species(std::unordered_map<std::string, const CreatureSpecies*>(initialCapacity)){};
|
2019-10-06 11:50:52 +00:00
|
|
|
|
2020-01-02 16:48:14 +00:00
|
|
|
virtual ~SpeciesLibrary() {
|
2019-11-28 11:55:22 +00:00
|
|
|
for (auto s : _species)
|
2019-10-06 12:06:17 +00:00
|
|
|
delete s.second;
|
2019-10-06 11:50:52 +00:00
|
|
|
_species.clear();
|
|
|
|
}
|
|
|
|
|
2020-02-01 14:33:44 +00:00
|
|
|
[[nodiscard]] bool TryGetSpecies(const std::string& name, const CreatureSpecies*& outSpecies) const;
|
2019-10-06 11:50:52 +00:00
|
|
|
[[nodiscard]] const CreatureSpecies* GetSpecies(const std::string& name) const;
|
2019-11-28 11:55:22 +00:00
|
|
|
[[nodiscard]] const CreatureSpecies* operator[](const std::string& name) const;
|
2019-10-06 11:50:52 +00:00
|
|
|
|
|
|
|
void LoadSpecies(const std::string& name, const CreatureSpecies* species);
|
|
|
|
void DeleteSpecies(const std::string& name);
|
2020-02-08 13:52:45 +00:00
|
|
|
|
2020-02-08 16:50:27 +00:00
|
|
|
size_t GetCount() const { return _species.size(); }
|
2019-10-06 11:50:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
#endif // CREATURELIB_SPECIESLIBRARY_HPP
|