#include <AtScopeEnd.h>
Public Member Functions | |
AtScopeEnd (const boost::function< void()> &func) | |
Create an object which runs func when it is destroyed. More... | |
void | disable () |
Disable the object, do not run the function upon destruction. More... | |
void | enable () |
Enable the object to run the function upon destruction (the default). More... | |
~AtScopeEnd () | |
Destructor, calls the function as promised. More... | |
Private Attributes | |
boost::function< void()> | m_func |
The function to run upon destruction. More... | |
bool | m_run_at_scope_end |
If false , m_func is not run upon destruction. More... | |
A simple helper class which executes a specific function when the object runs out of scope. Sometimes it is much too complex to wrap some structure that is outside your control into a proper C++ class with a destructor, just to make sure that you never forget to clean up. In this case, just create an AtScopeEnd object and pass to it a matching cleanup function (any thing that can be called as a void() function).
Definition at line 38 of file AtScopeEnd.h.
|
inline |
Create an object which runs func when it is destroyed.
Definition at line 42 of file AtScopeEnd.h.
|
inline |
Destructor, calls the function as promised.
Definition at line 48 of file AtScopeEnd.h.
|
inline |
Disable the object, do not run the function upon destruction.
Definition at line 57 of file AtScopeEnd.h.
|
inline |
Enable the object to run the function upon destruction (the default).
Definition at line 59 of file AtScopeEnd.h.
|
private |
The function to run upon destruction.
Definition at line 63 of file AtScopeEnd.h.
|
private |
If false
, m_func is not run upon destruction.
Definition at line 65 of file AtScopeEnd.h.