mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-21 20:27:13 +01:00
Implement foreach entity algorithm that accepts a payload to send to the callback.
This commit is contained in:
parent
80612c4146
commit
0df1582ac6
@ -320,6 +320,22 @@ static inline Uint32 Player_EachWhereNameEquals(bool neg, bool cs, CSStr name, O
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name matches or not the specified one.
|
||||
*/
|
||||
static inline Uint32 Player_EachWhereNameEqualsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_NAME_STR(name)
|
||||
// Create a new element forwarder
|
||||
ForwardElemDataFunc< CPlayer > fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachEquals(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemDataFunc< CPlayer > >(fwd), name, !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name begins with the specified string.
|
||||
*/
|
||||
@ -336,6 +352,22 @@ static inline Uint32 Player_EachWhereNameBegins(bool neg, bool cs, CSStr name, O
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name begins with the specified string.
|
||||
*/
|
||||
static inline Uint32 Player_EachWhereNameBeginsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_NAME_STR(name)
|
||||
// Create a new element forwarder
|
||||
ForwardElemDataFunc< CPlayer > fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachBegins(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemDataFunc< CPlayer > >(fwd), name, strlen(name), !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name ends or not with the specified string.
|
||||
*/
|
||||
@ -352,6 +384,22 @@ static inline Uint32 Player_EachWhereNameEnds(bool neg, bool cs, CSStr name, Obj
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name ends or not with the specified string.
|
||||
*/
|
||||
static inline Uint32 Player_EachWhereNameEndsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_NAME_STR(name)
|
||||
// Create a new element forwarder
|
||||
ForwardElemDataFunc< CPlayer > fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachEnds(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemDataFunc< CPlayer > >(fwd), name, strlen(name), !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name contains the specified string.
|
||||
*/
|
||||
@ -368,6 +416,22 @@ static inline Uint32 Player_EachWhereNameContains(bool neg, bool cs, CSStr name,
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name contains the specified string.
|
||||
*/
|
||||
static inline Uint32 Player_EachWhereNameContainsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_NAME_STR(name)
|
||||
// Create a new element forwarder
|
||||
ForwardElemDataFunc< CPlayer > fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachContains(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemDataFunc< CPlayer > >(fwd), name, !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name matches the specified filter.
|
||||
*/
|
||||
@ -384,6 +448,22 @@ static inline Uint32 Player_EachWhereNameMatches(bool neg, bool cs, CSStr name,
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the name matches the specified filter.
|
||||
*/
|
||||
static inline Uint32 Player_EachWhereNameMatchesData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_NAME_STR(name)
|
||||
// Create a new element forwarder
|
||||
ForwardElemDataFunc< CPlayer > fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachMatches(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
|
||||
ValidInstFunc< CPlayer >(), PlayerName(),
|
||||
std::reference_wrapper< ForwardElemDataFunc< CPlayer > >(fwd), name, !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Count all entities of this type where the name matches or not the specified one.
|
||||
*/
|
||||
@ -615,71 +695,118 @@ void Register(HSQUIRRELVM vm)
|
||||
Table each_ns(vm);
|
||||
|
||||
each_ns.Bind(_SC("Blip"), Table(vm)
|
||||
.Func(_SC("Active"), &Entity< CBlip >::EachActive)
|
||||
.Func(_SC("TagEquals"), &Entity< CBlip >::EachWhereTagEquals)
|
||||
.Func(_SC("TagBegins"), &Entity< CBlip >::EachWhereTagBegins)
|
||||
.Func(_SC("TagEnds"), &Entity< CBlip >::EachWhereTagEnds)
|
||||
.Func(_SC("TagContains"), &Entity< CBlip >::EachWhereTagContains)
|
||||
.Func(_SC("TagMatches"), &Entity< CBlip >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CBlip >::EachActive)
|
||||
.Overload(_SC("TagEquals"), &Entity< CBlip >::EachWhereTagEquals)
|
||||
.Overload(_SC("TagBegins"), &Entity< CBlip >::EachWhereTagBegins)
|
||||
.Overload(_SC("TagEnds"), &Entity< CBlip >::EachWhereTagEnds)
|
||||
.Overload(_SC("TagContains"), &Entity< CBlip >::EachWhereTagContains)
|
||||
.Overload(_SC("TagMatches"), &Entity< CBlip >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CBlip >::EachActiveData)
|
||||
.Overload(_SC("TagEquals"), &Entity< CBlip >::EachWhereTagEqualsData)
|
||||
.Overload(_SC("TagBegins"), &Entity< CBlip >::EachWhereTagBeginsData)
|
||||
.Overload(_SC("TagEnds"), &Entity< CBlip >::EachWhereTagEndsData)
|
||||
.Overload(_SC("TagContains"), &Entity< CBlip >::EachWhereTagContainsData)
|
||||
.Overload(_SC("TagMatches"), &Entity< CBlip >::EachWhereTagMatchesData)
|
||||
);
|
||||
|
||||
each_ns.Bind(_SC("Checkpoint"), Table(vm)
|
||||
.Func(_SC("Active"), &Entity< CCheckpoint >::EachActive)
|
||||
.Func(_SC("TagEquals"), &Entity< CCheckpoint >::EachWhereTagEquals)
|
||||
.Func(_SC("TagBegins"), &Entity< CCheckpoint >::EachWhereTagBegins)
|
||||
.Func(_SC("TagEnds"), &Entity< CCheckpoint >::EachWhereTagEnds)
|
||||
.Func(_SC("TagContains"), &Entity< CCheckpoint >::EachWhereTagContains)
|
||||
.Func(_SC("TagMatches"), &Entity< CCheckpoint >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CCheckpoint >::EachActive)
|
||||
.Overload(_SC("TagEquals"), &Entity< CCheckpoint >::EachWhereTagEquals)
|
||||
.Overload(_SC("TagBegins"), &Entity< CCheckpoint >::EachWhereTagBegins)
|
||||
.Overload(_SC("TagEnds"), &Entity< CCheckpoint >::EachWhereTagEnds)
|
||||
.Overload(_SC("TagContains"), &Entity< CCheckpoint >::EachWhereTagContains)
|
||||
.Overload(_SC("TagMatches"), &Entity< CCheckpoint >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CCheckpoint >::EachActiveData)
|
||||
.Overload(_SC("TagEquals"), &Entity< CCheckpoint >::EachWhereTagEqualsData)
|
||||
.Overload(_SC("TagBegins"), &Entity< CCheckpoint >::EachWhereTagBeginsData)
|
||||
.Overload(_SC("TagEnds"), &Entity< CCheckpoint >::EachWhereTagEndsData)
|
||||
.Overload(_SC("TagContains"), &Entity< CCheckpoint >::EachWhereTagContainsData)
|
||||
.Overload(_SC("TagMatches"), &Entity< CCheckpoint >::EachWhereTagMatchesData)
|
||||
);
|
||||
|
||||
each_ns.Bind(_SC("Keybind"), Table(vm)
|
||||
.Func(_SC("Active"), &Entity< CKeybind >::EachActive)
|
||||
.Func(_SC("TagEquals"), &Entity< CKeybind >::EachWhereTagEquals)
|
||||
.Func(_SC("TagBegins"), &Entity< CKeybind >::EachWhereTagBegins)
|
||||
.Func(_SC("TagEnds"), &Entity< CKeybind >::EachWhereTagEnds)
|
||||
.Func(_SC("TagContains"), &Entity< CKeybind >::EachWhereTagContains)
|
||||
.Func(_SC("TagMatches"), &Entity< CKeybind >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CKeybind >::EachActive)
|
||||
.Overload(_SC("TagEquals"), &Entity< CKeybind >::EachWhereTagEquals)
|
||||
.Overload(_SC("TagBegins"), &Entity< CKeybind >::EachWhereTagBegins)
|
||||
.Overload(_SC("TagEnds"), &Entity< CKeybind >::EachWhereTagEnds)
|
||||
.Overload(_SC("TagContains"), &Entity< CKeybind >::EachWhereTagContains)
|
||||
.Overload(_SC("TagMatches"), &Entity< CKeybind >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CKeybind >::EachActiveData)
|
||||
.Overload(_SC("TagEquals"), &Entity< CKeybind >::EachWhereTagEqualsData)
|
||||
.Overload(_SC("TagBegins"), &Entity< CKeybind >::EachWhereTagBeginsData)
|
||||
.Overload(_SC("TagEnds"), &Entity< CKeybind >::EachWhereTagEndsData)
|
||||
.Overload(_SC("TagContains"), &Entity< CKeybind >::EachWhereTagContainsData)
|
||||
.Overload(_SC("TagMatches"), &Entity< CKeybind >::EachWhereTagMatchesData)
|
||||
);
|
||||
|
||||
each_ns.Bind(_SC("Object"), Table(vm)
|
||||
.Func(_SC("Active"), &Entity< CObject >::EachActive)
|
||||
.Func(_SC("TagEquals"), &Entity< CObject >::EachWhereTagEquals)
|
||||
.Func(_SC("TagBegins"), &Entity< CObject >::EachWhereTagBegins)
|
||||
.Func(_SC("TagEnds"), &Entity< CObject >::EachWhereTagEnds)
|
||||
.Func(_SC("TagContains"), &Entity< CObject >::EachWhereTagContains)
|
||||
.Func(_SC("TagMatches"), &Entity< CObject >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CObject >::EachActive)
|
||||
.Overload(_SC("TagEquals"), &Entity< CObject >::EachWhereTagEquals)
|
||||
.Overload(_SC("TagBegins"), &Entity< CObject >::EachWhereTagBegins)
|
||||
.Overload(_SC("TagEnds"), &Entity< CObject >::EachWhereTagEnds)
|
||||
.Overload(_SC("TagContains"), &Entity< CObject >::EachWhereTagContains)
|
||||
.Overload(_SC("TagMatches"), &Entity< CObject >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CObject >::EachActiveData)
|
||||
.Overload(_SC("TagEquals"), &Entity< CObject >::EachWhereTagEqualsData)
|
||||
.Overload(_SC("TagBegins"), &Entity< CObject >::EachWhereTagBeginsData)
|
||||
.Overload(_SC("TagEnds"), &Entity< CObject >::EachWhereTagEndsData)
|
||||
.Overload(_SC("TagContains"), &Entity< CObject >::EachWhereTagContainsData)
|
||||
.Overload(_SC("TagMatches"), &Entity< CObject >::EachWhereTagMatchesData)
|
||||
);
|
||||
|
||||
each_ns.Bind(_SC("Pickup"), Table(vm)
|
||||
.Func(_SC("Active"), &Entity< CPickup >::EachActive)
|
||||
.Func(_SC("TagEquals"), &Entity< CPickup >::EachWhereTagEquals)
|
||||
.Func(_SC("TagBegins"), &Entity< CPickup >::EachWhereTagBegins)
|
||||
.Func(_SC("TagEnds"), &Entity< CPickup >::EachWhereTagEnds)
|
||||
.Func(_SC("TagContains"), &Entity< CPickup >::EachWhereTagContains)
|
||||
.Func(_SC("TagMatches"), &Entity< CPickup >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CPickup >::EachActive)
|
||||
.Overload(_SC("TagEquals"), &Entity< CPickup >::EachWhereTagEquals)
|
||||
.Overload(_SC("TagBegins"), &Entity< CPickup >::EachWhereTagBegins)
|
||||
.Overload(_SC("TagEnds"), &Entity< CPickup >::EachWhereTagEnds)
|
||||
.Overload(_SC("TagContains"), &Entity< CPickup >::EachWhereTagContains)
|
||||
.Overload(_SC("TagMatches"), &Entity< CPickup >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CPickup >::EachActiveData)
|
||||
.Overload(_SC("TagEquals"), &Entity< CPickup >::EachWhereTagEqualsData)
|
||||
.Overload(_SC("TagBegins"), &Entity< CPickup >::EachWhereTagBeginsData)
|
||||
.Overload(_SC("TagEnds"), &Entity< CPickup >::EachWhereTagEndsData)
|
||||
.Overload(_SC("TagContains"), &Entity< CPickup >::EachWhereTagContainsData)
|
||||
.Overload(_SC("TagMatches"), &Entity< CPickup >::EachWhereTagMatchesData)
|
||||
);
|
||||
|
||||
each_ns.Bind(_SC("Player"), Table(vm)
|
||||
.Func(_SC("Active"), &Entity< CPlayer >::EachActive)
|
||||
.Func(_SC("TagEquals"), &Entity< CPlayer >::EachWhereTagEquals)
|
||||
.Func(_SC("TagBegins"), &Entity< CPlayer >::EachWhereTagBegins)
|
||||
.Func(_SC("TagEnds"), &Entity< CPlayer >::EachWhereTagEnds)
|
||||
.Func(_SC("TagContains"), &Entity< CPlayer >::EachWhereTagContains)
|
||||
.Func(_SC("TagMatches"), &Entity< CPlayer >::EachWhereTagMatches)
|
||||
.Func(_SC("NameEquals"), &Player_EachWhereNameEquals)
|
||||
.Func(_SC("NameBegins"), &Player_EachWhereNameBegins)
|
||||
.Func(_SC("NameEnds"), &Player_EachWhereNameEnds)
|
||||
.Func(_SC("NameContains"), &Player_EachWhereNameContains)
|
||||
.Func(_SC("NameMatches"), &Player_EachWhereNameMatches)
|
||||
.Overload(_SC("Active"), &Entity< CPlayer >::EachActive)
|
||||
.Overload(_SC("TagEquals"), &Entity< CPlayer >::EachWhereTagEquals)
|
||||
.Overload(_SC("TagBegins"), &Entity< CPlayer >::EachWhereTagBegins)
|
||||
.Overload(_SC("TagEnds"), &Entity< CPlayer >::EachWhereTagEnds)
|
||||
.Overload(_SC("TagContains"), &Entity< CPlayer >::EachWhereTagContains)
|
||||
.Overload(_SC("TagMatches"), &Entity< CPlayer >::EachWhereTagMatches)
|
||||
.Overload(_SC("NameEquals"), &Player_EachWhereNameEquals)
|
||||
.Overload(_SC("NameBegins"), &Player_EachWhereNameBegins)
|
||||
.Overload(_SC("NameEnds"), &Player_EachWhereNameEnds)
|
||||
.Overload(_SC("NameContains"), &Player_EachWhereNameContains)
|
||||
.Overload(_SC("NameMatches"), &Player_EachWhereNameMatches)
|
||||
.Overload(_SC("Active"), &Entity< CPlayer >::EachActiveData)
|
||||
.Overload(_SC("TagEquals"), &Entity< CPlayer >::EachWhereTagEqualsData)
|
||||
.Overload(_SC("TagBegins"), &Entity< CPlayer >::EachWhereTagBeginsData)
|
||||
.Overload(_SC("TagEnds"), &Entity< CPlayer >::EachWhereTagEndsData)
|
||||
.Overload(_SC("TagContains"), &Entity< CPlayer >::EachWhereTagContainsData)
|
||||
.Overload(_SC("TagMatches"), &Entity< CPlayer >::EachWhereTagMatchesData)
|
||||
.Overload(_SC("NameEquals"), &Player_EachWhereNameEqualsData)
|
||||
.Overload(_SC("NameBegins"), &Player_EachWhereNameBeginsData)
|
||||
.Overload(_SC("NameEnds"), &Player_EachWhereNameEndsData)
|
||||
.Overload(_SC("NameContains"), &Player_EachWhereNameContainsData)
|
||||
.Overload(_SC("NameMatches"), &Player_EachWhereNameMatchesData)
|
||||
);
|
||||
|
||||
each_ns.Bind(_SC("Vehicle"), Table(vm)
|
||||
.Func(_SC("Active"), &Entity< CVehicle >::EachActive)
|
||||
.Func(_SC("TagEquals"), &Entity< CVehicle >::EachWhereTagEquals)
|
||||
.Func(_SC("TagBegins"), &Entity< CVehicle >::EachWhereTagBegins)
|
||||
.Func(_SC("TagEnds"), &Entity< CVehicle >::EachWhereTagEnds)
|
||||
.Func(_SC("TagContains"), &Entity< CVehicle >::EachWhereTagContains)
|
||||
.Func(_SC("TagMatches"), &Entity< CVehicle >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CVehicle >::EachActive)
|
||||
.Overload(_SC("TagEquals"), &Entity< CVehicle >::EachWhereTagEquals)
|
||||
.Overload(_SC("TagBegins"), &Entity< CVehicle >::EachWhereTagBegins)
|
||||
.Overload(_SC("TagEnds"), &Entity< CVehicle >::EachWhereTagEnds)
|
||||
.Overload(_SC("TagContains"), &Entity< CVehicle >::EachWhereTagContains)
|
||||
.Overload(_SC("TagMatches"), &Entity< CVehicle >::EachWhereTagMatches)
|
||||
.Overload(_SC("Active"), &Entity< CVehicle >::EachActiveData)
|
||||
.Overload(_SC("TagEquals"), &Entity< CVehicle >::EachWhereTagEqualsData)
|
||||
.Overload(_SC("TagBegins"), &Entity< CVehicle >::EachWhereTagBeginsData)
|
||||
.Overload(_SC("TagEnds"), &Entity< CVehicle >::EachWhereTagEndsData)
|
||||
.Overload(_SC("TagContains"), &Entity< CVehicle >::EachWhereTagContainsData)
|
||||
.Overload(_SC("TagMatches"), &Entity< CVehicle >::EachWhereTagMatchesData)
|
||||
);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqForeach"), each_ns);
|
||||
|
@ -885,6 +885,96 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Functor to forward the the received element and specific payload to a callback.
|
||||
*/
|
||||
template < typename T > struct ForwardElemDataFunc
|
||||
{
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Function mFunc; // The script callback to forward the element.
|
||||
Object mData; // The script payload to accompany the element.
|
||||
Uint32 mCount; // The number of elements forwarded by this functor.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
ForwardElemDataFunc(Object & data, Object & env, Function & func)
|
||||
: mFunc(env.IsNull() ? func : Function(env.GetVM(), env, func.GetFunc())), mData(data), mCount(0)
|
||||
{
|
||||
if (mFunc.IsNull())
|
||||
{
|
||||
STHROWF("Invalid script callback");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Function call operator.
|
||||
*/
|
||||
void operator () (const typename InstSpec< T >::Instance & inst)
|
||||
{
|
||||
mFunc.Execute(inst.mObj, mData);
|
||||
++mCount; // Only successful forwards are counted!
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed function.
|
||||
*/
|
||||
operator Function ()
|
||||
{
|
||||
return mFunc;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed function.
|
||||
*/
|
||||
operator Function & ()
|
||||
{
|
||||
return mFunc;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed function.
|
||||
*/
|
||||
operator const Function & () const
|
||||
{
|
||||
return mFunc;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed payload.
|
||||
*/
|
||||
operator Object ()
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed payload.
|
||||
*/
|
||||
operator Object & ()
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed payload.
|
||||
*/
|
||||
operator const Object & () const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the count value.
|
||||
*/
|
||||
operator Uint32 () const
|
||||
{
|
||||
return mCount;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Functor to count the the received elements.
|
||||
*/
|
||||
@ -933,12 +1023,13 @@ public:
|
||||
typedef InstSpec< T > Inst; // The type of entity instance to work with.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef ValidInstFunc< T > ValidInst;
|
||||
typedef InstTagFunc< T > InstTag;
|
||||
typedef AppendElemFunc< T > AppendElem;
|
||||
typedef RecvElemFunc< T > RecvElem;
|
||||
typedef ForwardElemFunc< T > ForwardElem;
|
||||
typedef CountElemFunc< T > CountElem;
|
||||
typedef ValidInstFunc< T > ValidInst;
|
||||
typedef InstTagFunc< T > InstTag;
|
||||
typedef AppendElemFunc< T > AppendElem;
|
||||
typedef RecvElemFunc< T > RecvElem;
|
||||
typedef ForwardElemFunc< T > ForwardElem;
|
||||
typedef ForwardElemDataFunc< T > ForwardElemData;
|
||||
typedef CountElemFunc< T > CountElem;
|
||||
|
||||
public:
|
||||
|
||||
@ -1181,6 +1272,20 @@ public:
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all active entities of this type.
|
||||
*/
|
||||
static inline Uint32 EachActiveData(Object & data, Object & env, Function & func)
|
||||
{
|
||||
// Create a new element forwarder
|
||||
ForwardElemData fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
Collect(Inst::CBegin(), Inst::CEnd(), ValidInst(),
|
||||
std::reference_wrapper< ForwardElemData >(fwd));
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag matches or not the specified one.
|
||||
*/
|
||||
@ -1196,6 +1301,21 @@ public:
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag matches or not the specified one.
|
||||
*/
|
||||
static inline Uint32 EachWhereTagEqualsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_TAG_STR(tag)
|
||||
// Create a new element forwarder
|
||||
ForwardElemData fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElemData >(fwd), tag, !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag begins with the specified string.
|
||||
*/
|
||||
@ -1211,6 +1331,21 @@ public:
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag begins with the specified string.
|
||||
*/
|
||||
static inline Uint32 EachWhereTagBeginsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_TAG_STR(tag)
|
||||
// Create a new element forwarder
|
||||
ForwardElemData fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElemData >(fwd), tag, strlen(tag), !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag ends or not with the specified string.
|
||||
*/
|
||||
@ -1226,6 +1361,21 @@ public:
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag ends or not with the specified string.
|
||||
*/
|
||||
static inline Uint32 EachWhereTagEndsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_TAG_STR(tag)
|
||||
// Create a new element forwarder
|
||||
ForwardElemData fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElemData >(fwd), tag, strlen(tag), !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag contains the specified string.
|
||||
*/
|
||||
@ -1241,6 +1391,21 @@ public:
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag contains the specified string.
|
||||
*/
|
||||
static inline Uint32 EachWhereTagContainsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_TAG_STR(tag)
|
||||
// Create a new element forwarder
|
||||
ForwardElemData fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElemData >(fwd), tag, !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag match the specified filter.
|
||||
*/
|
||||
@ -1256,6 +1421,21 @@ public:
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all entities of this type where the tag match the specified filter.
|
||||
*/
|
||||
static inline Uint32 EachWhereTagMatchesData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
|
||||
{
|
||||
SQMOD_VALID_TAG_STR(tag)
|
||||
// Create a new element forwarder
|
||||
ForwardElemData fwd(data, env, func);
|
||||
// Process each entity in the pool
|
||||
EachMatches(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(),
|
||||
std::reference_wrapper< ForwardElemData >(fwd), tag, !neg, cs);
|
||||
// Return the forward count
|
||||
return fwd.mCount;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Count all active entities of this type.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user