Public Member Functions | Private Attributes

ScopedSetter< T > Class Template Reference

ScopedSetter sets value to given variable and when goes out of scope, reset its original state. More...

#include <scopedsetter.h>

List of all members.

Public Member Functions

 ScopedSetter (T &variable, const T &value)
 ~ScopedSetter ()

Private Attributes

m_origValue
T & m_variable

Detailed Description

template<typename T>
class ScopedSetter< T >

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'
Author:
Milan Kriz (krizm7@fel.cvut.cz, milan.kriz@centrum.cz)

Definition at line 24 of file scopedsetter.h.


Constructor & Destructor Documentation

template<typename T>
ScopedSetter< T >::ScopedSetter ( T &  variable,
const T &  value 
) [inline]

Definition at line 27 of file scopedsetter.h.

References ScopedSetter< T >::m_variable.

template<typename T>
ScopedSetter< T >::~ScopedSetter (  )  [inline]

Definition at line 34 of file scopedsetter.h.

References ScopedSetter< T >::m_origValue, and ScopedSetter< T >::m_variable.


Member Data Documentation

template<typename T>
T ScopedSetter< T >::m_origValue [private]

Definition at line 41 of file scopedsetter.h.

Referenced by ScopedSetter< T >::~ScopedSetter().

template<typename T>
T& ScopedSetter< T >::m_variable [private]

The documentation for this class was generated from the following file: