diff options
author | Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> | 2024-01-20 22:40:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 23:40:27 +0100 |
commit | 447cace77f2533e616f82e42787c14f7fcbc039b (patch) | |
tree | 152ea76ec2196a808cf3aa0828cbe3436dc0b37d /primedev/util/utils.h | |
parent | 7c9ffa1cabbd03a87a1b8efa1d0db329ba9ecc77 (diff) | |
download | NorthstarLauncher-447cace77f2533e616f82e42787c14f7fcbc039b.tar.gz NorthstarLauncher-447cace77f2533e616f82e42787c14f7fcbc039b.zip |
Add and use ScopeGuard (#643)v1.22.1-rc2
Use a scope guard instead of `GOTO` statements for curl cleanup
Diffstat (limited to 'primedev/util/utils.h')
-rw-r--r-- | primedev/util/utils.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/primedev/util/utils.h b/primedev/util/utils.h index 85922692..1a419607 100644 --- a/primedev/util/utils.h +++ b/primedev/util/utils.h @@ -1,3 +1,23 @@ #pragma once void RemoveAsciiControlSequences(char* str, bool allow_color_codes); + +class ScopeGuard +{ +public: + auto operator=(ScopeGuard&) = delete; + ScopeGuard(ScopeGuard&) = delete; + + ScopeGuard(std::function<void()> callback) : m_callback(callback) {} + ~ScopeGuard() + { + m_callback(); + } + void Dismiss() + { + m_callback = [] {}; + } + +private: + std::function<void()> m_callback; +}; |