|
OpenVPN 3 Core Library
|
A scope guard that runs a callable on destruction unless dismissed or released. More...
#include <cleanup.hpp>
Public Member Functions | |
| CleanupType (F method) noexcept(std::is_nothrow_move_constructible_v< F >) | |
| CleanupType (const CleanupType &)=delete | |
| CleanupType & | operator= (const CleanupType &)=delete |
| CleanupType (CleanupType &&other) noexcept | |
| CleanupType & | operator= (CleanupType &&other) noexcept |
| ~CleanupType () noexcept | |
| Destructor that executes the cleanup action if not dismissed or released. | |
| void | dismiss () noexcept |
| Dismiss the cleanup action, preventing it from being executed on destruction. | |
| std::optional< std::function< void()> > | release () noexcept |
| Release the cleanup action, returning the callable and preventing it from being executed on destruction. | |
Private Attributes | |
| std::optional< F > | clean |
A scope guard that runs a callable on destruction unless dismissed or released.
| F | The type of the callable to run on destruction. |
The Cleanup class template provides a mechanism to ensure that a specified callable is executed when the Cleanup object goes out of scope, unless it has been dismissed or released. This is useful for resource management and cleanup tasks that need to be performed when exiting a scope.
Definition at line 35 of file cleanup.hpp.
|
inlineexplicitnoexcept |
Definition at line 38 of file cleanup.hpp.
|
delete |
|
inlinenoexcept |
Definition at line 44 of file cleanup.hpp.
|
inlinenoexcept |
Destructor that executes the cleanup action if not dismissed or released.
When the CleanupType object is destroyed, if the cleanup action has not been dismissed or released, it will be invoked. Any exceptions thrown by the cleanup action are caught and swallowed to prevent exceptions from escaping the destructor.
Definition at line 64 of file cleanup.hpp.
|
inlinenoexcept |
Dismiss the cleanup action, preventing it from being executed on destruction.
After calling dismiss, the cleanup action will not be invoked when the CleanupType object is destroyed.
Definition at line 85 of file cleanup.hpp.
|
inlinenoexcept |
Definition at line 48 of file cleanup.hpp.
|
delete |
|
inlinenoexcept |
Release the cleanup action, returning the callable and preventing it from being executed on destruction.
After calling release, the cleanup action will not be invoked when the CleanupType object is destroyed, and the caller takes ownership of the callable. This allows the caller to manage the callable's lifetime independently, including calling it earlier or later than it might be otherwise called.
Definition at line 99 of file cleanup.hpp.
|
private |
Definition at line 111 of file cleanup.hpp.