Crazy Eddies GUI System  0.7.8
CEGUIWindowRendererManager.h
1 /***********************************************************************
2  filename: CEGUIWindowRenderer.h
3  created: Jan 11 2006
4  author: Tomas Lindquist Olsen
5 
6  purpose: Defines interface for the WindowRendererManager class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2009 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 _CEGUIWindowRendererManager_h_
31 #define _CEGUIWindowRendererManager_h_
32 
33 #include "CEGUISingleton.h"
34 #include "CEGUIWindowRenderer.h"
35 #include "CEGUILogger.h"
36 #include "CEGUIExceptions.h"
37 #include <map>
38 #include <vector>
39 
40 #if defined(_MSC_VER)
41 # pragma warning(push)
42 # pragma warning(disable : 4251)
43 #endif
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
48 class CEGUIEXPORT WindowRendererManager : public Singleton<WindowRendererManager>
49 {
50 public:
51  /*************************************************************************
52  Contructor / Destructor
53  *************************************************************************/
56 
57  /*************************************************************************
58  Singleton
59  *************************************************************************/
60  static WindowRendererManager& getSingleton();
61  static WindowRendererManager* getSingletonPtr();
62 
63  /*************************************************************************
64  Accessors
65  *************************************************************************/
66  bool isFactoryPresent(const String& name) const;
67  WindowRendererFactory* getFactory(const String& name) const;
68 
69  /*************************************************************************
70  Manipulators
71  *************************************************************************/
85  template <typename T>
86  static void addFactory();
87  void addFactory(WindowRendererFactory* wr);
88  void removeFactory(const String& name);
89 
90  /*************************************************************************
91  Factory usage
92  *************************************************************************/
93  WindowRenderer* createWindowRenderer(const String& name);
94  void destroyWindowRenderer(WindowRenderer* wr);
95 
96 private:
97  /*************************************************************************
98  Private implementation
99  *************************************************************************/
100 
101  /*************************************************************************
102  Implementation data
103  *************************************************************************/
104  typedef std::map<String, WindowRendererFactory*, String::FastLessCompare> WR_Registry;
105  WR_Registry d_wrReg;
106 
108  typedef std::vector<WindowRendererFactory*> OwnedFactoryList;
110  static OwnedFactoryList d_ownedFactories;
111 };
112 
113 //----------------------------------------------------------------------------//
114 template <typename T>
116 {
117  // create the factory object
118  WindowRendererFactory* factory = new T;
119 
120  // only do the actual add now if our singleton has already been created
121  if (WindowRendererManager::getSingletonPtr())
122  {
123  Logger::getSingleton().logEvent("Created WindowRendererFactory for '" +
124  factory->getName() +
125  "' WindowRenderers.");
126  // add the factory we just created
127  CEGUI_TRY
128  {
129  WindowRendererManager::getSingleton().addFactory(factory);
130  }
131  CEGUI_CATCH (Exception&)
132  {
133  Logger::getSingleton().logEvent("Deleted WindowRendererFactory for "
134  "'" + factory->getName() +
135  "' WindowRenderers.");
136  // delete the factory object
137  delete factory;
138  CEGUI_RETHROW;
139  }
140  }
141 
142  d_ownedFactories.push_back(factory);
143 }
144 
145 //----------------------------------------------------------------------------//
146 
147 
148 } // End of CEGUI namespace
149 
150 #if defined(_MSC_VER)
151 # pragma warning(pop)
152 #endif
153 
154 #endif // _CEGUIWindowRendererManager_h_