2020-04-20 03:00:37 +08:00
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
|
2019-01-20 05:06:05 +08:00
|
|
|
#ifndef FTXUI_UTIL_AUTORESET_HPP
|
|
|
|
#define FTXUI_UTIL_AUTORESET_HPP
|
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
2020-03-24 04:26:00 +08:00
|
|
|
template <typename T>
|
2019-01-20 05:06:05 +08:00
|
|
|
class AutoReset {
|
|
|
|
public:
|
|
|
|
AutoReset(T* variable, T new_value)
|
2020-03-24 04:26:00 +08:00
|
|
|
: variable_(variable), previous_value_(std::move(*variable)) {
|
2019-01-20 05:06:05 +08:00
|
|
|
*variable_ = std::move(new_value);
|
|
|
|
}
|
|
|
|
~AutoReset() { *variable_ = std::move(previous_value_); }
|
2020-03-24 04:26:00 +08:00
|
|
|
|
2019-01-20 05:06:05 +08:00
|
|
|
private:
|
|
|
|
T* variable_;
|
|
|
|
T previous_value_;
|
|
|
|
};
|
|
|
|
|
2020-03-24 04:26:00 +08:00
|
|
|
} // namespace ftxui
|
2019-01-20 05:06:05 +08:00
|
|
|
|
|
|
|
#endif /* end of include guard: FTXUI_UTIL_AUTORESET_HPP */
|