Supports iterating over BaseLibrary.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
61bf868583
commit
47515399fe
|
@ -71,6 +71,19 @@ namespace CreatureLib::Library {
|
||||||
return _values;
|
return _values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using const_iterator = typename std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>::const_iterator;
|
||||||
|
|
||||||
|
inline const_iterator begin() const {
|
||||||
|
return reinterpret_cast<const std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>&>(
|
||||||
|
_values.GetStdMap())
|
||||||
|
.begin();
|
||||||
|
}
|
||||||
|
inline const_iterator end() const {
|
||||||
|
return reinterpret_cast<const std::unordered_map<uint32_t, ArbUt::BorrowedPtr<const T>>&>(
|
||||||
|
_values.GetStdMap())
|
||||||
|
.end();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] size_t GetCount() const noexcept { return _values.Count(); }
|
[[nodiscard]] size_t GetCount() const noexcept { return _values.Count(); }
|
||||||
|
|
||||||
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random rand = ArbUt::Random()) const noexcept {
|
inline ArbUt::BorrowedPtr<const T> GetRandomValue(ArbUt::Random rand = ArbUt::Random()) const noexcept {
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifdef TESTS_BUILD
|
||||||
|
#include "../../extern/catch.hpp"
|
||||||
|
#include "../../src/Library/BaseLibrary.hpp"
|
||||||
|
#include "../TestLibrary/TestLibrary.hpp"
|
||||||
|
|
||||||
|
using namespace CreatureLib::Library;
|
||||||
|
TEST_CASE("Iterate over library", "[Library]") {
|
||||||
|
auto& lib = TestLibrary::Get()->GetSpeciesLibrary();
|
||||||
|
auto i = 0;
|
||||||
|
for (auto b : *lib) {
|
||||||
|
if (i == 0) {
|
||||||
|
CHECK(b.second->GetName() == "testSpecies1"_cnc);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
CHECK(i == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue