Nature Library C Interface.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-17 20:03:01 +02:00
parent a9075d7ef3
commit bd3e274d3d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 35 additions and 6 deletions

View File

@ -0,0 +1,23 @@
#include "../../src/Library/Natures/NatureLibrary.hpp"
#include "../Core.hpp"
using namespace PkmnLib::Library;
export NatureLibrary* PkmnLib_NatureLibrary_Construct(size_t initialCapacity) {
return new NatureLibrary(initialCapacity);
}
export void PkmnLib_NatureLibrary_Destruct(const NatureLibrary* p) { delete p; }
export uint8_t PkmnLib_NatureLibrary_LoadNature(NatureLibrary* p, const char* name, const Nature* nature) {
Try(p->LoadNature(Arbutils::CaseInsensitiveConstString(name), nature);)
}
export uint8_t PkmnLib_NatureLibrary_GetNatureByName(NatureLibrary* p, const char* name, const Nature*& out) {
Try(out = p->GetNatureByName(Arbutils::CaseInsensitiveConstString(name)));
}
export const char* PkmnLib_NatureLibrary_GetRandomNatureName(NatureLibrary* p, Arbutils::Random* rand) {
return p->GetRandomNatureName(rand).c_str();
}
export uint8_t PkmnLib_NatureLibrary_GetNatureName(NatureLibrary* p, const Nature* nature, const char*& out) {
Try(out = p->GetNatureName(nature).c_str());
}

View File

@ -15,7 +15,7 @@ namespace PkmnLib::Library {
Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*> _items;
public:
explicit NatureLibrary(uint8_t size = 32)
explicit NatureLibrary(size_t size = 32) noexcept
: _items(Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*>(size)) {}
~NatureLibrary() {
@ -38,6 +38,12 @@ namespace PkmnLib::Library {
auto& map = _items.GetStdMap();
return std::next(std::begin(map), i)->first;
}
inline const Arbutils::CaseInsensitiveConstString&
GetRandomNatureName(Arbutils::Random* rand) const {
auto i = rand->Get(_items.Count());
auto& map = _items.GetStdMap();
return std::next(std::begin(map), i)->first;
}
inline Arbutils::CaseInsensitiveConstString GetNatureName(const Nature* nature) {
for (const auto& v : _items) {