Crazy Eddie's GUI System  0.8.7
WindowFactoryManager.h
1 /***********************************************************************
2  created: 22/2/2004
3  author: Paul D Turner
4 
5  purpose: Defines interface for WindowFactoryManager class
6 *************************************************************************/
7 /***************************************************************************
8  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUIWindowFactoryManager_h_
30 #define _CEGUIWindowFactoryManager_h_
31 
32 #include "CEGUI/Base.h"
33 #include "CEGUI/String.h"
34 #include "CEGUI/Singleton.h"
35 #include "CEGUI/Logger.h"
36 #include "CEGUI/IteratorBase.h"
37 #include "CEGUI/WindowFactory.h"
38 #include "CEGUI/TplWindowFactory.h"
39 #include "CEGUI/Exceptions.h"
40 #include <map>
41 #include <vector>
42 
43 #if defined(_MSC_VER)
44 # pragma warning(push)
45 # pragma warning(disable : 4275)
46 # pragma warning(disable : 4251)
47 #endif
48 
49 
50 // Start of CEGUI namespace section
51 namespace CEGUI
52 {
61 class CEGUIEXPORT WindowFactoryManager :
62  public Singleton<WindowFactoryManager>,
63  public AllocatedObject<WindowFactoryManager>
64 {
65 public:
70  struct CEGUIEXPORT FalagardWindowMapping
71  {
72  String d_windowType;
73  String d_lookName;
74  String d_baseType;
75  String d_rendererType;
76  String d_effectName;
77  };
78 
83  class CEGUIEXPORT AliasTargetStack
84  {
85  public:
91 
92 
98 
99 
107  const String& getActiveTarget(void) const;
108 
116  uint getStackedTargetCount(void) const;
117 
118 
119  private:
120  friend class WindowFactoryManager;
121 
122  typedef std::vector<String
123  CEGUI_VECTOR_ALLOC(String)> TargetTypeStack;
124 
125  TargetTypeStack d_targetStack;
126  };
127 
128 
129  /*************************************************************************
130  Construction and Destruction
131  *************************************************************************/
136  WindowFactoryManager(void);
137 
138 
144  {
145  Logger::getSingleton().logEvent("CEGUI::WindowFactoryManager singleton destroyed");
146  }
147 
148 
149  /*************************************************************************
150  Public Interface
151  *************************************************************************/
165  void addFactory(WindowFactory* factory);
166 
180  template <typename T>
181  static void addFactory();
182 
197  template <typename T>
198  static void addWindowType();
199 
214  void removeFactory(const String& name);
215 
216 
231  void removeFactory(WindowFactory* factory);
232 
233 
241  void removeAllFactories(void);
242 
243 
256  WindowFactory* getFactory(const String& type) const;
257 
258 
273  bool isFactoryPresent(const String& name) const;
274 
275 
301  void addWindowTypeAlias(const String& aliasName, const String& targetType);
302 
303 
321  void removeWindowTypeAlias(const String& aliasName, const String& targetType);
322 
327  void removeAllWindowTypeAliases();
328 
360  void addFalagardWindowMapping(const String& newType,
361  const String& targetType,
362  const String& lookName,
363  const String& renderer,
364  const String& effectName = String(""));
365 
373  void removeFalagardWindowMapping(const String& type);
374 
379  void removeAllFalagardWindowMappings();
380 
392  bool isFalagardMappedType(const String& type) const;
393 
406  const String& getMappedLookForType(const String& type) const;
407 
420  const String& getMappedRendererForType(const String& type) const;
421 
440  String getDereferencedAliasType(const String& type) const;
441 
454  const FalagardWindowMapping& getFalagardMappingForType(const String& type) const;
455 
456 private:
457  /*************************************************************************
458  Implementation Data
459  *************************************************************************/
460  typedef std::map<String, WindowFactory*, StringFastLessCompare
461  CEGUI_MAP_ALLOC(String, WindowFactory*)> WindowFactoryRegistry;
462  typedef std::map<String, AliasTargetStack, StringFastLessCompare
463  CEGUI_MAP_ALLOC(String, AliasTargetStack)> TypeAliasRegistry;
464  typedef std::map<String, FalagardWindowMapping, StringFastLessCompare
465  CEGUI_MAP_ALLOC(String, FalagardWindowMapping)> FalagardMapRegistry;
466  typedef std::vector<WindowFactory*
468  CEGUI_VECTOR_ALLOC(WindowFactory*)> OwnedWindowFactoryList;
469 
470  WindowFactoryRegistry d_factoryRegistry;
471  TypeAliasRegistry d_aliasRegistry;
472  FalagardMapRegistry d_falagardRegistry;
473  static OwnedWindowFactoryList d_ownedFactories;
475 
476 public:
477  /*************************************************************************
478  Iterator stuff
479  *************************************************************************/
480  typedef ConstMapIterator<WindowFactoryRegistry> WindowFactoryIterator;
481  typedef ConstMapIterator<TypeAliasRegistry> TypeAliasIterator;
482  typedef ConstMapIterator<FalagardMapRegistry> FalagardMappingIterator;
483 
488  WindowFactoryIterator getIterator(void) const;
489 
490 
495  TypeAliasIterator getAliasIterator(void) const;
496 
497 
502  FalagardMappingIterator getFalagardMappingIterator() const;
503 };
504 
505 //----------------------------------------------------------------------------//
506 template <typename T>
508 {
509  // create the factory object
510  WindowFactory* factory = CEGUI_NEW_AO T;
511 
512  // only do the actual add now if our singleton has already been created
513  if (WindowFactoryManager::getSingletonPtr())
514  {
515  Logger::getSingleton().logEvent("Created WindowFactory for '" +
516  factory->getTypeName() +
517  "' windows.");
518  // add the factory we just created
519  CEGUI_TRY
520  {
521  WindowFactoryManager::getSingleton().addFactory(factory);
522  }
523  CEGUI_CATCH (Exception&)
524  {
525  Logger::getSingleton().logEvent("Deleted WindowFactory for '" +
526  factory->getTypeName() +
527  "' windows.");
528  // delete the factory object
529  CEGUI_DELETE_AO factory;
530  CEGUI_RETHROW;
531  }
532  }
533 
534  d_ownedFactories.push_back(factory);
535 }
536 
537 //----------------------------------------------------------------------------//
538 template <typename T>
540 {
541  WindowFactoryManager::addFactory<TplWindowFactory<T> >();
542 }
543 
544 //----------------------------------------------------------------------------//
545 
546 } // End of CEGUI namespace section
547 
548 
549 #if defined(_MSC_VER)
550 # pragma warning(pop)
551 #endif
552 
553 #endif // end of guard _CEGUIWindowFactoryManager_h_
Functor that can be used as comparator in a std::map with String keys. It's faster than using the def...
Definition: String.h:5579
Definition: MemoryAllocatedObject.h:109
AliasTargetStack(void)
Constructor for WindowAliasTargetStack objects.
Definition: WindowFactoryManager.h:90
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
static void addFactory()
Creates a WindowFactory of the type T and adds it to the system for use. The created WindowFactory wi...
Definition: WindowFactoryManager.h:507
static void addWindowType()
Internally creates a factory suitable for creating Window objects of the given type and adds it to th...
Definition: WindowFactoryManager.h:539
Class that manages WindowFactory objects.
Definition: WindowFactoryManager.h:61
~WindowFactoryManager(void)
Destructor for WindowFactoryManager objects.
Definition: WindowFactoryManager.h:143
~AliasTargetStack(void)
Destructor for WindowAliasTargetStack objects.
Definition: WindowFactoryManager.h:97
Class used to track active alias targets for Window factory types.
Definition: WindowFactoryManager.h:83
struct used to hold mapping information required to create a falagard based window.
Definition: WindowFactoryManager.h:70
const String & getTypeName() const
Get the string that describes the type of Window object this WindowFactory produces.
Definition: WindowFactory.h:152
Definition: Singleton.h:55
Root exception class used within the GUI system.
Definition: Exceptions.h:46
iterator class for maps
Definition: IteratorBase.h:196
Abstract class that defines the required interface for all WindowFactory objects. ...
Definition: WindowFactory.h:115
String class used within the GUI system.
Definition: String.h:62