2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
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;
|
|
|
|
}
|
|
|
|
|
2022-10-16 22:06:11 +00:00
|
|
|
void set_override_rollback_value(T const& value)
|
2019-07-25 13:21:16 +00:00
|
|
|
{
|
|
|
|
m_saved_value = value;
|
|
|
|
}
|
|
|
|
|
2019-06-03 17:52:31 +00:00
|
|
|
private:
|
|
|
|
T& m_variable;
|
|
|
|
T m_saved_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
#if USING_AK_GLOBALLY
|
2019-07-25 13:15:14 +00:00
|
|
|
using AK::ScopedValueRollback;
|
2022-11-26 11:18:30 +00:00
|
|
|
#endif
|