Qt 4.8
Public Functions | Properties | List of all members
QScopedValueRollback< T > Class Template Reference

The QScopedValueRollback class resets a variable to its previous value on destruction. More...

#include <qscopedvaluerollback.h>

Public Functions

void commit ()
 Updates the previous value of the managed variable to its current value. More...
 
 QScopedValueRollback (T &var)
 Stores the previous value of var internally, for revert on destruction. More...
 
 ~QScopedValueRollback ()
 Assigns the previous value to the managed variable. More...
 

Properties

oldValue
 
T & varRef
 

Detailed Description

template<typename T>
class QScopedValueRollback< T >

The QScopedValueRollback class resets a variable to its previous value on destruction.

Since
4.8

The QScopedAssignment class can be used to revert state when an exception is thrown without needing to write try-catch blocks.

It can also be used to manage variables that are temporarily set, such as reentrancy guards. By using this class, the variable will be reset whether the function is exited normally, exited early by a return statement, or exited by an exception.

The template can only be instantiated with a type that supports assignment.

See also
QScopedPointer

Definition at line 52 of file qscopedvaluerollback.h.

Constructors and Destructors

◆ QScopedValueRollback()

template<typename T>
QScopedValueRollback< T >::QScopedValueRollback ( T &  var)
inline

Stores the previous value of var internally, for revert on destruction.

Definition at line 55 of file qscopedvaluerollback.h.

55  :
56  varRef(var)
57  {
58  oldValue = varRef;
59  }

◆ ~QScopedValueRollback()

template<typename T>
QScopedValueRollback< T >::~QScopedValueRollback ( )
inline

Assigns the previous value to the managed variable.

This is the value at construction time, or at the last call to commit()

Definition at line 61 of file qscopedvaluerollback.h.

Functions

◆ commit()

template<typename T>
void QScopedValueRollback< T >::commit ( )
inline

Updates the previous value of the managed variable to its current value.

Definition at line 66 of file qscopedvaluerollback.h.

Properties

◆ oldValue

template<typename T>
T QScopedValueRollback< T >::oldValue
private

◆ varRef

template<typename T>
T& QScopedValueRollback< T >::varRef
private

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