MyGUI  3.2.1
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"
10 
11 namespace MyGUI
12 {
13 
14  template <> FactoryManager* Singleton<FactoryManager>::msInstance = nullptr;
15  template <> const char* Singleton<FactoryManager>::mClassTypeName = "FactoryManager";
16 
18  mIsInitialise(false)
19  {
20  }
21 
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 
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 
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