MyGUI 3.2.0

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

- File List
- Globals

MyGUI_FactoryManager.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_FactoryManager.h"
24 #include "MyGUI_BackwardCompatibility.h"
25
26 namespace MyGUI
27 {
28
29 template <> FactoryManager* Singleton<FactoryManager>::msInstance = nullptr;
30 template <> const char* Singleton<FactoryManager>::mClassTypeName("FactoryManager");
31
32 FactoryManager::FactoryManager() :
33 mIsInitialise(false)
34 {
35 }
36
37 void FactoryManager::initialise()
38 {
39 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
40 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
41
42 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
43 mIsInitialise = true;
44 }
45
46 void FactoryManager::shutdown()
47 {
48 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
49 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
50
51 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
52 mIsInitialise = false;
53 }
54
55 void FactoryManager::registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate)
56 {
57 //FIXME
58 mRegisterFactoryItems[_category][_type] = _delegate;
59 }
60
61 void FactoryManager::unregisterFactory(const std::string& _category, const std::string& _type)
62 {
63 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
64 if (category == mRegisterFactoryItems.end())
65 {
66 return;
67 }
68 MapFactoryItem::iterator type = category->second.find(_type);
69 if (type == category->second.end())
70 {
71 return;
72 }
73
74 category->second.erase(type);
75 }
76
77 void FactoryManager::unregisterFactory(const std::string& _category)
78 {
79 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
80 if (category == mRegisterFactoryItems.end())
81 {
82 return;
83 }
84 mRegisterFactoryItems.erase(category);
85 }
86
87 IObject* FactoryManager::createObject(const std::string& _category, const std::string& _type)
88 {
89 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
90 if (category == mRegisterFactoryItems.end())
91 {
92 return nullptr;
93 }
94
95 std::string typeName = BackwardCompatibility::getFactoryRename(_category, _type);
96 MapFactoryItem::iterator type = category->second.find(typeName);
97 if (type == category->second.end())
98 {
99 return nullptr;
100 }
101 if (type->second.empty())
102 {
103 return nullptr;
104 }
105
106 IObject* result = nullptr;
107 type->second(result);
108 return result;
109 }
110
111 void FactoryManager::destroyObject(IObject* _object)
112 {
113 delete _object;
114
115 /*MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
116 if (category == mRegisterFactoryItems.end())
117 {
118 return;
119 }
120 MapFactoryItem::iterator type = category->second.find(_type);
121 if (type == category->second.end())
122 {
123 return;
124 }
125 if (type->second.empty())
126 {
127 return;
128 }
129
130 type->second(_object, nullptr, _version);*/
131 }
132
133 bool FactoryManager::isFactoryExist(const std::string& _category, const std::string& _type)
134 {
135 MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
136 if (category == mRegisterFactoryItems.end())
137 {
138 return false;
139 }
140 MapFactoryItem::iterator type = category->second.find(_type);
141 if (type == category->second.end())
142 {
143 return false;
144 }
145
146 return true;
147 }
148
149 } // namespace MyGUI
MyGUI_FactoryManager.h
MyGUI_Precompiled.h
MyGUI::delegates::IDelegate1
Definition: MyGUI_Delegate.h:41
MyGUI::Singleton< FactoryManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:64
MyGUI::FactoryManager::shutdown
void shutdown()
Definition: MyGUI_FactoryManager.cpp:46
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::BackwardCompatibility::getFactoryRename
static std::string getFactoryRename(const std::string &_categoryName, const std::string &_factoryName)
Definition: MyGUI_BackwardCompatibility.cpp:1061
MyGUI_BackwardCompatibility.h
MyGUI::FactoryManager::FactoryManager
FactoryManager()
Definition: MyGUI_FactoryManager.cpp:32
MyGUI::FactoryManager::initialise
void initialise()
Definition: MyGUI_FactoryManager.cpp:37
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:61
MyGUI::IObject
Definition: MyGUI_IObject.h:31
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:55
MyGUI::Singleton::mClassTypeName
static const char * mClassTypeName
Definition: MyGUI_Singleton.h:73
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:87
MyGUI::FactoryManager::destroyObject
void destroyObject(IObject *_object)
Definition: MyGUI_FactoryManager.cpp:111
MyGUI::FactoryManager::isFactoryExist
bool isFactoryExist(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:133