AtScopeEnd.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #ifndef ICL_CORE_AT_SCOPE_END_H_INCLUDED
24 #define ICL_CORE_AT_SCOPE_END_H_INCLUDED
25 
26 #include <boost/function.hpp>
27 
28 namespace icl_core {
29 
39 {
40 public:
42  AtScopeEnd(const boost::function<void()>& func)
43  : m_func(func),
44  m_run_at_scope_end(true)
45  { }
46 
49  {
51  {
52  m_func();
53  }
54  }
55 
57  void disable() { m_run_at_scope_end = false; }
59  void enable() { m_run_at_scope_end = true; }
60 
61 private:
63  boost::function<void()> m_func;
66 };
67 
68 }
69 
70 #endif
bool m_run_at_scope_end
If false, m_func is not run upon destruction.
Definition: AtScopeEnd.h:65
AtScopeEnd(const boost::function< void()> &func)
Create an object which runs func when it is destroyed.
Definition: AtScopeEnd.h:42
~AtScopeEnd()
Destructor, calls the function as promised.
Definition: AtScopeEnd.h:48
void enable()
Enable the object to run the function upon destruction (the default).
Definition: AtScopeEnd.h:59
boost::function< void()> m_func
The function to run upon destruction.
Definition: AtScopeEnd.h:63
void disable()
Disable the object, do not run the function upon destruction.
Definition: AtScopeEnd.h:57


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58