#include <AtScopeEnd.h>
Public Member Functions | |
| AtScopeEnd (const boost::function< void()> &func) | |
| Create an object which runs func when it is destroyed. | |
| void | disable () |
| Disable the object, do not run the function upon destruction. | |
| void | enable () |
| Enable the object to run the function upon destruction (the default). | |
| ~AtScopeEnd () | |
| Destructor, calls the function as promised. | |
Private Attributes | |
| boost::function< void()> | m_func |
| The function to run upon destruction. | |
| bool | m_run_at_scope_end |
If false, m_func is not run upon destruction. | |
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.
| icl_core::AtScopeEnd::AtScopeEnd | ( | const boost::function< void()> & | func | ) | [inline] |
Create an object which runs func when it is destroyed.
Definition at line 42 of file AtScopeEnd.h.
| icl_core::AtScopeEnd::~AtScopeEnd | ( | ) | [inline] |
Destructor, calls the function as promised.
Definition at line 48 of file AtScopeEnd.h.
| void icl_core::AtScopeEnd::disable | ( | ) | [inline] |
Disable the object, do not run the function upon destruction.
Definition at line 57 of file AtScopeEnd.h.
| void icl_core::AtScopeEnd::enable | ( | ) | [inline] |
Enable the object to run the function upon destruction (the default).
Definition at line 59 of file AtScopeEnd.h.
boost::function<void()> icl_core::AtScopeEnd::m_func [private] |
The function to run upon destruction.
Definition at line 63 of file AtScopeEnd.h.
bool icl_core::AtScopeEnd::m_run_at_scope_end [private] |
If false, m_func is not run upon destruction.
Definition at line 65 of file AtScopeEnd.h.