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"
14
15namespace MyGUI
16{
17
19 {
21
22 public:
24
25 void initialise();
26 void shutdown();
27
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 {
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_
#define MYGUI_EXPORT
#define MYGUI_SINGLETON_DECLARATION(ClassName)
delegates::Delegate< IObject *& > Delegate
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
void registerFactory(std::string_view _category, std::string_view _type)
bool isFactoryExist(std::string_view _category, std::string_view _type)
void unregisterFactory(std::string_view _category, std::string_view _type)
void unregisterFactory(std::string_view _category)
Type * createObject(std::string_view _category)
void registerFactory(std::string_view _category)
FactoryManager(const FactoryManager &)=delete
IObject * createObject(std::string_view _category, std::string_view _type)
static Delegate::IDelegate * getFactory()
Type * castType(bool _throw=true)
DelegateFunction< Args... > IDelegate