AtScopeEnd.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #ifndef ICL_CORE_AT_SCOPE_END_H_INCLUDED
00024 #define ICL_CORE_AT_SCOPE_END_H_INCLUDED
00025 
00026 #include <boost/function.hpp>
00027 
00028 namespace icl_core {
00029 
00038 class AtScopeEnd
00039 {
00040 public:
00042   AtScopeEnd(const boost::function<void()>& func)
00043     : m_func(func),
00044       m_run_at_scope_end(true)
00045   { }
00046 
00048   ~AtScopeEnd()
00049   {
00050     if (m_run_at_scope_end)
00051     {
00052       m_func();
00053     }
00054   }
00055 
00057   void disable() { m_run_at_scope_end = false; }
00059   void enable() { m_run_at_scope_end = true; }
00060 
00061 private:
00063   boost::function<void()> m_func;
00065   bool m_run_at_scope_end;
00066 };
00067 
00068 }
00069 
00070 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03