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-02-06 15:01:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
#include <AK/Platform.h>
|
|
|
|
|
2019-02-06 15:01:59 +00:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class TemporaryChange {
|
|
|
|
public:
|
2019-05-28 09:53:16 +00:00
|
|
|
TemporaryChange(T& variable, T value)
|
|
|
|
: m_variable(variable)
|
2024-10-10 07:57:42 +00:00
|
|
|
, m_old_value(move(variable))
|
2019-05-28 09:53:16 +00:00
|
|
|
{
|
2024-10-10 07:57:42 +00:00
|
|
|
m_variable = move(value);
|
2019-05-28 09:53:16 +00:00
|
|
|
}
|
2024-10-10 07:57:42 +00:00
|
|
|
~TemporaryChange() { m_variable = move(m_old_value); }
|
2019-02-06 15:01:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
T& m_variable;
|
|
|
|
T m_old_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
#if USING_AK_GLOBALLY
|
2019-02-06 15:01:59 +00:00
|
|
|
using AK::TemporaryChange;
|
2022-11-26 11:18:30 +00:00
|
|
|
#endif
|