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 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany 00012 // 00013 // -- END LICENSE BLOCK ------------------------------------------------ 00014 00015 //---------------------------------------------------------------------- 00026 //---------------------------------------------------------------------- 00027 #ifndef ICL_CORE_SINGLETON_H_INCLUDED 00028 #define ICL_CORE_SINGLETON_H_INCLUDED 00029 00030 #include "icl_core/SingletonCreationPolicies.h" 00031 #include "icl_core/SingletonLifetimePolicies.h" 00032 #include "icl_core/SingletonThreadingModels.h" 00033 00034 namespace icl_core { 00035 00050 template 00051 <class T, 00052 template <class> class TCreationPolicy = SCPCreateUsingNew, 00053 template <class> class TLifetimePolicy = SLPDefaultLifetime, 00054 template <class> class TThreadingModel = STMSingleThreaded> 00055 class Singleton 00056 { 00057 public: 00059 static T& instance(); 00060 00061 private: 00063 Singleton(); 00065 ~Singleton(); 00067 Singleton(const Singleton&); 00069 Singleton& operator = (const Singleton&); 00070 00072 static void destroySingleton(); 00074 static T *m_instance; 00076 static bool m_destroyed; 00078 static typename TThreadingModel<T>::Lock m_lock; 00079 }; 00080 00081 } 00082 00083 #endif