00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "CEGUIWindowFactoryManager.h"
00027 #include "CEGUIWindowFactory.h"
00028 #include "CEGUIExceptions.h"
00029 #include <algorithm>
00030
00031
00032 namespace CEGUI
00033 {
00034
00035
00036
00037
00038 template<> WindowFactoryManager* Singleton<WindowFactoryManager>::ms_Singleton = NULL;
00039
00040
00041
00042
00043
00044 void WindowFactoryManager::addFactory(WindowFactory* factory)
00045 {
00046
00047 if (factory == NULL)
00048 {
00049 throw NullObjectException((utf8*)"WindowFactoryManager::addFactory - The provided WindowFactory pointer was NULL");
00050 }
00051
00052
00053 if (d_factoryRegistry.find(factory->getTypeName()) != d_factoryRegistry.end())
00054 {
00055 throw AlreadyExistsException((utf8*)"WindowFactoryManager::addFactory - A WindowFactory for type '" + factory->getTypeName() + (utf8*)"' is already registered.");
00056 }
00057
00058
00059 d_factoryRegistry[factory->getTypeName()] = factory;
00060
00061 Logger::getSingleton().logEvent((utf8*)"WindowFactory for '" + factory->getTypeName() +"' windows added.");
00062 }
00063
00064
00065
00066
00067
00068 void WindowFactoryManager::removeFactory(const String& name)
00069 {
00070 d_factoryRegistry.erase(name);
00071
00072 Logger::getSingleton().logEvent((utf8*)"WindowFactory for '" + name +"' windows removed.");
00073 }
00074
00075
00076
00077
00078
00079 void WindowFactoryManager::removeFactory(WindowFactory* factory)
00080 {
00081 if (factory != NULL)
00082 {
00083 removeFactory(factory->getTypeName());
00084 }
00085
00086 }
00087
00088
00089
00090
00091
00092 WindowFactory* WindowFactoryManager::getFactory(const String& type) const
00093 {
00094
00095 WindowFactoryRegistry::const_iterator pos = d_factoryRegistry.find(type);
00096
00097
00098 if (pos != d_factoryRegistry.end())
00099 {
00100 return pos->second;
00101 }
00102
00103 else
00104 {
00105 TypeAliasRegistry::const_iterator aliasPos = d_aliasRegistry.find(type);
00106
00107
00108 if (aliasPos == d_aliasRegistry.end())
00109 {
00110 throw UnknownObjectException((utf8*)"WindowFactoryManager::getFactory - A WindowFactory object (or an alias) for '" + type + (utf8*)"' Window objects is not registered with the system.");
00111 }
00112 else
00113 {
00114
00115 return getFactory(aliasPos->second.getActiveTarget());
00116 }
00117
00118 }
00119
00120 }
00121
00122
00123
00124
00125
00126
00127 bool WindowFactoryManager::isFactoryPresent(const String& name) const
00128 {
00129
00130 if (d_factoryRegistry.find(name) != d_factoryRegistry.end())
00131 {
00132 return true;
00133 }
00134
00135 else
00136 {
00137 return (d_aliasRegistry.find(name) != d_aliasRegistry.end());
00138 }
00139
00140 }
00141
00142
00143 WindowFactoryManager& WindowFactoryManager::getSingleton(void)
00144 {
00145 return Singleton<WindowFactoryManager>::getSingleton();
00146 }
00147
00148
00149 WindowFactoryManager* WindowFactoryManager::getSingletonPtr(void)
00150 {
00151 return Singleton<WindowFactoryManager>::getSingletonPtr();
00152 }
00153
00154
00155
00156
00157
00158
00159 WindowFactoryManager::WindowFactoryIterator WindowFactoryManager::getIterator(void) const
00160 {
00161 return WindowFactoryIterator(d_factoryRegistry.begin(), d_factoryRegistry.end());
00162 }
00163
00164
00165
00166
00167
00168
00169 WindowFactoryManager::TypeAliasIterator WindowFactoryManager::getAliasIterator(void) const
00170 {
00171 return TypeAliasIterator(d_aliasRegistry.begin(), d_aliasRegistry.end());
00172 }
00173
00174
00175
00176
00177
00178 void WindowFactoryManager::addWindowTypeAlias(const String& aliasName, const String& targetType)
00179 {
00180
00181 if (!isFactoryPresent(targetType))
00182 {
00183 throw UnknownObjectException((utf8*)"WindowFactoryManager::addWindowTypeAlias - alias '" + aliasName + "' could not be created because the target type '" + targetType + "' is unknown within the system.");
00184 }
00185
00186 TypeAliasRegistry::iterator pos = d_aliasRegistry.find(aliasName);
00187
00188 if (pos == d_aliasRegistry.end())
00189 {
00190 d_aliasRegistry[aliasName].d_targetStack.push_back(targetType);
00191 }
00192
00193 else
00194 {
00195 pos->second.d_targetStack.push_back(targetType);
00196 }
00197
00198 Logger::getSingleton().logEvent((utf8*)"Window type alias named '" + aliasName + "' added for window type '" + targetType +"'.");
00199 }
00200
00201
00202
00203
00204
00205 void WindowFactoryManager::removeWindowTypeAlias(const String& aliasName, const String& targetType)
00206 {
00207
00208 TypeAliasRegistry::iterator pos = d_aliasRegistry.find(aliasName);
00209
00210
00211 if (pos != d_aliasRegistry.end())
00212 {
00213
00214 std::vector<String>::iterator aliasPos = std::find(pos->second.d_targetStack.begin(), pos->second.d_targetStack.end(), targetType);
00215
00216
00217 if (aliasPos != pos->second.d_targetStack.end())
00218 {
00219
00220 pos->second.d_targetStack.erase(aliasPos);
00221
00222 Logger::getSingleton().logEvent((utf8*)"Window type alias named '" + aliasName + "' removed for window type '" + targetType +"'.");
00223
00224
00225 if (pos->second.d_targetStack.empty())
00226 {
00227
00228 d_aliasRegistry.erase(aliasName);
00229
00230 Logger::getSingleton().logEvent((utf8*)"Window type alias named '" + aliasName + "' has no more targets and has been removed.", Informative);
00231 }
00232
00233 }
00234
00235 }
00236
00237 }
00238
00239
00241
00242
00243
00245 const String& WindowFactoryManager::AliasTargetStack::getActiveTarget(void) const
00246 {
00247 return d_targetStack.back();
00248 }
00249
00250
00251 uint WindowFactoryManager::AliasTargetStack::getStackedTargetCount(void) const
00252 {
00253 return (uint)d_targetStack.size();
00254 }
00255
00256
00257 }