2019-06-03 19:52:31 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<typename T>
|
2019-07-25 15:15:14 +02:00
|
|
|
class ScopedValueRollback {
|
2019-06-03 19:52:31 +02:00
|
|
|
public:
|
2019-07-25 15:15:14 +02:00
|
|
|
ScopedValueRollback(T& variable)
|
2019-06-03 19:52:31 +02:00
|
|
|
: m_variable(variable)
|
|
|
|
, m_saved_value(variable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:15:14 +02:00
|
|
|
~ScopedValueRollback()
|
2019-06-03 19:52:31 +02:00
|
|
|
{
|
|
|
|
m_variable = m_saved_value;
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:21:16 +02:00
|
|
|
void set_override_rollback_value(const T& value)
|
|
|
|
{
|
|
|
|
m_saved_value = value;
|
|
|
|
}
|
|
|
|
|
2019-06-03 19:52:31 +02:00
|
|
|
private:
|
|
|
|
T& m_variable;
|
|
|
|
T m_saved_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:15:14 +02:00
|
|
|
using AK::ScopedValueRollback;
|