MyGUI: MyGUI_FactoryManager.cpp Source File

MyGUI 3.4.3

MyGUI_FactoryManager.cpp
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#include "MyGUI_Precompiled.h"
8#include "MyGUI_FactoryManager.h"
9#include "MyGUI_BackwardCompatibility.h"
10
11namespace MyGUI
12{
13
14 MYGUI_SINGLETON_DEFINITION(FactoryManager);
15
16 FactoryManager::FactoryManager() :
17 mSingletonHolder(this)
18 {
19 }
20
21 void FactoryManager::initialise()
22 {
23 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
24 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
25
26 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
27 mIsInitialise = true;
28 }
29
30 void FactoryManager::shutdown()
31 {
32 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
33 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
34
35 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
36 mIsInitialise = false;
37 }
38
39 void FactoryManager::registerFactory(
40 std::string_view _category,
41 std::string_view _type,
42 Delegate::IDelegate* _delegate)
43 {
44 //FIXME
45 auto category = mRegisterFactoryItems.find(_category);
46 if (category == mRegisterFactoryItems.end())
47 category = mRegisterFactoryItems.emplace(_category, MapFactoryItem()).first;
48 auto type = category->second.find(_type);
49 if (type == category->second.end())
50 type = category->second.emplace(_type, Delegate()).first;
51 type->second = _delegate;
52 }
53
54 void FactoryManager::unregisterFactory(std::string_view _category, std::string_view _type)
55 {
56 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
57 if (category == mRegisterFactoryItems.end())
58 {
59 return;
60 }
61 MapFactoryItem::iterator type = category->second.find(_type);
62 if (type == category->second.end())
63 {
64 return;
65 }
66
67 category->second.erase(type);
68 }
69
70 void FactoryManager::unregisterFactory(std::string_view _category)
71 {
72 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
73 if (category == mRegisterFactoryItems.end())
74 {
75 return;
76 }
77 mRegisterFactoryItems.erase(category);
78 }
79
80 IObject* FactoryManager::createObject(std::string_view _category, std::string_view _type)
81 {
82 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
83 if (category == mRegisterFactoryItems.end())
84 {
85 return nullptr;
86 }
87
88 std::string_view typeName = BackwardCompatibility::getFactoryRename(_category, _type);
89 MapFactoryItem::iterator type = category->second.find(typeName);
90 if (type == category->second.end())
91 {
92 return nullptr;
93 }
94 if (type->second.empty())
95 {
96 return nullptr;
97 }
98
99 IObject* result = nullptr;
100 type->second(result);
101 return result;
102 }
103
104 void FactoryManager::destroyObject(IObject* _object)
105 {
106 delete _object;
107
108 /*MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
109 if (category == mRegisterFactoryItems.end())
110 {
111 return;
112 }
113 MapFactoryItem::iterator type = category->second.find(_type);
114 if (type == category->second.end())
115 {
116 return;
117 }
118 if (type->second.empty())
119 {
120 return;
121 }
122
123 type->second(_object, nullptr, _version);*/
124 }
125
126 bool FactoryManager::isFactoryExist(std::string_view _category, std::string_view _type)
127 {
128 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
129 if (category == mRegisterFactoryItems.end())
130 {
131 return false;
132 }
133 return category->second.find(_type) != category->second.end();
134 }
135
136} // namespace MyGUI
MyGUI_BackwardCompatibility.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_FactoryManager.h
MyGUI_Precompiled.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI::BackwardCompatibility::getFactoryRename
static std::string_view getFactoryRename(std::string_view _categoryName, std::string_view _factoryName)
Definition MyGUI_BackwardCompatibility.cpp:1320
MyGUI::FactoryManager
Definition MyGUI_FactoryManager.h:19
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::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::FactoryManager
FactoryManager()
Definition MyGUI_FactoryManager.cpp:16
MyGUI::FactoryManager::shutdown
void shutdown()
Definition MyGUI_FactoryManager.cpp:30
MyGUI::FactoryManager::destroyObject
void destroyObject(IObject *_object)
Definition MyGUI_FactoryManager.cpp:104
MyGUI::FactoryManager::initialise
void initialise()
Definition MyGUI_FactoryManager.cpp:21
MyGUI::FactoryManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::FactoryManager::createObject
IObject * createObject(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:80
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::delegates::Delegate< IObject *& >::IDelegate
DelegateFunction< Args... > IDelegate
Definition MyGUI_Delegate.h:160
MyGUI
Definition MyGUI_ActionController.h:15