diff --git a/shared/Base/Utility.hpp b/shared/Base/Utility.hpp index 85518b8a..3cfffeaa 100644 --- a/shared/Base/Utility.hpp +++ b/shared/Base/Utility.hpp @@ -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. */ diff --git a/source/Base/Shared.hpp b/source/Base/Shared.hpp index dda3bc40..ee592ef7 100644 --- a/source/Base/Shared.hpp +++ b/source/Base/Shared.hpp @@ -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. */