MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_FACTORY_MANAGER_H__ 00023 #define __MYGUI_FACTORY_MANAGER_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 #include "MyGUI_Singleton.h" 00027 #include "MyGUI_IObject.h" 00028 #include "MyGUI_GenericFactory.h" 00029 00030 namespace MyGUI 00031 { 00032 00033 class MYGUI_EXPORT FactoryManager : 00034 public Singleton<FactoryManager> 00035 { 00036 public: 00037 FactoryManager(); 00038 00039 void initialise(); 00040 void shutdown(); 00041 00042 typedef delegates::CDelegate1<IObject*&> Delegate; 00044 void registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate); 00046 void unregisterFactory(const std::string& _category, const std::string& _type); 00048 void unregisterFactory(const std::string& _category); 00049 00051 bool isFactoryExist(const std::string& _category, const std::string& _type); 00052 00054 template<typename Type> 00055 void registerFactory(const std::string& _category) 00056 { 00057 registerFactory(_category, Type::getClassTypeName(), GenericFactory<Type>::getFactory()); 00058 } 00059 00061 template<typename Type> 00062 void registerFactory(const std::string& _category, const std::string& _type) 00063 { 00064 registerFactory(_category, _type, GenericFactory<Type>::getFactory()); 00065 } 00066 00068 template<typename Type> 00069 void unregisterFactory(const std::string& _category) 00070 { 00071 unregisterFactory(_category, Type::getClassTypeName()); 00072 } 00073 00075 IObject* createObject(const std::string& _category, const std::string& _type); 00077 void destroyObject(IObject* _object); 00078 00079 private: 00080 typedef std::map<std::string, Delegate> MapFactoryItem; 00081 typedef std::map<std::string, MapFactoryItem> MapRegisterFactoryItem; 00082 MapRegisterFactoryItem mRegisterFactoryItems; 00083 00084 bool mIsInitialise; 00085 }; 00086 00087 } // namespace MyGUI 00088 00089 #endif // __MYGUI_FACTORY_MANAGER_H__