Nui
Loading...
Searching...
No Matches
on_destroy.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
5namespace Nui
6{
8 {
9 public:
10 OnDestroy(std::function<void()> onDestroy)
11 : wasMoved_{false}
12 , onDestroy_{std::move(onDestroy)}
13 {}
14 OnDestroy(OnDestroy const&) = delete;
16 : wasMoved_{other.wasMoved_}
17 , onDestroy_{std::move(other.onDestroy_)}
18 {
19 other.wasMoved_ = true;
20 }
21 OnDestroy& operator=(OnDestroy const&) = delete;
23 {
24 wasMoved_ = other.wasMoved_;
25 onDestroy_ = std::move(other.onDestroy_);
26 other.wasMoved_ = true;
27 return *this;
28 }
30 {
31 if (!wasMoved_ && onDestroy_)
32 onDestroy_();
33 }
34 void trigger()
35 {
36 if (!wasMoved_ && onDestroy_)
37 {
38 onDestroy_();
39 onDestroy_ = nullptr;
40 }
41 }
42
43 private:
44 bool wasMoved_;
45 std::function<void()> onDestroy_;
46 };
47}
Definition on_destroy.hpp:8
OnDestroy(std::function< void()> onDestroy)
Definition on_destroy.hpp:10
void trigger()
Definition on_destroy.hpp:34
OnDestroy(OnDestroy const &)=delete
OnDestroy(OnDestroy &&other)
Definition on_destroy.hpp:15
OnDestroy & operator=(OnDestroy const &)=delete
~OnDestroy()
Definition on_destroy.hpp:29
OnDestroy & operator=(OnDestroy &&other)
Definition on_destroy.hpp:22
Definition file_dialog.hpp:6