1
0
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:
Sandu Liviu Catalin 2016-11-04 01:31:49 +02:00
parent 5b39f7f061
commit f54271a4fd
2 changed files with 24 additions and 2 deletions

View File

@ -26,6 +26,8 @@ void Signal::Terminate()
s.second.mPtr->Clear(); s.second.mPtr->Clear();
// Release the name // Release the name
s.second.mPtr->m_Name.clear(); s.second.mPtr->m_Name.clear();
// Release whatever is in the user data
s.second.mPtr->m_Data.Release();
} }
// Finally clear the container itself // Finally clear the container itself
s_Signals.clear(); s_Signals.clear();
@ -36,6 +38,8 @@ void Signal::Terminate()
{ {
// Clear slots // Clear slots
s->Clear(); s->Clear();
// Release whatever is in the user data
s->m_Data.Release();
} }
// Finally clear the container itself // Finally clear the container itself
s_FreeSignals.clear(); s_FreeSignals.clear();
@ -246,6 +250,7 @@ void Register_Signal(HSQUIRRELVM vm)
.SquirrelFunc(_SC("_typename"), &Signal::Typename) .SquirrelFunc(_SC("_typename"), &Signal::Typename)
.Func(_SC("_tostring"), &Signal::ToString) .Func(_SC("_tostring"), &Signal::ToString)
// Core Properties // Core Properties
.Prop(_SC("Data"), &Signal::GetData, &Signal::SetData)
.Prop(_SC("Slots"), &Signal::Count) .Prop(_SC("Slots"), &Signal::Count)
// Core Methods // Core Methods
.Func(_SC("Clear"), &Signal::Clear) .Func(_SC("Clear"), &Signal::Clear)

View File

@ -341,13 +341,14 @@ private:
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
Slot * m_Head; // The chain of slots bound to this signal. 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. String m_Name; // The name that identifies this signal.
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Default constructor. * Default constructor.
*/ */
Signal() Signal()
: m_Head(nullptr), m_Name() : m_Head(nullptr), m_Data(), m_Name()
{ {
s_FreeSignals.push_back(this); s_FreeSignals.push_back(this);
} }
@ -374,7 +375,7 @@ private:
* Base constructor. * Base constructor.
*/ */
Signal(String && name) 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()) if (m_Name.empty())
{ {
@ -449,6 +450,22 @@ public:
*/ */
static SQInteger Typename(HSQUIRRELVM vm); 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. * The number of slots connected to the signal.
*/ */