Saves a variable reference at construction time to restore/set its value at destruction time. More...
#include "keyvalue/util/NullDeleter.h"
Public Member Functions | |
Saver (SavedType &data) | |
Constructs a Saver for a variable. | |
Saver (SavedType &data, const SavedType &onExit) | |
Constructs a Saver for a variable and sets the value it will get at time the of Saver's destruction. | |
SavedType | getSaved () const |
Gets saved value. | |
Private Attributes | |
SavedType & | data_ |
SavedType | onExit_ |
Saves a variable reference at construction time to restore/set its value at destruction time.
This class
applies Stroustrup's RAII technique to reset a (probably, static) variable when Saver go out of scope. The variable can be reset to the value it had when Saver was constructed or set to another given value.
SavedType | : (template parameter) The type of saved value. |
Saver | ( | SavedType & | data | ) | [inline, explicit] |
Constructs a Saver for a variable.
data | : the variable to be saved. |
Saver | ( | SavedType & | data, | |
const SavedType & | onExit | |||
) | [inline] |