mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-21 17:47:13 +02:00
Add iteration.
This commit is contained in:
module/Core
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -296,6 +296,16 @@ struct PvClass
|
||||
* See if a unit with a certain tag inherits this class.
|
||||
*/
|
||||
bool HaveUnitWithTag(StackStrF & tag);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Invoke a given callback with every owned entry identifier.
|
||||
*/
|
||||
void EachEntryID(Object & ctx, Function & func);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Invoke a given callback with every parented unit identifier.
|
||||
*/
|
||||
void EachUnitID(Object & ctx, Function & func);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -358,6 +368,9 @@ struct SqPvClass
|
||||
SQMOD_NODISCARD LightObj GetUnitWithTag(StackStrF & tag) const { return Valid().GetUnitWithTag(tag); }
|
||||
SQMOD_NODISCARD bool HaveUnitWithID(SQInteger id) const { return Valid().HaveUnitWithID(id); }
|
||||
SQMOD_NODISCARD bool HaveUnitWithTag(StackStrF & tag) const { return Valid().HaveUnitWithTag(tag); }
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void EachEntryID(Object & ctx, Function & func) { return Valid().EachEntryID(ctx, func); }
|
||||
void EachUnitID(Object & ctx, Function & func) { return Valid().EachUnitID(ctx, func); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -342,6 +342,18 @@ bool PvUnit::Can(SQInteger id) const
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void PvUnit::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);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
LightObj SqPvUnit::GetClass() const
|
||||
{
|
||||
@ -429,6 +441,7 @@ void Register_Privilege_Unit(HSQUIRRELVM vm, Table & ns)
|
||||
.Func(_SC("Modify"), &SqPvUnit::ModifyPrivilegeWithID)
|
||||
.FmtFunc(_SC("ModifyWithTag"), &SqPvUnit::ModifyPrivilegeWithTag)
|
||||
.Func(_SC("RemoveAll"), &SqPvUnit::RemoveAllPrivileges)
|
||||
.Func(_SC("EachEntryID"), &SqPvUnit::EachEntryID)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -249,6 +249,11 @@ struct PvUnit
|
||||
* Check if this unit has a certain privilege.
|
||||
*/
|
||||
SQMOD_NODISCARD bool Can(SQInteger id) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Invoke a given callback with every owned entry identifier.
|
||||
*/
|
||||
void EachEntryID(Object & ctx, Function & func);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -304,6 +309,8 @@ struct SqPvUnit
|
||||
void ModifyPrivilegeWithID(SQInteger id, SQInteger value) { Valid().ModifyPrivilege(id, value); }
|
||||
void ModifyPrivilegeWithTag(StackStrF & tag, SQInteger value) { Valid().ModifyPrivilege(tag, value); }
|
||||
void RemoveAllPrivileges() { Valid().RemoveAllPrivileges(); }
|
||||
// --------------------------------------------------------------------------------------------
|
||||
void EachEntryID(Object & ctx, Function & func) { return Valid().EachEntryID(ctx, func); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
Reference in New Issue
Block a user