Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 22/2/2004 00003 author: Paul D Turner 00004 00005 purpose: Defines interface for WindowFactoryManager class 00006 *************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining 00011 * a copy of this software and associated documentation files (the 00012 * "Software"), to deal in the Software without restriction, including 00013 * without limitation the rights to use, copy, modify, merge, publish, 00014 * distribute, sublicense, and/or sell copies of the Software, and to 00015 * permit persons to whom the Software is furnished to do so, subject to 00016 * the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be 00019 * included in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00024 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00025 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00026 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00027 * OTHER DEALINGS IN THE SOFTWARE. 00028 ***************************************************************************/ 00029 #ifndef _CEGUIWindowFactoryManager_h_ 00030 #define _CEGUIWindowFactoryManager_h_ 00031 00032 #include "CEGUI/Base.h" 00033 #include "CEGUI/String.h" 00034 #include "CEGUI/Singleton.h" 00035 #include "CEGUI/Logger.h" 00036 #include "CEGUI/IteratorBase.h" 00037 #include "CEGUI/WindowFactory.h" 00038 #include "CEGUI/TplWindowFactory.h" 00039 #include "CEGUI/Exceptions.h" 00040 #include <map> 00041 #include <vector> 00042 00043 #if defined(_MSC_VER) 00044 # pragma warning(push) 00045 # pragma warning(disable : 4275) 00046 # pragma warning(disable : 4251) 00047 #endif 00048 00049 00050 // Start of CEGUI namespace section 00051 namespace CEGUI 00052 { 00061 class CEGUIEXPORT WindowFactoryManager : 00062 public Singleton<WindowFactoryManager>, 00063 public AllocatedObject<WindowFactoryManager> 00064 { 00065 public: 00070 struct CEGUIEXPORT FalagardWindowMapping 00071 { 00072 String d_windowType; 00073 String d_lookName; 00074 String d_baseType; 00075 String d_rendererType; 00076 String d_effectName; 00077 }; 00078 00083 class CEGUIEXPORT AliasTargetStack 00084 { 00085 public: 00090 AliasTargetStack(void) {} 00091 00092 00097 ~AliasTargetStack(void) {} 00098 00099 00107 const String& getActiveTarget(void) const; 00108 00116 uint getStackedTargetCount(void) const; 00117 00118 00119 private: 00120 friend class WindowFactoryManager; 00121 00122 typedef std::vector<String 00123 CEGUI_VECTOR_ALLOC(String)> TargetTypeStack; 00124 00125 TargetTypeStack d_targetStack; 00126 }; 00127 00128 00129 /************************************************************************* 00130 Construction and Destruction 00131 *************************************************************************/ 00136 WindowFactoryManager(void); 00137 00138 00143 ~WindowFactoryManager(void) 00144 { 00145 Logger::getSingleton().logEvent("CEGUI::WindowFactoryManager singleton destroyed"); 00146 } 00147 00148 00149 /************************************************************************* 00150 Public Interface 00151 *************************************************************************/ 00165 void addFactory(WindowFactory* factory); 00166 00180 template <typename T> 00181 static void addFactory(); 00182 00197 template <typename T> 00198 static void addWindowType(); 00199 00214 void removeFactory(const String& name); 00215 00216 00231 void removeFactory(WindowFactory* factory); 00232 00233 00241 void removeAllFactories(void); 00242 00243 00256 WindowFactory* getFactory(const String& type) const; 00257 00258 00273 bool isFactoryPresent(const String& name) const; 00274 00275 00301 void addWindowTypeAlias(const String& aliasName, const String& targetType); 00302 00303 00321 void removeWindowTypeAlias(const String& aliasName, const String& targetType); 00322 00327 void removeAllWindowTypeAliases(); 00328 00360 void addFalagardWindowMapping(const String& newType, 00361 const String& targetType, 00362 const String& lookName, 00363 const String& renderer, 00364 const String& effectName = String("")); 00365 00373 void removeFalagardWindowMapping(const String& type); 00374 00379 void removeAllFalagardWindowMappings(); 00380 00392 bool isFalagardMappedType(const String& type) const; 00393 00406 const String& getMappedLookForType(const String& type) const; 00407 00420 const String& getMappedRendererForType(const String& type) const; 00421 00440 String getDereferencedAliasType(const String& type) const; 00441 00454 const FalagardWindowMapping& getFalagardMappingForType(const String& type) const; 00455 00456 private: 00457 /************************************************************************* 00458 Implementation Data 00459 *************************************************************************/ 00460 typedef std::map<String, WindowFactory*, StringFastLessCompare 00461 CEGUI_MAP_ALLOC(String, WindowFactory*)> WindowFactoryRegistry; 00462 typedef std::map<String, AliasTargetStack, StringFastLessCompare 00463 CEGUI_MAP_ALLOC(String, AliasTargetStack)> TypeAliasRegistry; 00464 typedef std::map<String, FalagardWindowMapping, StringFastLessCompare 00465 CEGUI_MAP_ALLOC(String, FalagardWindowMapping)> FalagardMapRegistry; 00466 00467 typedef std::vector<WindowFactory* 00468 CEGUI_VECTOR_ALLOC(WindowFactory*)> OwnedWindowFactoryList; 00469 00470 WindowFactoryRegistry d_factoryRegistry; 00471 TypeAliasRegistry d_aliasRegistry; 00472 FalagardMapRegistry d_falagardRegistry; 00473 00474 static OwnedWindowFactoryList d_ownedFactories; 00475 00476 public: 00477 /************************************************************************* 00478 Iterator stuff 00479 *************************************************************************/ 00480 typedef ConstMapIterator<WindowFactoryRegistry> WindowFactoryIterator; 00481 typedef ConstMapIterator<TypeAliasRegistry> TypeAliasIterator; 00482 typedef ConstMapIterator<FalagardMapRegistry> FalagardMappingIterator; 00483 00488 WindowFactoryIterator getIterator(void) const; 00489 00490 00495 TypeAliasIterator getAliasIterator(void) const; 00496 00497 00502 FalagardMappingIterator getFalagardMappingIterator() const; 00503 }; 00504 00505 //----------------------------------------------------------------------------// 00506 template <typename T> 00507 void WindowFactoryManager::addFactory() 00508 { 00509 // create the factory object 00510 WindowFactory* factory = CEGUI_NEW_AO T; 00511 00512 // only do the actual add now if our singleton has already been created 00513 if (WindowFactoryManager::getSingletonPtr()) 00514 { 00515 Logger::getSingleton().logEvent("Created WindowFactory for '" + 00516 factory->getTypeName() + 00517 "' windows."); 00518 // add the factory we just created 00519 CEGUI_TRY 00520 { 00521 WindowFactoryManager::getSingleton().addFactory(factory); 00522 } 00523 CEGUI_CATCH (Exception&) 00524 { 00525 Logger::getSingleton().logEvent("Deleted WindowFactory for '" + 00526 factory->getTypeName() + 00527 "' windows."); 00528 // delete the factory object 00529 CEGUI_DELETE_AO factory; 00530 CEGUI_RETHROW; 00531 } 00532 } 00533 00534 d_ownedFactories.push_back(factory); 00535 } 00536 00537 //----------------------------------------------------------------------------// 00538 template <typename T> 00539 void WindowFactoryManager::addWindowType() 00540 { 00541 WindowFactoryManager::addFactory<TplWindowFactory<T> >(); 00542 } 00543 00544 //----------------------------------------------------------------------------// 00545 00546 } // End of CEGUI namespace section 00547 00548 00549 #if defined(_MSC_VER) 00550 # pragma warning(pop) 00551 #endif 00552 00553 #endif // end of guard _CEGUIWindowFactoryManager_h_