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