Crazy Eddies GUI System
0.7.6
|
00001 /*********************************************************************** 00002 filename: CEGUIWindowFactoryManager.h 00003 created: 22/2/2004 00004 author: Paul D Turner 00005 00006 purpose: Defines interface for WindowFactoryManager class 00007 *************************************************************************/ 00008 /*************************************************************************** 00009 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifndef _CEGUIWindowFactoryManager_h_ 00031 #define _CEGUIWindowFactoryManager_h_ 00032 00033 #include "CEGUIBase.h" 00034 #include "CEGUIString.h" 00035 #include "CEGUISingleton.h" 00036 #include "CEGUILogger.h" 00037 #include "CEGUIIteratorBase.h" 00038 #include "CEGUIWindowFactory.h" 00039 #include <map> 00040 #include <vector> 00041 00042 #if defined(_MSC_VER) 00043 # pragma warning(push) 00044 # pragma warning(disable : 4275) 00045 # pragma warning(disable : 4251) 00046 #endif 00047 00048 00049 // Start of CEGUI namespace section 00050 namespace CEGUI 00051 { 00060 class CEGUIEXPORT WindowFactoryManager : public Singleton<WindowFactoryManager> 00061 { 00062 public: 00067 struct CEGUIEXPORT FalagardWindowMapping 00068 { 00069 String d_windowType; 00070 String d_lookName; 00071 String d_baseType; 00072 String d_rendererType; 00073 String d_effectName; 00074 }; 00075 00080 class CEGUIEXPORT AliasTargetStack 00081 { 00082 public: 00087 AliasTargetStack(void) {} 00088 00089 00094 ~AliasTargetStack(void) {} 00095 00096 00104 const String& getActiveTarget(void) const; 00105 00113 uint getStackedTargetCount(void) const; 00114 00115 00116 private: 00117 friend class WindowFactoryManager; 00118 typedef std::vector<String> TargetTypeStack; 00119 00120 TargetTypeStack d_targetStack; 00121 }; 00122 00123 00124 /************************************************************************* 00125 Construction and Destruction 00126 *************************************************************************/ 00131 WindowFactoryManager(void); 00132 00133 00138 ~WindowFactoryManager(void) 00139 { 00140 Logger::getSingleton().logEvent("CEGUI::WindowFactoryManager singleton destroyed"); 00141 } 00142 00143 00144 /************************************************************************* 00145 Public Interface 00146 *************************************************************************/ 00160 void addFactory(WindowFactory* factory); 00161 00175 template <typename T> 00176 static void addFactory(); 00177 00178 00193 void removeFactory(const String& name); 00194 00195 00210 void removeFactory(WindowFactory* factory); 00211 00212 00220 void removeAllFactories(void); 00221 00222 00235 WindowFactory* getFactory(const String& type) const; 00236 00237 00252 bool isFactoryPresent(const String& name) const; 00253 00254 00280 void addWindowTypeAlias(const String& aliasName, const String& targetType); 00281 00282 00300 void removeWindowTypeAlias(const String& aliasName, const String& targetType); 00301 00333 void addFalagardWindowMapping(const String& newType, 00334 const String& targetType, 00335 const String& lookName, 00336 const String& renderer, 00337 const String& effectName = String("")); 00338 00346 void removeFalagardWindowMapping(const String& type); 00347 00359 bool isFalagardMappedType(const String& type) const; 00360 00373 const String& getMappedLookForType(const String& type) const; 00374 00387 const String& getMappedRendererForType(const String& type) const; 00388 00407 String getDereferencedAliasType(const String& type) const; 00408 00421 const FalagardWindowMapping& getFalagardMappingForType(const String& type) const; 00422 00423 private: 00424 /************************************************************************* 00425 Implementation Data 00426 *************************************************************************/ 00427 typedef std::map<String, WindowFactory*, String::FastLessCompare> WindowFactoryRegistry; 00428 typedef std::map<String, AliasTargetStack, String::FastLessCompare> TypeAliasRegistry; 00429 typedef std::map<String, FalagardWindowMapping, String::FastLessCompare> FalagardMapRegistry; 00430 00431 typedef std::vector<WindowFactory*> OwnedWindowFactoryList; 00432 00433 WindowFactoryRegistry d_factoryRegistry; 00434 TypeAliasRegistry d_aliasRegistry; 00435 FalagardMapRegistry d_falagardRegistry; 00436 00437 static OwnedWindowFactoryList d_ownedFactories; 00438 00439 public: 00440 /************************************************************************* 00441 Iterator stuff 00442 *************************************************************************/ 00443 typedef ConstBaseIterator<WindowFactoryRegistry> WindowFactoryIterator; 00444 typedef ConstBaseIterator<TypeAliasRegistry> TypeAliasIterator; 00445 typedef ConstBaseIterator<FalagardMapRegistry> FalagardMappingIterator; 00446 00451 WindowFactoryIterator getIterator(void) const; 00452 00453 00458 TypeAliasIterator getAliasIterator(void) const; 00459 00460 00465 FalagardMappingIterator getFalagardMappingIterator() const; 00466 }; 00467 00468 //----------------------------------------------------------------------------// 00469 template <typename T> 00470 void WindowFactoryManager::addFactory() 00471 { 00472 // create the factory object 00473 WindowFactory* factory = new T; 00474 00475 // only do the actual add now if our singleton has already been created 00476 if (WindowFactoryManager::getSingletonPtr()) 00477 { 00478 Logger::getSingleton().logEvent("Created WindowFactory for '" + 00479 factory->getTypeName() + 00480 "' windows."); 00481 // add the factory we just created 00482 CEGUI_TRY 00483 { 00484 WindowFactoryManager::getSingleton().addFactory(factory); 00485 } 00486 CEGUI_CATCH (Exception&) 00487 { 00488 Logger::getSingleton().logEvent("Deleted WindowFactory for '" + 00489 factory->getTypeName() + 00490 "' windows."); 00491 // delete the factory object 00492 delete factory; 00493 CEGUI_RETHROW; 00494 } 00495 } 00496 00497 d_ownedFactories.push_back(factory); 00498 } 00499 00500 } // End of CEGUI namespace section 00501 00502 00503 #if defined(_MSC_VER) 00504 # pragma warning(pop) 00505 #endif 00506 00507 #endif // end of guard _CEGUIWindowFactoryManager_h_