MyGUI  3.2.2
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 
18  class MYGUI_EXPORT FactoryManager :
19  public Singleton<FactoryManager>
20  {
21  public:
23 
24  void initialise();
25  void shutdown();
26 
27  typedef delegates::CDelegate1<IObject*&> Delegate;
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_
MyGUI_IObject.h
MyGUI::FactoryManager::createObject
Type * createObject(const std::string &_category)
Definition: MyGUI_FactoryManager.h:63
MyGUI::FactoryManager
Definition: MyGUI_FactoryManager.h:18
MyGUI_GenericFactory.h
MyGUI_Prerequest.h
MyGUI_Singleton.h
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category)
Definition: MyGUI_FactoryManager.h:54
MyGUI::IObject
Definition: MyGUI_IObject.h:16
MyGUI::GenericFactory
Definition: MyGUI_GenericFactory.h:18
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.h:47
MyGUI::Singleton
Definition: MyGUI_Singleton.h:20
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category)
Definition: MyGUI_FactoryManager.h:40
MyGUI::FactoryManager::Delegate
delegates::CDelegate1< IObject *& > Delegate
Definition: MyGUI_FactoryManager.h:27