MyGUI  3.2.1
MyGUI_FactoryManager.h
Go to the documentation of this file.
1 /*
2  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3  * Distributed under the MIT License
4  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5  */
6 
7 #ifndef __MYGUI_FACTORY_MANAGER_H__
8 #define __MYGUI_FACTORY_MANAGER_H__
9 
10 #include "MyGUI_Prerequest.h"
11 #include "MyGUI_Singleton.h"
12 #include "MyGUI_IObject.h"
13 #include "MyGUI_GenericFactory.h"
14 
15 namespace MyGUI
16 {
17 
19  public Singleton<FactoryManager>
20  {
21  public:
23 
24  void initialise();
25  void shutdown();
26 
29  void registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate);
31  void unregisterFactory(const std::string& _category, const std::string& _type);
33  void unregisterFactory(const std::string& _category);
34 
36  bool isFactoryExist(const std::string& _category, const std::string& _type);
37 
39  template<typename Type>
40  void registerFactory(const std::string& _category)
41  {
42  registerFactory(_category, Type::getClassTypeName(), GenericFactory<Type>::getFactory());
43  }
44 
46  template<typename Type>
47  void registerFactory(const std::string& _category, const std::string& _type)
48  {
49  registerFactory(_category, _type, GenericFactory<Type>::getFactory());
50  }
51 
53  template<typename Type>
54  void unregisterFactory(const std::string& _category)
55  {
56  unregisterFactory(_category, Type::getClassTypeName());
57  }
58 
60  IObject* createObject(const std::string& _category, const std::string& _type);
62  template<typename Type>
63  Type* createObject(const std::string& _category)
64  {
65  IObject* item = createObject(_category, Type::getClassTypeName());
66  if (item != nullptr)
67  return item->castType<Type>(false);
68  return nullptr;
69  }
70 
72  void destroyObject(IObject* _object);
73 
74  private:
75  typedef std::map<std::string, Delegate> MapFactoryItem;
76  typedef std::map<std::string, MapFactoryItem> MapRegisterFactoryItem;
77  MapRegisterFactoryItem mRegisterFactoryItems;
78 
79  bool mIsInitialise;
80  };
81 
82 } // namespace MyGUI
83 
84 #endif // __MYGUI_FACTORY_MANAGER_H__