MyGUI  3.2.0
MyGUI_FactoryManager.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_FACTORY_MANAGER_H__
23 #define __MYGUI_FACTORY_MANAGER_H__
24 
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Singleton.h"
27 #include "MyGUI_IObject.h"
28 #include "MyGUI_GenericFactory.h"
29 
30 namespace MyGUI
31 {
32 
34  public Singleton<FactoryManager>
35  {
36  public:
38 
39  void initialise();
40  void shutdown();
41 
44  void registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate);
46  void unregisterFactory(const std::string& _category, const std::string& _type);
48  void unregisterFactory(const std::string& _category);
49 
51  bool isFactoryExist(const std::string& _category, const std::string& _type);
52 
54  template<typename Type>
55  void registerFactory(const std::string& _category)
56  {
57  registerFactory(_category, Type::getClassTypeName(), GenericFactory<Type>::getFactory());
58  }
59 
61  template<typename Type>
62  void registerFactory(const std::string& _category, const std::string& _type)
63  {
64  registerFactory(_category, _type, GenericFactory<Type>::getFactory());
65  }
66 
68  template<typename Type>
69  void unregisterFactory(const std::string& _category)
70  {
71  unregisterFactory(_category, Type::getClassTypeName());
72  }
73 
75  IObject* createObject(const std::string& _category, const std::string& _type);
77  void destroyObject(IObject* _object);
78 
79  private:
80  typedef std::map<std::string, Delegate> MapFactoryItem;
81  typedef std::map<std::string, MapFactoryItem> MapRegisterFactoryItem;
82  MapRegisterFactoryItem mRegisterFactoryItems;
83 
84  bool mIsInitialise;
85  };
86 
87 } // namespace MyGUI
88 
89 #endif // __MYGUI_FACTORY_MANAGER_H__