Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
WindowFactoryManager.h
1 /***********************************************************************
2  filename: CEGUIWindowFactoryManager.h
3  created: 22/2/2004
4  author: Paul D Turner
5 
6  purpose: Defines interface for WindowFactoryManager class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIWindowFactoryManager_h_
31 #define _CEGUIWindowFactoryManager_h_
32 
33 #include "CEGUI/Base.h"
34 #include "CEGUI/String.h"
35 #include "CEGUI/Singleton.h"
36 #include "CEGUI/Logger.h"
37 #include "CEGUI/IteratorBase.h"
38 #include "CEGUI/WindowFactory.h"
39 #include "CEGUI/TplWindowFactory.h"
40 #include "CEGUI/Exceptions.h"
41 #include <map>
42 #include <vector>
43 
44 #if defined(_MSC_VER)
45 # pragma warning(push)
46 # pragma warning(disable : 4275)
47 # pragma warning(disable : 4251)
48 #endif
49 
50 
51 // Start of CEGUI namespace section
52 namespace CEGUI
53 {
62 class CEGUIEXPORT WindowFactoryManager :
63  public Singleton<WindowFactoryManager>,
64  public AllocatedObject<WindowFactoryManager>
65 {
66 public:
71  struct CEGUIEXPORT FalagardWindowMapping
72  {
73  String d_windowType;
74  String d_lookName;
75  String d_baseType;
76  String d_rendererType;
77  String d_effectName;
78  };
79 
84  class CEGUIEXPORT AliasTargetStack
85  {
86  public:
92 
93 
99 
100 
108  const String& getActiveTarget(void) const;
109 
117  uint getStackedTargetCount(void) const;
118 
119 
120  private:
121  friend class WindowFactoryManager;
122 
123  typedef std::vector<String
124  CEGUI_VECTOR_ALLOC(String)> TargetTypeStack;
125 
126  TargetTypeStack d_targetStack;
127  };
128 
129 
130  /*************************************************************************
131  Construction and Destruction
132  *************************************************************************/
137  WindowFactoryManager(void);
138 
139 
145  {
146  Logger::getSingleton().logEvent("CEGUI::WindowFactoryManager singleton destroyed");
147  }
148 
149 
150  /*************************************************************************
151  Public Interface
152  *************************************************************************/
166  void addFactory(WindowFactory* factory);
167 
181  template <typename T>
182  static void addFactory();
183 
198  template <typename T>
199  static void addWindowType();
200 
215  void removeFactory(const String& name);
216 
217 
232  void removeFactory(WindowFactory* factory);
233 
234 
242  void removeAllFactories(void);
243 
244 
257  WindowFactory* getFactory(const String& type) const;
258 
259 
274  bool isFactoryPresent(const String& name) const;
275 
276 
302  void addWindowTypeAlias(const String& aliasName, const String& targetType);
303 
304 
322  void removeWindowTypeAlias(const String& aliasName, const String& targetType);
323 
328  void removeAllWindowTypeAliases();
329 
361  void addFalagardWindowMapping(const String& newType,
362  const String& targetType,
363  const String& lookName,
364  const String& renderer,
365  const String& effectName = String(""));
366 
374  void removeFalagardWindowMapping(const String& type);
375 
380  void removeAllFalagardWindowMappings();
381 
393  bool isFalagardMappedType(const String& type) const;
394 
407  const String& getMappedLookForType(const String& type) const;
408 
421  const String& getMappedRendererForType(const String& type) const;
422 
441  String getDereferencedAliasType(const String& type) const;
442 
455  const FalagardWindowMapping& getFalagardMappingForType(const String& type) const;
456 
457 private:
458  /*************************************************************************
459  Implementation Data
460  *************************************************************************/
461  typedef std::map<String, WindowFactory*, StringFastLessCompare
462  CEGUI_MAP_ALLOC(String, WindowFactory*)> WindowFactoryRegistry;
463  typedef std::map<String, AliasTargetStack, StringFastLessCompare
464  CEGUI_MAP_ALLOC(String, AliasTargetStack)> TypeAliasRegistry;
465  typedef std::map<String, FalagardWindowMapping, StringFastLessCompare
466  CEGUI_MAP_ALLOC(String, FalagardWindowMapping)> FalagardMapRegistry;
467 
468  typedef std::vector<WindowFactory*
469  CEGUI_VECTOR_ALLOC(WindowFactory*)> OwnedWindowFactoryList;
470 
471  WindowFactoryRegistry d_factoryRegistry;
472  TypeAliasRegistry d_aliasRegistry;
473  FalagardMapRegistry d_falagardRegistry;
474 
475  static OwnedWindowFactoryList d_ownedFactories;
476 
477 public:
478  /*************************************************************************
479  Iterator stuff
480  *************************************************************************/
481  typedef ConstMapIterator<WindowFactoryRegistry> WindowFactoryIterator;
482  typedef ConstMapIterator<TypeAliasRegistry> TypeAliasIterator;
483  typedef ConstMapIterator<FalagardMapRegistry> FalagardMappingIterator;
484 
489  WindowFactoryIterator getIterator(void) const;
490 
491 
496  TypeAliasIterator getAliasIterator(void) const;
497 
498 
503  FalagardMappingIterator getFalagardMappingIterator() const;
504 };
505 
506 //----------------------------------------------------------------------------//
507 template <typename T>
509 {
510  // create the factory object
511  WindowFactory* factory = CEGUI_NEW_AO T;
512 
513  // only do the actual add now if our singleton has already been created
514  if (WindowFactoryManager::getSingletonPtr())
515  {
516  Logger::getSingleton().logEvent("Created WindowFactory for '" +
517  factory->getTypeName() +
518  "' windows.");
519  // add the factory we just created
520  CEGUI_TRY
521  {
522  WindowFactoryManager::getSingleton().addFactory(factory);
523  }
524  CEGUI_CATCH (Exception&)
525  {
526  Logger::getSingleton().logEvent("Deleted WindowFactory for '" +
527  factory->getTypeName() +
528  "' windows.");
529  // delete the factory object
530  CEGUI_DELETE_AO factory;
531  CEGUI_RETHROW;
532  }
533  }
534 
535  d_ownedFactories.push_back(factory);
536 }
537 
538 //----------------------------------------------------------------------------//
539 template <typename T>
541 {
542  WindowFactoryManager::addFactory<TplWindowFactory<T> >();
543 }
544 
545 //----------------------------------------------------------------------------//
546 
547 } // End of CEGUI namespace section
548 
549 
550 #if defined(_MSC_VER)
551 # pragma warning(pop)
552 #endif
553 
554 #endif // end of guard _CEGUIWindowFactoryManager_h_