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