mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Adjust the smart pointers in the Sqrat library.
Do not overwrite command listener options inc constructor. Few other minor changes.
This commit is contained in:
parent
749f232d06
commit
a373682cee
@ -886,7 +886,7 @@ public:
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
operator bool () const
|
||||
{
|
||||
return m_Ptr != NULL;
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -895,7 +895,7 @@ public:
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
bool operator!() const
|
||||
{
|
||||
return m_Ptr == NULL;
|
||||
return !m_Ptr;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1044,7 +1044,7 @@ public:
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Gets the number of referencesd to the underlying pointer
|
||||
/// Gets the number of references to the underlying pointer
|
||||
///
|
||||
/// \return Number of references
|
||||
///
|
||||
@ -1351,24 +1351,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Checks if there is an associated managed object
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
operator bool () const
|
||||
{
|
||||
return m_Ptr != NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Checks if there is NOT an associated managed object
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
bool operator!() const
|
||||
{
|
||||
return m_Ptr == NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Checks whether the managed object exists
|
||||
///
|
||||
@ -1422,6 +1404,17 @@ public:
|
||||
m_RefCountRefCount = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Gets the number of weak references to the underlying pointer
|
||||
///
|
||||
/// \return Number of references
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
unsigned int Count() const
|
||||
{
|
||||
return m_RefCountRefCount ? *m_RefCountRefCount : 0;
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -49,7 +49,7 @@ Command::~Command()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object & Controller::Attach(Object & obj, Listener * ptr)
|
||||
Object & Controller::Attach(Object && obj, Listener * ptr)
|
||||
{
|
||||
// Is there anything that we can attach
|
||||
if (obj.IsNull() && ptr == nullptr)
|
||||
@ -102,7 +102,7 @@ Object & Controller::Attach(Object & obj, Listener * ptr)
|
||||
}
|
||||
}
|
||||
// Attempt to insert the command
|
||||
m_Commands.emplace_back(hash, name, ptr, obj);
|
||||
m_Commands.emplace_back(hash, name, ptr, std::move(obj));
|
||||
// Attempt to associate with the listener
|
||||
if (m_Manager)
|
||||
{
|
||||
@ -140,7 +140,7 @@ Object Manager::Create(CSStr name, CSStr spec, Array & tags, Uint8 min, Uint8 ma
|
||||
// Attempt to attach the command listener to the controller
|
||||
Object & o = m_Controller->Attach(obj, ptr);
|
||||
// Return the script object
|
||||
return o;
|
||||
return o;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -1022,6 +1022,7 @@ void Register(HSQUIRRELVM vm)
|
||||
.Func(_SC("_tostring"), &Manager::ToString)
|
||||
// Member Properties
|
||||
.Prop(_SC("Count"), &Manager::GetCount)
|
||||
.Prop(_SC("References"), &Manager::GetRefCount)
|
||||
.Prop(_SC("IsContext"), &Manager::IsContext)
|
||||
.Prop(_SC("OnFail"), &Manager::GetOnFail)
|
||||
.Prop(_SC("OnAuth"), &Manager::GetOnAuth)
|
||||
@ -1064,6 +1065,7 @@ void Register(HSQUIRRELVM vm)
|
||||
.SquirrelFunc(_SC("_typename"), &Listener::Typename)
|
||||
.Func(_SC("_tostring"), &Listener::ToString)
|
||||
// Member Properties
|
||||
.Prop(_SC("References"), &Listener::GetRefCount)
|
||||
.Prop(_SC("Attached"), &Listener::Attached)
|
||||
.Prop(_SC("Manager"), &Listener::GetManager)
|
||||
.Prop(_SC("Name"), &Listener::GetName, &Listener::SetName)
|
||||
|
@ -278,6 +278,15 @@ struct Command
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct a command and extract the listener from the specified script object.
|
||||
*/
|
||||
Command(std::size_t hash, const String & name, Object && obj)
|
||||
: mHash(hash), mName(name), mPtr(obj.Cast< Listener * >()), mObj(obj)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct a command with the given parameters.
|
||||
*/
|
||||
@ -287,6 +296,15 @@ struct Command
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct a command with the given parameters.
|
||||
*/
|
||||
Command(std::size_t hash, const String & name, Listener * ptr, Object && obj)
|
||||
: mHash(hash), mName(name), mPtr(ptr), mObj(obj)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
@ -416,7 +434,23 @@ protected:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach a command listener to a certain name.
|
||||
*/
|
||||
Object & Attach(Object & obj, Listener * ptr);
|
||||
Object & Attach(Object & obj, Listener * ptr)
|
||||
{
|
||||
return Attach(Object(obj), ptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach a command listener to a certain name.
|
||||
*/
|
||||
Object & Attach(const Object & obj, Listener * ptr)
|
||||
{
|
||||
return Attach(Object(obj), ptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach a command listener to a certain name.
|
||||
*/
|
||||
Object & Attach(Object && obj, Listener * ptr);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Detach a command listener from a certain name.
|
||||
@ -765,6 +799,14 @@ public:
|
||||
return m_Controller;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of references to the managed controller.
|
||||
*/
|
||||
Uint32 GetRefCount() const
|
||||
{
|
||||
return m_Controller.Count();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Run a command under a specific invoker.
|
||||
*/
|
||||
@ -1056,14 +1098,6 @@ public:
|
||||
// Set the specified minimum and maximum allowed arguments
|
||||
SetMinArgC(min);
|
||||
SetMaxArgC(max);
|
||||
// Default to no authority check
|
||||
m_Authority = -1;
|
||||
// Default to unprotected command
|
||||
m_Protected = false;
|
||||
// Default to unsuspended command
|
||||
m_Suspended = false;
|
||||
// Default to non-associative arguments
|
||||
m_Associate = false;
|
||||
// Generate information for the command
|
||||
GenerateInfo(false);
|
||||
}
|
||||
@ -1137,6 +1171,14 @@ public:
|
||||
*/
|
||||
static SQInteger Typename(HSQUIRRELVM vm);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of weak references to the managed controller.
|
||||
*/
|
||||
Uint32 GetRefCount() const
|
||||
{
|
||||
return m_Controller.Count();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attach the listener instance to the associated command name.
|
||||
*/
|
||||
@ -1186,7 +1228,7 @@ public:
|
||||
Object GetManager() const
|
||||
{
|
||||
// Are we even associated with a controller?
|
||||
if (!m_Controller)
|
||||
if (m_Controller.Expired())
|
||||
{
|
||||
return NullObject(); // Default to null
|
||||
}
|
||||
@ -1489,7 +1531,7 @@ public:
|
||||
void SetOnExec(Object & env, Function & func)
|
||||
{
|
||||
// Make sure that we are allowed to store script resources
|
||||
if (!m_Controller)
|
||||
if (m_Controller.Expired())
|
||||
{
|
||||
STHROWF("Detached commands cannot store script resources");
|
||||
}
|
||||
@ -1511,7 +1553,7 @@ public:
|
||||
void SetOnAuth(Object & env, Function & func)
|
||||
{
|
||||
// Make sure that we are allowed to store script resources
|
||||
if (!m_Controller)
|
||||
if (m_Controller.Expired())
|
||||
{
|
||||
STHROWF("Detached commands cannot store script resources");
|
||||
}
|
||||
@ -1533,7 +1575,7 @@ public:
|
||||
void SetOnPost(Object & env, Function & func)
|
||||
{
|
||||
// Make sure that we are allowed to store script resources
|
||||
if (!m_Controller)
|
||||
if (m_Controller.Expired())
|
||||
{
|
||||
STHROWF("Detached listeners cannot store script resources");
|
||||
}
|
||||
@ -1555,7 +1597,7 @@ public:
|
||||
void SetOnFail(Object & env, Function & func)
|
||||
{
|
||||
// Make sure that we are allowed to store script resources
|
||||
if (!m_Controller)
|
||||
if (m_Controller.Expired())
|
||||
{
|
||||
STHROWF("Detached listeners cannot store script resources");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user