00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : SingletonManager 00006 * Package : Zeus.ZeusBase.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef SingletonManagerH 00033 #define SingletonManagerH 00034 00035 00036 #include <zeusbase/System/Interfaces/ISingletonManager.hpp> 00037 #include <zeusbase/System/ZObject.h> 00038 #include <zeusbase/System/StringMap.hpp> 00039 00040 #define SingletonManager TSingletonManager::getInstance() 00041 00042 BEGIN_NAMESPACE_Zeus 00043 00044 class TCriticalSection; 00045 00046 /***************************************************************************/ 00049 /***************************************************************************/ 00050 zeusbase_class TSingletonManager : public TZObject, public ISingletonManager 00051 { 00052 public: 00053 static TSingletonManager& getInstance(); 00054 void removeAll(); 00055 void registerCommonSingletons(); 00056 00057 //Methods of ISingletonManager 00058 virtual Retval MQUALIFIER addSingleton(const IString& rName, IZUnknown& rIface); 00059 virtual Retval MQUALIFIER getSingleton(const IString& rName, IZUnknown*& rpIface); 00060 virtual Retval MQUALIFIER removeSingleton(const IString& rName); 00061 00062 //Methods of IZUnknown 00063 MEMORY_MANAGER_DECL 00064 00065 protected: 00067 static TAutoPtr<TSingletonManager> m_ptrInstance; 00068 00070 //Compiler problem on older version from microsoft 00071 #ifdef _MSC_VER 00072 public: 00073 #endif 00074 00075 00076 TSingletonManager(); 00077 virtual ~TSingletonManager(); 00078 00079 00080 private: 00082 TStringMap<IZUnknown*> m_mapSings; 00084 TCriticalSection& m_rLock; 00085 00086 00087 }; 00088 00089 /**************************************************************************/ 00092 /**************************************************************************/ 00093 inline TSingletonManager& TSingletonManager::getInstance() 00094 { 00095 return *m_ptrInstance; 00096 } 00097 00098 END_NAMESPACE_Zeus 00099 00100 #endif