Support getting an item from BaseLibrary by index, for iterating purposes.

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-08-10 17:01:21 +02:00
parent 48660f3a4c
commit 3a75a40671
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 7 additions and 1 deletions

View File

@ -37,4 +37,7 @@
Try(out = p->Get(hashedKey).GetRaw();) \
} \
\
export size_t simpleName##_GetCount(fullname* p) { return p->GetCount(); }
export size_t simpleName##_GetCount(fullname* p) { return p->GetCount(); } \
export uint8_t simpleName##_GetAtIndex(fullname* p, size_t index, const returnType*& out) { \
Try(out = p->GetAtIndex(index).GetRaw();) \
}

View File

@ -85,6 +85,9 @@ namespace CreatureLib::Library {
}
[[nodiscard]] size_t GetCount() const noexcept { return _values.Count(); }
ArbUt::BorrowedPtr<const T> GetAtIndex(size_t index) const {
return std::next(std::begin(_values), index)->second;
}
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random& rand) const noexcept {
auto i = rand.Get(_listValues.Count());