Crazy Eddies GUI System  0.6.2
CEGUIWindowFactoryManager.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 "CEGUIBase.h"
34 #include "CEGUIString.h"
35 #include "CEGUISingleton.h"
36 #include "CEGUILogger.h"
37 #include "CEGUIIteratorBase.h"
38 #include "CEGUIWindowFactory.h"
39 #include <map>
40 #include <vector>
41 
42 #if defined(_MSC_VER)
43 # pragma warning(push)
44 # pragma warning(disable : 4275)
45 # pragma warning(disable : 4251)
46 #endif
47 
48 
49 // Start of CEGUI namespace section
50 namespace CEGUI
51 {
60 class CEGUIEXPORT WindowFactoryManager : public Singleton<WindowFactoryManager>
61 {
62 public:
67  struct CEGUIEXPORT FalagardWindowMapping
68  {
69  String d_windowType;
70  String d_lookName;
71  String d_baseType;
72  String d_rendererType;
73  };
74 
79  class CEGUIEXPORT AliasTargetStack
80  {
81  public:
87 
88 
94 
95 
103  const String& getActiveTarget(void) const;
104 
112  uint getStackedTargetCount(void) const;
113 
114 
115  private:
116  friend class WindowFactoryManager;
117  typedef std::vector<String> TargetTypeStack;
118 
119  TargetTypeStack d_targetStack;
120  };
121 
122 
123  /*************************************************************************
124  Construction and Destruction
125  *************************************************************************/
130  WindowFactoryManager(void);
131 
132 
138  {
139  Logger::getSingleton().logEvent("CEGUI::WindowFactoryManager singleton destroyed");
140  }
141 
142 
143  /*************************************************************************
144  Public Interface
145  *************************************************************************/
159  void addFactory(WindowFactory* factory);
160 
174  template <typename T>
175  static void addFactory();
176 
177 
192  void removeFactory(const String& name);
193 
194 
209  void removeFactory(WindowFactory* factory);
210 
211 
219  void removeAllFactories(void);
220 
221 
234  WindowFactory* getFactory(const String& type) const;
235 
236 
251  bool isFactoryPresent(const String& name) const;
252 
253 
279  void addWindowTypeAlias(const String& aliasName, const String& targetType);
280 
281 
299  void removeWindowTypeAlias(const String& aliasName, const String& targetType);
300 
329  void addFalagardWindowMapping(const String& newType, const String& targetType, const String& lookName, const String& renderer);
330 
338  void removeFalagardWindowMapping(const String& type);
339 
351  bool isFalagardMappedType(const String& type) const;
352 
365  const String& getMappedLookForType(const String& type) const;
366 
379  const String& getMappedRendererForType(const String& type) const;
380 
399  String getDereferencedAliasType(const String& type) const;
400 
413  const FalagardWindowMapping& getFalagardMappingForType(const String& type) const;
414 
415 private:
416  /*************************************************************************
417  Implementation Data
418  *************************************************************************/
419  typedef std::map<String, WindowFactory*, String::FastLessCompare> WindowFactoryRegistry;
420  typedef std::map<String, AliasTargetStack, String::FastLessCompare> TypeAliasRegistry;
421  typedef std::map<String, FalagardWindowMapping, String::FastLessCompare> FalagardMapRegistry;
422 
423  typedef std::vector<WindowFactory*> OwnedWindowFactoryList;
424 
425  WindowFactoryRegistry d_factoryRegistry;
426  TypeAliasRegistry d_aliasRegistry;
427  FalagardMapRegistry d_falagardRegistry;
428 
429  static OwnedWindowFactoryList d_ownedFactories;
430 
431 public:
432  /*************************************************************************
433  Iterator stuff
434  *************************************************************************/
436  typedef ConstBaseIterator<TypeAliasRegistry> TypeAliasIterator;
438 
443  WindowFactoryIterator getIterator(void) const;
444 
445 
450  TypeAliasIterator getAliasIterator(void) const;
451 
452 
457  FalagardMappingIterator getFalagardMappingIterator() const;
458 };
459 
460 //----------------------------------------------------------------------------//
461 template <typename T>
463 {
464  // create the factory object
465  WindowFactory* factory = new T;
466 
467  // only do the actual add now if our singleton has already been created
468  if (WindowFactoryManager::getSingletonPtr())
469  {
470  Logger::getSingleton().logEvent("Created WindowFactory for '" +
471  factory->getTypeName() +
472  "' windows.");
473  // add the factory we just created
474  try
475  {
476  WindowFactoryManager::getSingleton().addFactory(factory);
477  }
478  catch (Exception& e)
479  {
480  Logger::getSingleton().logEvent("Deleted WindowFactory for '" +
481  factory->getTypeName() +
482  "' windows.");
483  // delete the factory object
484  delete factory;
485  throw;
486  }
487  }
488 
489  d_ownedFactories.push_back(factory);
490 }
491 
492 } // End of CEGUI namespace section
493 
494 
495 #if defined(_MSC_VER)
496 # pragma warning(pop)
497 #endif
498 
499 #endif // end of guard _CEGUIWindowFactoryManager_h_