mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-21 20:27:13 +01:00
Implement arbitrary user data for signals.
This commit is contained in:
parent
5b39f7f061
commit
f54271a4fd
@ -26,6 +26,8 @@ void Signal::Terminate()
|
||||
s.second.mPtr->Clear();
|
||||
// Release the name
|
||||
s.second.mPtr->m_Name.clear();
|
||||
// Release whatever is in the user data
|
||||
s.second.mPtr->m_Data.Release();
|
||||
}
|
||||
// Finally clear the container itself
|
||||
s_Signals.clear();
|
||||
@ -36,6 +38,8 @@ void Signal::Terminate()
|
||||
{
|
||||
// Clear slots
|
||||
s->Clear();
|
||||
// Release whatever is in the user data
|
||||
s->m_Data.Release();
|
||||
}
|
||||
// Finally clear the container itself
|
||||
s_FreeSignals.clear();
|
||||
@ -246,6 +250,7 @@ void Register_Signal(HSQUIRRELVM vm)
|
||||
.SquirrelFunc(_SC("_typename"), &Signal::Typename)
|
||||
.Func(_SC("_tostring"), &Signal::ToString)
|
||||
// Core Properties
|
||||
.Prop(_SC("Data"), &Signal::GetData, &Signal::SetData)
|
||||
.Prop(_SC("Slots"), &Signal::Count)
|
||||
// Core Methods
|
||||
.Func(_SC("Clear"), &Signal::Clear)
|
||||
|
@ -341,13 +341,14 @@ private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Slot * m_Head; // The chain of slots bound to this signal.
|
||||
Object m_Data; // User data associated with this instance.
|
||||
String m_Name; // The name that identifies this signal.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
Signal()
|
||||
: m_Head(nullptr), m_Name()
|
||||
: m_Head(nullptr), m_Data(), m_Name()
|
||||
{
|
||||
s_FreeSignals.push_back(this);
|
||||
}
|
||||
@ -374,7 +375,7 @@ private:
|
||||
* Base constructor.
|
||||
*/
|
||||
Signal(String && name)
|
||||
: m_Head(nullptr), m_Name(std::move(name))
|
||||
: m_Head(nullptr), m_Data(), m_Name(std::move(name))
|
||||
{
|
||||
if (m_Name.empty())
|
||||
{
|
||||
@ -449,6 +450,22 @@ public:
|
||||
*/
|
||||
static SQInteger Typename(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user data.
|
||||
*/
|
||||
Object & GetData()
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user data.
|
||||
*/
|
||||
void SetData(Object & data)
|
||||
{
|
||||
m_Data = data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* The number of slots connected to the signal.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user