1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-17 07:37:13 +02:00

Add iteration.

This commit is contained in:
Sandu Liviu Catalin
2021-02-05 15:42:27 +02:00
parent bd1504bd24
commit 479272d59f
6 changed files with 125 additions and 0 deletions

View File

@ -390,6 +390,30 @@ bool PvClass::HaveUnitWithTag(StackStrF & tag)
return false;
}
// ------------------------------------------------------------------------------------------------
void PvClass::EachEntryID(Object & ctx, Function & func)
{
// In order to be safe from modifications while iterating, create a copy
PvStatusList list(mPrivileges);
// Iterate entries and forward the ID to the callback
for (const auto & e : list)
{
func(ctx, e.first);
}
}
// ------------------------------------------------------------------------------------------------
void PvClass::EachUnitID(Object & ctx, Function & func)
{
// In order to be safe from modifications while iterating, create a copy
PvUnit::List list(mUnits);
// Iterate units and forward the ID to the callback
for (const auto & u : list)
{
func(ctx, u.second->mID);
}
}
// ================================================================================================
bool SqPvClass::Can(LightObj & obj) const
{
@ -462,6 +486,8 @@ void Register_Privilege_Class(HSQUIRRELVM vm, Table & ns)
.FmtFunc(_SC("GetUnitWithTag"), &SqPvClass::GetUnitWithTag)
.Func(_SC("HaveUnit"), &SqPvClass::HaveUnitWithID)
.FmtFunc(_SC("HaveUnitWithTag"), &SqPvClass::HaveUnitWithTag)
.FmtFunc(_SC("EachEntryID"), &SqPvClass::EachEntryID)
.FmtFunc(_SC("EachUnitID"), &SqPvClass::EachUnitID)
);
}