Crazy Eddie's GUI System  0.8.3
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
WindowRendererManager.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 "CEGUI/Singleton.h"
34 #include "CEGUI/WindowRenderer.h"
35 #include "CEGUI/Logger.h"
36 #include "CEGUI/Exceptions.h"
37 #include "CEGUI/TplWindowRendererFactory.h"
38 #include <map>
39 #include <vector>
40 
41 #if defined(_MSC_VER)
42 # pragma warning(push)
43 # pragma warning(disable : 4251)
44 #endif
45 
46 // Start of CEGUI namespace section
47 namespace CEGUI
48 {
49 class CEGUIEXPORT WindowRendererManager :
50  public Singleton<WindowRendererManager>,
51  public AllocatedObject<WindowRendererManager>
52 {
53 public:
54  /*************************************************************************
55  Contructor / Destructor
56  *************************************************************************/
59 
60  /*************************************************************************
61  Singleton
62  *************************************************************************/
63  static WindowRendererManager& getSingleton();
64  static WindowRendererManager* getSingletonPtr();
65 
66  /*************************************************************************
67  Accessors
68  *************************************************************************/
69  bool isFactoryPresent(const String& name) const;
70  WindowRendererFactory* getFactory(const String& name) const;
71 
72  /*************************************************************************
73  Manipulators
74  *************************************************************************/
88  template <typename T>
89  static void addFactory();
90 
105  template <typename T>
106  static void addWindowRendererType();
107 
108  void addFactory(WindowRendererFactory* wr);
109  void removeFactory(const String& name);
110 
111  /*************************************************************************
112  Factory usage
113  *************************************************************************/
114  WindowRenderer* createWindowRenderer(const String& name);
115  void destroyWindowRenderer(WindowRenderer* wr);
116 
117 private:
118  /*************************************************************************
119  Private implementation
120  *************************************************************************/
121 
122  /*************************************************************************
123  Implementation data
124  *************************************************************************/
125  typedef std::map<String, WindowRendererFactory*, StringFastLessCompare> WR_Registry;
126  WR_Registry d_wrReg;
127 
129  typedef std::vector<WindowRendererFactory*
130  CEGUI_VECTOR_ALLOC(WindowRendererFactory*)> OwnedFactoryList;
132  static OwnedFactoryList d_ownedFactories;
133 };
134 
135 //----------------------------------------------------------------------------//
136 template <typename T>
138 {
139  // create the factory object
140  WindowRendererFactory* factory = CEGUI_NEW_AO T;
141 
142  // only do the actual add now if our singleton has already been created
143  if (WindowRendererManager::getSingletonPtr())
144  {
145  Logger::getSingleton().logEvent("Created WindowRendererFactory for '" +
146  factory->getName() +
147  "' WindowRenderers.");
148  // add the factory we just created
149  CEGUI_TRY
150  {
151  WindowRendererManager::getSingleton().addFactory(factory);
152  }
153  CEGUI_CATCH (Exception&)
154  {
155  Logger::getSingleton().logEvent("Deleted WindowRendererFactory for "
156  "'" + factory->getName() +
157  "' WindowRenderers.");
158  // delete the factory object
159  CEGUI_DELETE_AO factory;
160  CEGUI_RETHROW;
161  }
162  }
163 
164  d_ownedFactories.push_back(factory);
165 }
166 
167 //----------------------------------------------------------------------------//
168 template <typename T>
170 {
171  WindowRendererManager::addFactory<TplWindowRendererFactory<T> >();
172 }
173 
174 //----------------------------------------------------------------------------//
175 
176 
177 } // End of CEGUI namespace
178 
179 #if defined(_MSC_VER)
180 # pragma warning(pop)
181 #endif
182 
183 #endif // _CEGUIWindowRendererManager_h_