MyGUI  3.2.0
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"
25 
26 namespace MyGUI
27 {
28 
29  template <> FactoryManager* Singleton<FactoryManager>::msInstance = nullptr;
30  template <> const char* Singleton<FactoryManager>::mClassTypeName("FactoryManager");
31 
33  mIsInitialise(false)
34  {
35  }
36 
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 
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 
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
static const char * getClassTypeName()
#define MYGUI_LOG(level, text)
#define MYGUI_ASSERT(exp, dest)
static std::string getFactoryRename(const std::string &_categoryName, const std::string &_factoryName)
void unregisterFactory(const std::string &_category, const std::string &_type)
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
IObject * createObject(const std::string &_category, const std::string &_type)
void destroyObject(IObject *_object)
bool isFactoryExist(const std::string &_category, const std::string &_type)