MagicSmoke  $VERSION$
cleanup.h
Go to the documentation of this file.
1 //
2 // C++ Interface: misc
3 //
4 // Description: miscellaneous helper functions
5 //
6 //
7 // Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2012
8 //
9 // Copyright: See README/COPYING.GPL files that come with this distribution
10 //
11 //
12 
13 #ifndef MAGICSMOKE_LAMBDACLEAN_H
14 #define MAGICSMOKE_LAMBDACLEAN_H
15 
16 #include <functional>
17 
18 #ifndef MSIFACE_EXPORT
19 #define MSIFACE_EXPORT Q_DECL_IMPORT
20 #endif
21 
24 {
25  std::function<void()>m_ptr;
26  public:
28  MCleanup(const std::function<void()>&f):m_ptr(f){}
29 
31  void setFunction(const std::function<void()>&f){m_ptr=f;}
32 
34  ~MCleanup(){if(m_ptr)m_ptr();}
35 };
36 
37 #endif
void setFunction(const std::function< void()> &f)
sets a new cleanup function, removing the old one
Definition: cleanup.h:31
~MCleanup()
destructs the object and executes the cleanup function
Definition: cleanup.h:34
#define MSIFACE_EXPORT
Definition: cleanup.h:19
clean-up function: executes a lambda expression when it is destructed (i.e. when the instance leaves ...
Definition: cleanup.h:23
MCleanup(const std::function< void()> &f)
instantiates a new cleanup object and remembers the given function for later execution ...
Definition: cleanup.h:28