FTXUI
5.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
autoreset.hpp
Go to the documentation of this file.
1
// Copyright 2020 Arthur Sonzogni. All rights reserved.
2
// Use of this source code is governed by the MIT license that can be found in
3
// the LICENSE file.
4
#ifndef FTXUI_UTIL_AUTORESET_HPP
5
#define FTXUI_UTIL_AUTORESET_HPP
6
7
#include <utility>
8
9
namespace
ftxui
{
10
11
/// Assign a value to a variable, reset its old value when going out of scope.
12
template
<
typename
T>
13
class
AutoReset
{
14
public
:
15
AutoReset
(T* variable, T new_value)
16
: variable_(variable), previous_value_(std::move(*variable)) {
17
*variable_ = std::move(new_value);
18
}
19
~AutoReset
() { *variable_ = std::move(previous_value_); }
20
21
private
:
22
T* variable_;
23
T previous_value_;
24
};
25
26
}
// namespace ftxui
27
28
#endif
/* end of include guard: FTXUI_UTIL_AUTORESET_HPP */
ftxui::AutoReset
Assign a value to a variable, reset its old value when going out of scope.
Definition
autoreset.hpp:13
ftxui::AutoReset::~AutoReset
~AutoReset()
Definition
autoreset.hpp:19
ftxui::AutoReset::AutoReset
AutoReset(T *variable, T new_value)
Definition
autoreset.hpp:15
ftxui
Definition
animation.hpp:12