ScopedSetter sets value to given variable and when goes out of scope, reset its original state. More...
#include <scopedsetter.h>
Public Member Functions | |
ScopedSetter (T &variable, const T &value) | |
~ScopedSetter () | |
Private Attributes | |
T | m_origValue |
T & | m_variable |
ScopedSetter sets value to given variable and when goes out of scope, reset its original state.
Usage:
// assume bool member variable m_isSet == true ... std::cout << (m_isSet ? "true" : "false") << std::endl; // print 'true' { SCOPED_SETTER(bool, m_isSet, false); // false is required state std::cout << (m_isSet ? "true" : "false") << std::endl; // print 'false' } // end of scope - return orig state std::cout << (m_isSet ? "true" : "false") << std::endl; // print 'true'
Definition at line 24 of file scopedsetter.h.
ScopedSetter< T >::ScopedSetter | ( | T & | variable, | |
const T & | value | |||
) | [inline] |
Definition at line 27 of file scopedsetter.h.
References ScopedSetter< T >::m_variable.
ScopedSetter< T >::~ScopedSetter | ( | ) | [inline] |
Definition at line 34 of file scopedsetter.h.
References ScopedSetter< T >::m_origValue, and ScopedSetter< T >::m_variable.
T ScopedSetter< T >::m_origValue [private] |
Definition at line 41 of file scopedsetter.h.
Referenced by ScopedSetter< T >::~ScopedSetter().
T& ScopedSetter< T >::m_variable [private] |
Definition at line 40 of file scopedsetter.h.
Referenced by ScopedSetter< T >::ScopedSetter(), and ScopedSetter< T >::~ScopedSetter().