Crazy Eddies GUI System  0.7.8
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  String d_effectName;
74  };
75 
80  class CEGUIEXPORT AliasTargetStack
81  {
82  public:
88 
89 
95 
96 
104  const String& getActiveTarget(void) const;
105 
113  uint getStackedTargetCount(void) const;
114 
115 
116  private:
117  friend class WindowFactoryManager;
118  typedef std::vector<String> TargetTypeStack;
119 
120  TargetTypeStack d_targetStack;
121  };
122 
123 
124  /*************************************************************************
125  Construction and Destruction
126  *************************************************************************/
131  WindowFactoryManager(void);
132 
133 
139  {
140  Logger::getSingleton().logEvent("CEGUI::WindowFactoryManager singleton destroyed");
141  }
142 
143 
144  /*************************************************************************
145  Public Interface
146  *************************************************************************/
160  void addFactory(WindowFactory* factory);
161 
175  template <typename T>
176  static void addFactory();
177 
178 
193  void removeFactory(const String& name);
194 
195 
210  void removeFactory(WindowFactory* factory);
211 
212 
220  void removeAllFactories(void);
221 
222 
235  WindowFactory* getFactory(const String& type) const;
236 
237 
252  bool isFactoryPresent(const String& name) const;
253 
254 
280  void addWindowTypeAlias(const String& aliasName, const String& targetType);
281 
282 
300  void removeWindowTypeAlias(const String& aliasName, const String& targetType);
301 
333  void addFalagardWindowMapping(const String& newType,
334  const String& targetType,
335  const String& lookName,
336  const String& renderer,
337  const String& effectName = String(""));
338 
346  void removeFalagardWindowMapping(const String& type);
347 
359  bool isFalagardMappedType(const String& type) const;
360 
373  const String& getMappedLookForType(const String& type) const;
374 
387  const String& getMappedRendererForType(const String& type) const;
388 
407  String getDereferencedAliasType(const String& type) const;
408 
421  const FalagardWindowMapping& getFalagardMappingForType(const String& type) const;
422 
423 private:
424  /*************************************************************************
425  Implementation Data
426  *************************************************************************/
427  typedef std::map<String, WindowFactory*, String::FastLessCompare> WindowFactoryRegistry;
428  typedef std::map<String, AliasTargetStack, String::FastLessCompare> TypeAliasRegistry;
429  typedef std::map<String, FalagardWindowMapping, String::FastLessCompare> FalagardMapRegistry;
430 
431  typedef std::vector<WindowFactory*> OwnedWindowFactoryList;
432 
433  WindowFactoryRegistry d_factoryRegistry;
434  TypeAliasRegistry d_aliasRegistry;
435  FalagardMapRegistry d_falagardRegistry;
436 
437  static OwnedWindowFactoryList d_ownedFactories;
438 
439 public:
440  /*************************************************************************
441  Iterator stuff
442  *************************************************************************/
443  typedef ConstBaseIterator<WindowFactoryRegistry> WindowFactoryIterator;
444  typedef ConstBaseIterator<TypeAliasRegistry> TypeAliasIterator;
445  typedef ConstBaseIterator<FalagardMapRegistry> FalagardMappingIterator;
446 
451  WindowFactoryIterator getIterator(void) const;
452 
453 
458  TypeAliasIterator getAliasIterator(void) const;
459 
460 
465  FalagardMappingIterator getFalagardMappingIterator() const;
466 };
467 
468 //----------------------------------------------------------------------------//
469 template <typename T>
471 {
472  // create the factory object
473  WindowFactory* factory = new T;
474 
475  // only do the actual add now if our singleton has already been created
476  if (WindowFactoryManager::getSingletonPtr())
477  {
478  Logger::getSingleton().logEvent("Created WindowFactory for '" +
479  factory->getTypeName() +
480  "' windows.");
481  // add the factory we just created
482  CEGUI_TRY
483  {
484  WindowFactoryManager::getSingleton().addFactory(factory);
485  }
486  CEGUI_CATCH (Exception&)
487  {
488  Logger::getSingleton().logEvent("Deleted WindowFactory for '" +
489  factory->getTypeName() +
490  "' windows.");
491  // delete the factory object
492  delete factory;
493  CEGUI_RETHROW;
494  }
495  }
496 
497  d_ownedFactories.push_back(factory);
498 }
499 
500 } // End of CEGUI namespace section
501 
502 
503 #if defined(_MSC_VER)
504 # pragma warning(pop)
505 #endif
506 
507 #endif // end of guard _CEGUIWindowFactoryManager_h_