mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Move the auto assign helper class to the shared utility header.
This commit is contained in:
parent
64416c093c
commit
d95f3253d4
@ -1286,6 +1286,82 @@ typedef BitGuard< Uint8 > BitGuardU8;
|
||||
typedef BitGuard< Uint16 > BitGuardU16;
|
||||
typedef BitGuard< Uint32 > BitGuardU32;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* RAII approach to make sure a value is assigned regardless of what exceptions are thrown.
|
||||
*/
|
||||
template < typename T > class AutoAssign
|
||||
{
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
T & m_Var; // Variable to receive the value.
|
||||
T m_Val; // Value to be assigned.
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AutoAssign(T & variable, T value)
|
||||
: m_Var(variable), m_Val(value)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AutoAssign(T & variable, T value, T start)
|
||||
: m_Var(variable), m_Val(value)
|
||||
{
|
||||
m_Var = start;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
AutoAssign(const AutoAssign & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
AutoAssign(AutoAssign && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~AutoAssign()
|
||||
{
|
||||
m_Var = m_Val;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
AutoAssign & operator = (const AutoAssign & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
AutoAssign & operator = (AutoAssign && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Direct value assignment.
|
||||
*/
|
||||
template < typename U > AutoAssign & operator = (U value)
|
||||
{
|
||||
m_Var = value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Direct value assignment.
|
||||
*/
|
||||
template < typename U > void Set(U value)
|
||||
{
|
||||
m_Val = value;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Implements RAII to restore the VM stack to it's initial size on function exit.
|
||||
*/
|
||||
|
@ -311,82 +311,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* RAII approach to make sure a value is assigned regardless of what exceptions are thrown.
|
||||
*/
|
||||
template < typename T > class AutoAssign
|
||||
{
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
T & m_Var; // Variable to receive the value.
|
||||
T m_Val; // Value to be assigned.
|
||||
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AutoAssign(T & variable, T value)
|
||||
: m_Var(variable), m_Val(value)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AutoAssign(T & variable, T value, T start)
|
||||
: m_Var(variable), m_Val(value)
|
||||
{
|
||||
m_Var = start;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
AutoAssign(const AutoAssign & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
AutoAssign(AutoAssign && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~AutoAssign()
|
||||
{
|
||||
m_Var = m_Val;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
AutoAssign & operator = (const AutoAssign & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
AutoAssign & operator = (AutoAssign && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Direct value assignment.
|
||||
*/
|
||||
template < typename U > AutoAssign & operator = (U value)
|
||||
{
|
||||
m_Var = value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Direct value assignment.
|
||||
*/
|
||||
template < typename U > void Set(U value)
|
||||
{
|
||||
m_Var = value;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Retrieve the string delimiter of a base type.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user