MythTV  0.26-pre
cleanup.cpp
Go to the documentation of this file.
00001 #include <list>
00002 #include <algorithm>
00003 
00004 #include "cleanup.h"
00005 
00006 CleanupProc::~CleanupProc()
00007 {
00008 }
00009 
00010 class CleanupHooksImp
00011 {
00012   private:
00013     typedef std::list<CleanupProc *> clean_list;
00014 
00015   private:
00016     clean_list m_clean_list;
00017 
00018   public:
00019     void addHook(CleanupProc *clean_proc)
00020     {
00021         m_clean_list.push_back(clean_proc);
00022     }
00023 
00024     void removeHook(CleanupProc *clean_proc)
00025     {
00026         clean_list::iterator p = std::find(m_clean_list.begin(),
00027                                            m_clean_list.end(), clean_proc);
00028         if (p != m_clean_list.end())
00029         {
00030             m_clean_list.erase(p);
00031         }
00032     }
00033 
00034     void cleanup()
00035     {
00036         for (clean_list::iterator p = m_clean_list.begin();
00037              p != m_clean_list.end();++p)
00038         {
00039             (*p)->doClean();
00040         }
00041         m_clean_list.clear();
00042     }
00043 };
00044 
00045 namespace
00046 {
00047     CleanupHooks *g_cleanup_hooks = 0;
00048 }
00049 
00050 CleanupHooks *CleanupHooks::getInstance()
00051 {
00052     if (!g_cleanup_hooks)
00053     {
00054         g_cleanup_hooks = new CleanupHooks();
00055     }
00056     return g_cleanup_hooks;
00057 }
00058 
00059 void CleanupHooks::addHook(CleanupProc *clean_proc)
00060 {
00061     m_imp->addHook(clean_proc);
00062 }
00063 
00064 void CleanupHooks::removeHook(CleanupProc *clean_proc)
00065 {
00066     m_imp->removeHook(clean_proc);
00067 }
00068 
00069 void CleanupHooks::cleanup()
00070 {
00071     m_imp->cleanup();
00072     delete g_cleanup_hooks;
00073     g_cleanup_hooks = 0;
00074 }
00075 
00076 CleanupHooks::CleanupHooks()
00077 {
00078     m_imp = new CleanupHooksImp();
00079 }
00080 
00081 CleanupHooks::~CleanupHooks()
00082 {
00083     delete m_imp;
00084 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends