2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-10-17 00:06:11 +02:00
|
|
|
void set_override_rollback_value(T const& value)
|
2019-07-25 15:21:16 +02:00
|
|
|
{
|
|
|
|
m_saved_value = value;
|
|
|
|
}
|
|
|
|
|
2019-06-03 19:52:31 +02:00
|
|
|
private:
|
|
|
|
T& m_variable;
|
|
|
|
T m_saved_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-26 12:18:30 +01:00
|
|
|
#if USING_AK_GLOBALLY
|
2019-07-25 15:15:14 +02:00
|
|
|
using AK::ScopedValueRollback;
|
2022-11-26 12:18:30 +01:00
|
|
|
#endif
|