FTXUI 6.1.9 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(const AutoReset&) = delete;
20 AutoReset(AutoReset&&) = delete;
21 AutoReset& operator=(const AutoReset&) = delete;
22 AutoReset& operator=(AutoReset&&) = delete;
23 ~AutoReset() { *variable_ = std::move(previous_value_); }
24
25 private:
26 T* variable_;
27 T previous_value_;
28};
29
30} // namespace ftxui
31
32#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(const AutoReset &)=delete
ftxui::AutoReset::operator=
AutoReset & operator=(AutoReset &&)=delete
ftxui::AutoReset::operator=
AutoReset & operator=(const AutoReset &)=delete
ftxui::AutoReset::AutoReset
AutoReset(AutoReset &&)=delete
ftxui::AutoReset::~AutoReset
~AutoReset()
Definition autoreset.hpp:23
ftxui::AutoReset::AutoReset
AutoReset(T *variable, T new_value)
Definition autoreset.hpp:15
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10