Auto Restore Class
CAutoRestore is a simple class that saves the value of a variable and restores the variable once it goes out of scope. CAutoRestore is useful for situations such as setting and automatically restoring reentrancy flags.
To use auto restore, simply declare it and pass a reference to the variable to be restored and a new value for the variable:
CAutoRestore<bool> bSave(m_bReentrancyFlag, true);
This example will save the current value of m_bReentrancyFlag and set it to true. Once bSave goes out of scope (say on leaving the function), m_bReentrancyFlag will be set back to its original value.