2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-06-03 20:52:31 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<typename T>
|
2019-07-25 16:15:14 +03:00
|
|
|
class ScopedValueRollback {
|
2019-06-03 20:52:31 +03:00
|
|
|
public:
|
2019-07-25 16:15:14 +03:00
|
|
|
ScopedValueRollback(T& variable)
|
2019-06-03 20:52:31 +03:00
|
|
|
: m_variable(variable)
|
|
|
|
, m_saved_value(variable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-07-25 16:15:14 +03:00
|
|
|
~ScopedValueRollback()
|
2019-06-03 20:52:31 +03:00
|
|
|
{
|
|
|
|
m_variable = m_saved_value;
|
|
|
|
}
|
|
|
|
|
2019-07-25 16:21:16 +03:00
|
|
|
void set_override_rollback_value(const T& value)
|
|
|
|
{
|
|
|
|
m_saved_value = value;
|
|
|
|
}
|
|
|
|
|
2019-06-03 20:52:31 +03:00
|
|
|
private:
|
|
|
|
T& m_variable;
|
|
|
|
T m_saved_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-25 16:15:14 +03:00
|
|
|
using AK::ScopedValueRollback;
|