MyGUI 3.2.2

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

- File List
- Globals

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