mirror of
https://github.com/DrBeef/JKXR.git
synced 2024-12-12 21:52:08 +00:00
4597b03873
Opens in Android Studio but haven't even tried to build it yet (it won't.. I know that much!)
58 lines
737 B
C++
58 lines
737 B
C++
//
|
|
// Calls specified callbacks on scope enter (optional) and exit.
|
|
//
|
|
|
|
|
|
#ifndef OJK_SCOPE_GUARD_INCLUDED
|
|
#define OJK_SCOPE_GUARD_INCLUDED
|
|
|
|
|
|
#include <functional>
|
|
#include <utility>
|
|
|
|
|
|
namespace ojk
|
|
{
|
|
|
|
|
|
class ScopeGuard
|
|
{
|
|
public:
|
|
using Callback = std::function<void()>;
|
|
|
|
|
|
ScopeGuard(
|
|
Callback leave_callback) :
|
|
leave_callback_(leave_callback)
|
|
{
|
|
}
|
|
|
|
ScopeGuard(
|
|
Callback enter_callback,
|
|
Callback leave_callback) :
|
|
ScopeGuard(leave_callback)
|
|
{
|
|
enter_callback();
|
|
}
|
|
|
|
ScopeGuard(
|
|
const ScopeGuard& that) = delete;
|
|
|
|
ScopeGuard& operator=(
|
|
const ScopeGuard& that) = delete;
|
|
|
|
~ScopeGuard()
|
|
{
|
|
leave_callback_();
|
|
}
|
|
|
|
|
|
private:
|
|
Callback leave_callback_;
|
|
}; // ScopeGuard
|
|
|
|
|
|
} // ojk
|
|
|
|
|
|
#endif // OJK_SCOPE_GUARD_INCLUDED
|