Public Member Functions | Private Attributes

Saver< SavedType > Class Template Reference

Saves a variable reference at construction time to restore/set its value at destruction time. More...

List of all members.

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_

Detailed Description

template<typename SavedType>
class keyvalue::util::Saver< SavedType >

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.

Parameters:
SavedType : (template parameter) The type of saved value.

Constructor & Destructor Documentation

Saver ( SavedType &  data  )  [explicit]

Constructs a Saver for a variable.

Parameters:
data : the variable to be saved.
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.

Parameters:
data : the variable to be saved.
onExit : the value that data is set to when Saver is destroyed.

Member Function Documentation

SavedType getSaved (  )  const

Gets saved value.

Returns:
The value.