openMSX
ScopedAssign.hh
Go to the documentation of this file.
1 #ifndef SCOPEDASSIGN_HH
2 #define SCOPEDASSIGN_HH
3 
7 template <typename T> class ScopedAssign
8 {
9 public:
10  ScopedAssign(T& var_, T newValue)
11  : var(var_)
12  {
13  oldValue = var;
14  var = newValue;
15  }
17  {
18  var = oldValue;
19  }
20 private:
21  T& var;
22  T oldValue;
23 };
24 
25 #endif
ScopedAssign(T &var_, T newValue)
Definition: ScopedAssign.hh:10
Assign new value to some variable and restore the original value when this object goes out of scope...
Definition: ScopedAssign.hh:7