diff options
author | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 |
commit | 60cbbdec07ab7a5636eac5b3c024ae44e937f4d4 (patch) | |
tree | b2c7b0a868f18159dbc43d8954e1bd7668549a88 /Client/Source/Utilities/AutoInvoke.h |
+init
Diffstat (limited to 'Client/Source/Utilities/AutoInvoke.h')
-rw-r--r-- | Client/Source/Utilities/AutoInvoke.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Client/Source/Utilities/AutoInvoke.h b/Client/Source/Utilities/AutoInvoke.h new file mode 100644 index 0000000..7d9bb83 --- /dev/null +++ b/Client/Source/Utilities/AutoInvoke.h @@ -0,0 +1,27 @@ +#pragma once + +typedef void(*AutoInvokeAction)(); + +// RAII auto call +class AutoInvokerWhenLeave +{ +public: + AutoInvokerWhenLeave(AutoInvokeAction func) + { + m_Func = func; + }; + ~AutoInvokerWhenLeave() + { + if (m_Func) + { + m_Func(); + } + } +private: + AutoInvokeAction m_Func; + +}; + +#define InvokeWhenLeave(func) \ +AutoInvokerWhenLeave auto_invoker = AutoInvokerWhenLeave(func); + |