3ds Max C++ API Reference
|
Resets a variable when the object goes out of scope. More...
#include <VariableGuard.h>
Public Member Functions | |
VariableGuard (T &variable) | |
Guards the given variable, restoring its value when this object instance goes out of scope. | |
VariableGuard (T &variable, const T &value) | |
Guards the given variable, and sets it to the specified value. | |
~VariableGuard () | |
Restores the variable to its original value. | |
const T & | GetCurrentValue () const |
Retrieves the current value of the guarded variable. | |
void | SetCurrentValue (const T &value) |
Sets the variable to the specified value. | |
const T & | GetRestoreValue () const |
Retrieves the original value of the guarded variable. | |
void | RestoreValue () |
Restores the variable to its original value Note that the variable will be restored again to its original value when the object instance goes out of scope. | |
Resets a variable when the object goes out of scope.
Following the principle of resource acquisition is allocation, this class, which should always be allocated on the stack, will set a variable to the given value, then set the variable back to its original value when it goes out of score. This is safer than setting things by hand since the destructor will still be executed if an exception is thrown from the guarded block. An example given a member variable mRecursionLocked:
|
inline |
Guards the given variable, restoring its value when this object instance goes out of scope.
variable | - the variable to be guarded (whose value needs to be restored) |
|
inline |
Guards the given variable, and sets it to the specified value.
The variable is restored to its original value when this object instance goes out of scope.
variable | - the variable to be guarded (whose value needs to be restored) |
value | - the new value the variable should be set to right away |
|
inline |
Restores the variable to its original value.
|
inline |
Retrieves the current value of the guarded variable.
|
inline |
Sets the variable to the specified value.
Upon this guard's destruction, the variable will be reset to the original value found during the guard's construction.
value | - the new value the variable should be set to |
|
inline |
Retrieves the original value of the guarded variable.
|
inline |
Restores the variable to its original value Note that the variable will be restored again to its original value when the object instance goes out of scope.