MyGUI: MyGUI_FactoryManager.h Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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
15namespace MyGUI
16{
17
18 class MYGUI_EXPORT FactoryManager
19 {
20 MYGUI_SINGLETON_DECLARATION(FactoryManager);
21 public:
22 FactoryManager();
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_GenericFactory.h
MyGUI_IObject.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI_Singleton.h
MYGUI_SINGLETON_DECLARATION
#define MYGUI_SINGLETON_DECLARATION(ClassName)
Definition MyGUI_Singleton.h:111
MyGUI::FactoryManager
Definition MyGUI_FactoryManager.h:19
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category)
Definition MyGUI_FactoryManager.h:40
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type)
Definition MyGUI_FactoryManager.h:47
MyGUI::FactoryManager::createObject
Type * createObject(const std::string &_category)
Definition MyGUI_FactoryManager.h:63
MyGUI::FactoryManager::Delegate
delegates::CDelegate1< IObject *& > Delegate
Definition MyGUI_FactoryManager.h:27
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category)
Definition MyGUI_FactoryManager.h:54
MyGUI::GenericFactory
Definition MyGUI_GenericFactory.h:20
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::delegates::DelegateFunction
Definition MyGUI_Delegate.h:42
MyGUI::delegates::Delegate
Definition MyGUI_Delegate.h:136
MyGUI
Definition MyGUI_ActionController.h:15