MyGUI: MyGUI_FactoryManager.h Source File

MyGUI 3.4.3

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
22 public:
23 FactoryManager();
24
25 void initialise();
26 void shutdown();
27
28 using Delegate = delegates::Delegate<IObject*&>;
30 void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate* _delegate);
32 void unregisterFactory(std::string_view _category, std::string_view _type);
34 void unregisterFactory(std::string_view _category);
35
37 bool isFactoryExist(std::string_view _category, std::string_view _type);
38
40 template<typename Type>
41 void registerFactory(std::string_view _category)
42 {
43 registerFactory(_category, Type::getClassTypeName(), GenericFactory<Type>::getFactory());
44 }
45
47 template<typename Type>
48 void registerFactory(std::string_view _category, std::string_view _type)
49 {
50 registerFactory(_category, _type, GenericFactory<Type>::getFactory());
51 }
52
54 template<typename Type>
55 void unregisterFactory(std::string_view _category)
56 {
57 unregisterFactory(_category, Type::getClassTypeName());
58 }
59
61 IObject* createObject(std::string_view _category, std::string_view _type);
63 template<typename Type>
64 Type* createObject(std::string_view _category)
65 {
66 IObject* item = createObject(_category, Type::getClassTypeName());
67 if (item != nullptr)
68 return item->castType<Type>(false);
69 return nullptr;
70 }
71
73 void destroyObject(IObject* _object);
74
75 private:
76 using MapFactoryItem = std::map<std::string, Delegate, std::less<>>;
77 using MapRegisterFactoryItem = std::map<std::string, MapFactoryItem, std::less<>>;
78 MapRegisterFactoryItem mRegisterFactoryItems;
79
80 bool mIsInitialise{false};
81 };
82
83} // namespace MyGUI
84
85#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:112
MyGUI::FactoryManager::Delegate
delegates::Delegate< IObject *& > Delegate
Definition MyGUI_FactoryManager.h:28
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
Definition MyGUI_FactoryManager.cpp:39
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.h:48
MyGUI::FactoryManager::isFactoryExist
bool isFactoryExist(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:126
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:54
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(std::string_view _category)
Definition MyGUI_FactoryManager.h:55
MyGUI::FactoryManager::createObject
Type * createObject(std::string_view _category)
Definition MyGUI_FactoryManager.h:64
MyGUI::FactoryManager::shutdown
void shutdown()
Definition MyGUI_FactoryManager.cpp:30
MyGUI::FactoryManager::initialise
void initialise()
Definition MyGUI_FactoryManager.cpp:21
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category)
Definition MyGUI_FactoryManager.h:41
MyGUI::FactoryManager::FactoryManager
FactoryManager(const FactoryManager &)=delete
MyGUI::FactoryManager::createObject
IObject * createObject(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:80
MyGUI::GenericFactory::getFactory
static Delegate::IDelegate * getFactory()
Definition MyGUI_GenericFactory.h:23
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition MyGUI_IObject.h:18
MyGUI::delegates::Delegate
Definition MyGUI_Delegate.h:158
MyGUI::delegates::Delegate< IObject *& >::IDelegate
DelegateFunction< Args... > IDelegate
Definition MyGUI_Delegate.h:160
MyGUI
Definition MyGUI_ActionController.h:15