mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-20 17:17:13 +02:00
Various minor changes and fixes that were not pushed to the repository. Just random stuff.
This commit is contained in:
@ -1457,109 +1457,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* RAII approach to delete an instance of a class if not released.
|
||||
*/
|
||||
template < typename T > class AutoDelete
|
||||
{
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
T * m_Inst; // The managed instance.
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AutoDelete(T * inst)
|
||||
: m_Inst(inst)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
AutoDelete(const AutoDelete & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
AutoDelete(AutoDelete && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~AutoDelete()
|
||||
{
|
||||
if (m_Inst)
|
||||
{
|
||||
delete m_Inst;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
AutoDelete & operator = (const AutoDelete & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
AutoDelete & operator = (AutoDelete && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed instance.
|
||||
*/
|
||||
operator T * ()
|
||||
{
|
||||
return m_Inst;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit cast to the managed instance.
|
||||
*/
|
||||
operator const T * () const
|
||||
{
|
||||
return m_Inst;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Released the managed instance.
|
||||
*/
|
||||
void Release()
|
||||
{
|
||||
m_Inst = nullptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Released the managed instance.
|
||||
*/
|
||||
T * Grab()
|
||||
{
|
||||
T * ptr = m_Inst;
|
||||
m_Inst = nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the managed instance.
|
||||
*/
|
||||
T * Get()
|
||||
{
|
||||
return m_Inst;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the managed instance.
|
||||
*/
|
||||
const T * Get() const
|
||||
{
|
||||
return m_Inst;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the string representation of a certain type.
|
||||
*/
|
||||
@ -1570,32 +1467,6 @@ CSStr SqTypeName(SQObjectType type);
|
||||
*/
|
||||
String SqTypeName(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script object from the specified value on the default VM.
|
||||
*/
|
||||
template < typename T > Object MakeObject(const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(DefaultVM::Get(), v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script object from the specified value on the specified VM.
|
||||
*/
|
||||
template < typename T > Object MakeObject(HSQUIRRELVM vm, const T & v)
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(vm, v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(vm, -1).value;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script string instance from a buffer.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user