Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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 "CEGUIExceptions.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 : public Singleton<WindowFactoryManager>
62 {
63 public:
68  struct CEGUIEXPORT FalagardWindowMapping
69  {
70  String d_windowType;
71  String d_lookName;
72  String d_baseType;
73  String d_rendererType;
74  String d_effectName;
75  };
76 
81  class CEGUIEXPORT AliasTargetStack
82  {
83  public:
89 
90 
96 
97 
105  const String& getActiveTarget(void) const;
106 
114  uint getStackedTargetCount(void) const;
115 
116 
117  private:
118  friend class WindowFactoryManager;
119  typedef std::vector<String> TargetTypeStack;
120 
121  TargetTypeStack d_targetStack;
122  };
123 
124 
125  /*************************************************************************
126  Construction and Destruction
127  *************************************************************************/
132  WindowFactoryManager(void);
133 
134 
140  {
141  Logger::getSingleton().logEvent("CEGUI::WindowFactoryManager singleton destroyed");
142  }
143 
144 
145  /*************************************************************************
146  Public Interface
147  *************************************************************************/
161  void addFactory(WindowFactory* factory);
162 
176  template <typename T>
177  static void addFactory();
178 
179 
194  void removeFactory(const String& name);
195 
196 
211  void removeFactory(WindowFactory* factory);
212 
213 
221  void removeAllFactories(void);
222 
223 
236  WindowFactory* getFactory(const String& type) const;
237 
238 
253  bool isFactoryPresent(const String& name) const;
254 
255 
281  void addWindowTypeAlias(const String& aliasName, const String& targetType);
282 
283 
301  void removeWindowTypeAlias(const String& aliasName, const String& targetType);
302 
334  void addFalagardWindowMapping(const String& newType,
335  const String& targetType,
336  const String& lookName,
337  const String& renderer,
338  const String& effectName = String(""));
339 
347  void removeFalagardWindowMapping(const String& type);
348 
360  bool isFalagardMappedType(const String& type) const;
361 
374  const String& getMappedLookForType(const String& type) const;
375 
388  const String& getMappedRendererForType(const String& type) const;
389 
408  String getDereferencedAliasType(const String& type) const;
409 
422  const FalagardWindowMapping& getFalagardMappingForType(const String& type) const;
423 
424 private:
425  /*************************************************************************
426  Implementation Data
427  *************************************************************************/
428  typedef std::map<String, WindowFactory*, String::FastLessCompare> WindowFactoryRegistry;
429  typedef std::map<String, AliasTargetStack, String::FastLessCompare> TypeAliasRegistry;
430  typedef std::map<String, FalagardWindowMapping, String::FastLessCompare> FalagardMapRegistry;
431 
432  typedef std::vector<WindowFactory*> OwnedWindowFactoryList;
433 
434  WindowFactoryRegistry d_factoryRegistry;
435  TypeAliasRegistry d_aliasRegistry;
436  FalagardMapRegistry d_falagardRegistry;
437 
438  static OwnedWindowFactoryList d_ownedFactories;
439 
440 public:
441  /*************************************************************************
442  Iterator stuff
443  *************************************************************************/
444  typedef ConstBaseIterator<WindowFactoryRegistry> WindowFactoryIterator;
445  typedef ConstBaseIterator<TypeAliasRegistry> TypeAliasIterator;
446  typedef ConstBaseIterator<FalagardMapRegistry> FalagardMappingIterator;
447 
452  WindowFactoryIterator getIterator(void) const;
453 
454 
459  TypeAliasIterator getAliasIterator(void) const;
460 
461 
466  FalagardMappingIterator getFalagardMappingIterator() const;
467 };
468 
469 //----------------------------------------------------------------------------//
470 template <typename T>
472 {
473  // create the factory object
474  WindowFactory* factory = new T;
475 
476  // only do the actual add now if our singleton has already been created
477  if (WindowFactoryManager::getSingletonPtr())
478  {
479  Logger::getSingleton().logEvent("Created WindowFactory for '" +
480  factory->getTypeName() +
481  "' windows.");
482  // add the factory we just created
483  CEGUI_TRY
484  {
485  WindowFactoryManager::getSingleton().addFactory(factory);
486  }
487  CEGUI_CATCH (Exception&)
488  {
489  Logger::getSingleton().logEvent("Deleted WindowFactory for '" +
490  factory->getTypeName() +
491  "' windows.");
492  // delete the factory object
493  delete factory;
494  CEGUI_RETHROW;
495  }
496  }
497 
498  d_ownedFactories.push_back(factory);
499 }
500 
501 } // End of CEGUI namespace section
502 
503 
504 #if defined(_MSC_VER)
505 # pragma warning(pop)
506 #endif
507 
508 #endif // end of guard _CEGUIWindowFactoryManager_h_