PkmnLib/src/Library/Species/SpeciesLibrary.hpp

44 lines
1.9 KiB
C++

#ifndef PKMNLIB_SPECIESLIBRARY_HPP
#define PKMNLIB_SPECIESLIBRARY_HPP
#include <CreatureLib/Library/SpeciesLibrary.hpp>
#include "PokemonSpecies.hpp"
namespace PkmnLib::Library {
class SpeciesLibrary final : public CreatureLib::Library::SpeciesLibrary {
ArbUt::Dictionary<ArbUt::BorrowedPtr<const PokemonSpecies>, ArbUt::BorrowedPtr<const PokemonSpecies>>
_preEvolutionCache;
public:
SpeciesLibrary(size_t initialCapacity = 32) : CreatureLib::Library::SpeciesLibrary(initialCapacity) {}
inline std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>> TryGet(const ArbUt::StringView& name) const {
auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name);
if (!res.has_value())
return {};
return res.value().ForceAs<const PokemonSpecies>();
}
inline std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>> TryGetByHash(u32 hashedKey) const {
auto res = CreatureLib::Library::SpeciesLibrary::TryGetByHash(hashedKey);
if (!res.has_value())
return {};
return res.value().ForceAs<const PokemonSpecies>();
}
inline ArbUt::BorrowedPtr<const PokemonSpecies> Get(const ArbUt::StringView& name) const {
return CreatureLib::Library::SpeciesLibrary::Get(name).As<const PokemonSpecies>();
}
inline ArbUt::BorrowedPtr<const PokemonSpecies> GetByHash(u32 hashedKey) const {
return CreatureLib::Library::SpeciesLibrary::GetByHash(hashedKey).As<const PokemonSpecies>();
}
ArbUt::BorrowedPtr<const PokemonSpecies> operator[](const ArbUt::StringView& name) const { return Get(name); }
std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>>
FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept;
};
}
#endif // PKMNLIB_SPECIESLIBRARY_HPP