MyGUI  3.0.1
MyGUI_FactoryManager.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_FactoryManager.h"
25 
26 namespace MyGUI
27 {
28 
29  MYGUI_INSTANCE_IMPLEMENT( FactoryManager )
30 
31  void FactoryManager::initialise()
32  {
33  MYGUI_ASSERT(!mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
34  MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);
35 
36 
37  MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
38  mIsInitialise = true;
39  }
40 
42  {
43  if (!mIsInitialise) return;
44  MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
45 
46  MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown");
47  mIsInitialise = false;
48  }
49 
50  void FactoryManager::registerFactory(const std::string& _category, const std::string& _type, Delegate::IDelegate* _delegate)
51  {
52  //FIXME
53  mRegisterFactoryItems[_category][_type] = _delegate;
54  }
55 
56  void FactoryManager::unregisterFactory(const std::string& _category, const std::string& _type)
57  {
58  MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
59  if (category == mRegisterFactoryItems.end())
60  {
61  return;
62  }
63  MapFactoryItem::iterator type = category->second.find(_type);
64  if (type == category->second.end())
65  {
66  return;
67  }
68 
69  category->second.erase(type);
70  }
71 
72  void FactoryManager::unregisterFactory(const std::string& _category)
73  {
74  MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
75  if (category == mRegisterFactoryItems.end())
76  {
77  return;
78  }
79  mRegisterFactoryItems.erase(category);
80  }
81 
82  IObject* FactoryManager::createObject(const std::string& _category, const std::string& _type)
83  {
84  MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
85  if (category == mRegisterFactoryItems.end())
86  {
87  return nullptr;
88  }
89  MapFactoryItem::iterator type = category->second.find(_type);
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 
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(const std::string& _category, const std::string& _type)
127  {
128  MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
129  if (category == mRegisterFactoryItems.end())
130  {
131  return false;
132  }
133  MapFactoryItem::iterator type = category->second.find(_type);
134  if (type == category->second.end())
135  {
136  return false;
137  }
138 
139  return true;
140  }
141 
142 } // namespace MyGUI