mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Add removal methods.
This commit is contained in:
parent
ff8da4dad1
commit
bd1504bd24
@ -339,6 +339,136 @@ bool PvManager::HaveUnitWithTag(StackStrF & tag)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void PvManager::RemoveEntryWithID(SQInteger id)
|
||||||
|
{
|
||||||
|
// Remove this entry from the units
|
||||||
|
for (const auto & u : m_Units)
|
||||||
|
{
|
||||||
|
u.second->mPrivileges.erase(id);
|
||||||
|
}
|
||||||
|
// Remove this entry from the classes
|
||||||
|
for (const auto & c : m_Units)
|
||||||
|
{
|
||||||
|
c.second->mPrivileges.erase(id);
|
||||||
|
}
|
||||||
|
// Finally remove it from the list
|
||||||
|
m_Entries.erase(PvIdentity(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void PvManager::RemoveEntryWithTag(StackStrF & tag)
|
||||||
|
{
|
||||||
|
PvEntry & e = *GetValidEntryWithTag(tag);
|
||||||
|
// Remove this entry from the units
|
||||||
|
for (const auto & u : m_Units)
|
||||||
|
{
|
||||||
|
u.second->mPrivileges.erase(e.mID);
|
||||||
|
}
|
||||||
|
// Remove this entry from the classes
|
||||||
|
for (const auto & c : m_Units)
|
||||||
|
{
|
||||||
|
c.second->mPrivileges.erase(e.mID);
|
||||||
|
}
|
||||||
|
// Finally remove it from the list
|
||||||
|
auto itr = std::find_if(m_Entries.cbegin(), m_Entries.cend(),
|
||||||
|
[h = tag.CacheHash().GetHash()](PvEntry::List::const_reference e) -> bool { return e.first.mHash == h; });
|
||||||
|
// Was this unit found?
|
||||||
|
if (itr != m_Entries.end())
|
||||||
|
{
|
||||||
|
m_Entries.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void PvManager::RemoveClassWithID(SqPvClass & sub, SQInteger id)
|
||||||
|
{
|
||||||
|
PvClass::Ref cls = sub.mI.lock();
|
||||||
|
// Remove this entry from units
|
||||||
|
for (const auto & u : m_Units)
|
||||||
|
{
|
||||||
|
if (u.second->mClass.lock().get() == cls.get())
|
||||||
|
{
|
||||||
|
AutoAssign< bool > aag(m_LockUnits, false, true);
|
||||||
|
u.second->AssignClass(cls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remove this entry from classes
|
||||||
|
for (const auto & c : m_Classes)
|
||||||
|
{
|
||||||
|
if (!c.second->mParent.expired() && c.second->mParent.lock().get() == cls.get())
|
||||||
|
{
|
||||||
|
AutoAssign< bool > aag(m_LockClasses, false, true);
|
||||||
|
c.second->AssignParent(cls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Finally remove it from the list
|
||||||
|
m_Classes.erase(PvIdentity(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void PvManager::RemoveClassWithTag(SqPvClass & sub, StackStrF & tag)
|
||||||
|
{
|
||||||
|
PvClass::Ref cls = sub.mI.lock();
|
||||||
|
// Remove this class from units
|
||||||
|
for (const auto & u : m_Units)
|
||||||
|
{
|
||||||
|
if (u.second->mClass.lock().get() == cls.get())
|
||||||
|
{
|
||||||
|
AutoAssign< bool > aag(m_LockUnits, false, true);
|
||||||
|
u.second->AssignClass(cls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Remove this class from classes
|
||||||
|
for (const auto & c : m_Classes)
|
||||||
|
{
|
||||||
|
if (!c.second->mParent.expired() && c.second->mParent.lock().get() == cls.get())
|
||||||
|
{
|
||||||
|
AutoAssign< bool > aag(m_LockClasses, false, true);
|
||||||
|
c.second->AssignParent(cls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Finally remove it from the list
|
||||||
|
auto itr = std::find_if(m_Classes.cbegin(), m_Classes.cend(),
|
||||||
|
[h = tag.CacheHash().GetHash()](PvClass::List::const_reference e) -> bool { return e.first.mHash == h; });
|
||||||
|
// Was this unit found?
|
||||||
|
if (itr != m_Classes.end())
|
||||||
|
{
|
||||||
|
m_Classes.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void PvManager::RemoveUnitWithID(SQInteger id)
|
||||||
|
{
|
||||||
|
// Remove this class from classes
|
||||||
|
for (const auto & c : m_Classes)
|
||||||
|
{
|
||||||
|
c.second->mUnits.erase(PvIdentity(id));
|
||||||
|
}
|
||||||
|
// Finally remove it from the list
|
||||||
|
m_Units.erase(PvIdentity(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void PvManager::RemoveUnitWithTag(StackStrF & tag)
|
||||||
|
{
|
||||||
|
PvUnit & u = *GetValidUnitWithTag(tag);
|
||||||
|
// Remove this class from classes
|
||||||
|
for (const auto & c : m_Classes)
|
||||||
|
{
|
||||||
|
c.second->mUnits.erase(PvIdentity(u.mID));
|
||||||
|
}
|
||||||
|
// Finally remove it from the list
|
||||||
|
auto itr = std::find_if(m_Units.cbegin(), m_Units.cend(),
|
||||||
|
[h = tag.CacheHash().GetHash()](PvUnit::List::const_reference e) -> bool { return e.first.mHash == h; });
|
||||||
|
// Was this unit found?
|
||||||
|
if (itr != m_Units.end())
|
||||||
|
{
|
||||||
|
m_Units.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
extern void Register_Privilege_Class(HSQUIRRELVM vm, Table & ns);
|
extern void Register_Privilege_Class(HSQUIRRELVM vm, Table & ns);
|
||||||
extern void Register_Privilege_Entry(HSQUIRRELVM vm, Table & ns);
|
extern void Register_Privilege_Entry(HSQUIRRELVM vm, Table & ns);
|
||||||
@ -387,6 +517,12 @@ void Register_Privilege(HSQUIRRELVM vm)
|
|||||||
.FmtFunc(_SC("GetUnitWithTag"), &PvManager::GetUnitWithTag)
|
.FmtFunc(_SC("GetUnitWithTag"), &PvManager::GetUnitWithTag)
|
||||||
.Func(_SC("HaveUnit"), &PvManager::HaveUnitWithID)
|
.Func(_SC("HaveUnit"), &PvManager::HaveUnitWithID)
|
||||||
.FmtFunc(_SC("HaveUnitWithTag"), &PvManager::HaveUnitWithTag)
|
.FmtFunc(_SC("HaveUnitWithTag"), &PvManager::HaveUnitWithTag)
|
||||||
|
.Func(_SC("RemoveUnit"), &PvManager::RemoveUnitWithID)
|
||||||
|
.FmtFunc(_SC("RemoveUnitWithTag"), &PvManager::RemoveUnitWithTag)
|
||||||
|
.Func(_SC("RemoveEntry"), &PvManager::RemoveEntryWithID)
|
||||||
|
.FmtFunc(_SC("RemoveEntryWithTag"), &PvManager::RemoveEntryWithTag)
|
||||||
|
.Func(_SC("RemoveClass"), &PvManager::RemoveClassWithID)
|
||||||
|
.FmtFunc(_SC("RemoveClassWithTag"), &PvManager::RemoveClassWithTag)
|
||||||
);
|
);
|
||||||
|
|
||||||
RootTable(vm).Bind(_SC("SqPrivilege"), ns);
|
RootTable(vm).Bind(_SC("SqPrivilege"), ns);
|
||||||
|
@ -558,64 +558,94 @@ public:
|
|||||||
void PropagateClassChange(const PvUnit::Ref & unit, const PvClass::Ref & cls) { PropagateClassChange(*unit, cls); }
|
void PropagateClassChange(const PvUnit::Ref & unit, const PvClass::Ref & cls) { PropagateClassChange(*unit, cls); }
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a entry with a certain identifier inherits this class.
|
* Retrieve a entry with a certain identifier from this manager.
|
||||||
*/
|
*/
|
||||||
SQMOD_NODISCARD LightObj GetEntryWithID(SQInteger id);
|
SQMOD_NODISCARD LightObj GetEntryWithID(SQInteger id);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a entry with a certain tag inherits this class.
|
* Retrieve a entry with a certain tag from this manager.
|
||||||
*/
|
*/
|
||||||
SQMOD_NODISCARD LightObj GetEntryWithTag(StackStrF & tag);
|
SQMOD_NODISCARD LightObj GetEntryWithTag(StackStrF & tag);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a entry with a certain identifier inherits this class.
|
* See if a entry with a certain identifier exists in this manager.
|
||||||
*/
|
*/
|
||||||
bool HaveEntryWithID(SQInteger id);
|
bool HaveEntryWithID(SQInteger id);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a entry with a certain tag inherits this class.
|
* See if a entry with a certain tag exists in this manager.
|
||||||
*/
|
*/
|
||||||
bool HaveEntryWithTag(StackStrF & tag);
|
bool HaveEntryWithTag(StackStrF & tag);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a class with a certain identifier inherits this class.
|
* Retrieve a class with a certain identifier from this manager.
|
||||||
*/
|
*/
|
||||||
SQMOD_NODISCARD LightObj GetClassWithID(SQInteger id);
|
SQMOD_NODISCARD LightObj GetClassWithID(SQInteger id);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a class with a certain tag inherits this class.
|
* Retrieve a class with a certain tag from this manager.
|
||||||
*/
|
*/
|
||||||
SQMOD_NODISCARD LightObj GetClassWithTag(StackStrF & tag);
|
SQMOD_NODISCARD LightObj GetClassWithTag(StackStrF & tag);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a class with a certain identifier inherits this class.
|
* See if a class with a certain identifier exists in this manager.
|
||||||
*/
|
*/
|
||||||
bool HaveClassWithID(SQInteger id);
|
bool HaveClassWithID(SQInteger id);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a class with a certain tag inherits this class.
|
* See if a class with a certain tag exists in this manager.
|
||||||
*/
|
*/
|
||||||
bool HaveClassWithTag(StackStrF & tag);
|
bool HaveClassWithTag(StackStrF & tag);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a unit with a certain identifier inherits this class.
|
* Retrieve a unit with a certain identifier from this manager.
|
||||||
*/
|
*/
|
||||||
SQMOD_NODISCARD LightObj GetUnitWithID(SQInteger id);
|
SQMOD_NODISCARD LightObj GetUnitWithID(SQInteger id);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a unit with a certain tag inherits this class.
|
* Retrieve a unit with a certain tag from this manager.
|
||||||
*/
|
*/
|
||||||
SQMOD_NODISCARD LightObj GetUnitWithTag(StackStrF & tag);
|
SQMOD_NODISCARD LightObj GetUnitWithTag(StackStrF & tag);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a unit with a certain identifier inherits this class.
|
* See if a unit with a certain identifier exists in this manager.
|
||||||
*/
|
*/
|
||||||
bool HaveUnitWithID(SQInteger id);
|
bool HaveUnitWithID(SQInteger id);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if a unit with a certain tag inherits this class.
|
* See if a unit with a certain tag exists in this manager.
|
||||||
*/
|
*/
|
||||||
bool HaveUnitWithTag(StackStrF & tag);
|
bool HaveUnitWithTag(StackStrF & tag);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Remove a entry with a certain identifier from this manager.
|
||||||
|
*/
|
||||||
|
void RemoveEntryWithID(SQInteger id);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Remove a entry with a certain tag from this manager.
|
||||||
|
*/
|
||||||
|
void RemoveEntryWithTag(StackStrF & tag);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Remove a class with a certain identifier from this manager.
|
||||||
|
*/
|
||||||
|
void RemoveClassWithID(SqPvClass & sub, SQInteger id);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Remove a class with a certain tag from this manager.
|
||||||
|
*/
|
||||||
|
void RemoveClassWithTag(SqPvClass & sub, StackStrF & tag);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Remove a unit with a certain identifier from this manager.
|
||||||
|
*/
|
||||||
|
void RemoveUnitWithID(SQInteger id);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Remove a unit with a certain tag from this manager.
|
||||||
|
*/
|
||||||
|
void RemoveUnitWithTag(StackStrF & tag);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
Loading…
Reference in New Issue
Block a user