Crazy Eddie's GUI System 0.8.7
WindowRendererManager.h
1/***********************************************************************
2 created: Jan 11 2006
3 author: Tomas Lindquist Olsen
4
5 purpose: Defines interface for the WindowRendererManager class
6*************************************************************************/
7/***************************************************************************
8 * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29#ifndef _CEGUIWindowRendererManager_h_
30#define _CEGUIWindowRendererManager_h_
31
32#include "CEGUI/Singleton.h"
33#include "CEGUI/WindowRenderer.h"
34#include "CEGUI/Logger.h"
35#include "CEGUI/Exceptions.h"
36#include "CEGUI/TplWindowRendererFactory.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
46namespace CEGUI
47{
48class CEGUIEXPORT WindowRendererManager :
49 public Singleton<WindowRendererManager>,
50 public AllocatedObject<WindowRendererManager>
51{
52public:
53 /*************************************************************************
54 Contructor / Destructor
55 *************************************************************************/
58
59 /*************************************************************************
60 Singleton
61 *************************************************************************/
62 static WindowRendererManager& getSingleton();
63 static WindowRendererManager* getSingletonPtr();
64
65 /*************************************************************************
66 Accessors
67 *************************************************************************/
68 bool isFactoryPresent(const String& name) const;
69 WindowRendererFactory* getFactory(const String& name) const;
70
71 /*************************************************************************
72 Manipulators
73 *************************************************************************/
87 template <typename T>
88 static void addFactory();
89
104 template <typename T>
105 static void addWindowRendererType();
106
107 void addFactory(WindowRendererFactory* wr);
108 void removeFactory(const String& name);
109
110 /*************************************************************************
111 Factory usage
112 *************************************************************************/
113 WindowRenderer* createWindowRenderer(const String& name);
114 void destroyWindowRenderer(WindowRenderer* wr);
115
116private:
117 /*************************************************************************
118 Private implementation
119 *************************************************************************/
120
121 /*************************************************************************
122 Implementation data
123 *************************************************************************/
124 typedef std::map<String, WindowRendererFactory*, StringFastLessCompare> WR_Registry;
125 WR_Registry d_wrReg;
126
128 typedef std::vector<WindowRendererFactory*
129 CEGUI_VECTOR_ALLOC(WindowRendererFactory*)> OwnedFactoryList;
131 static OwnedFactoryList d_ownedFactories;
132};
133
134//----------------------------------------------------------------------------//
135template <typename T>
137{
138 // create the factory object
139 WindowRendererFactory* factory = CEGUI_NEW_AO T;
140
141 // only do the actual add now if our singleton has already been created
142 if (WindowRendererManager::getSingletonPtr())
143 {
144 Logger::getSingleton().logEvent("Created WindowRendererFactory for '" +
145 factory->getName() +
146 "' WindowRenderers.");
147 // add the factory we just created
148 CEGUI_TRY
149 {
150 WindowRendererManager::getSingleton().addFactory(factory);
151 }
152 CEGUI_CATCH (Exception&)
153 {
154 Logger::getSingleton().logEvent("Deleted WindowRendererFactory for "
155 "'" + factory->getName() +
156 "' WindowRenderers.");
157 // delete the factory object
158 CEGUI_DELETE_AO factory;
159 CEGUI_RETHROW;
160 }
161 }
162
163 d_ownedFactories.push_back(factory);
164}
165
166//----------------------------------------------------------------------------//
167template <typename T>
169{
170 WindowRendererManager::addFactory<TplWindowRendererFactory<T> >();
171}
172
173//----------------------------------------------------------------------------//
174
175
176} // End of CEGUI namespace
177
178#if defined(_MSC_VER)
179# pragma warning(pop)
180#endif
181
182#endif // _CEGUIWindowRendererManager_h_
Definition: MemoryAllocatedObject.h:110
Root exception class used within the GUI system.
Definition: Exceptions.h:49
Definition: Singleton.h:56
String class used within the GUI system.
Definition: String.h:64
Base-class for WindowRendererFactory.
Definition: WindowRenderer.h:238
const String & getName() const
Returns the type name of this window renderer factory.
Definition: WindowRenderer.h:259
Definition: WindowRendererManager.h:51
static void addFactory()
Creates a WindowRendererFactory of the type T and adds it to the system for use.
Definition: WindowRendererManager.h:136
static void addWindowRendererType()
Internally creates a factory suitable for creating WindowRenderer objects of the given type and adds ...
Definition: WindowRendererManager.h:168
Base-class for the assignable WindowRenderer object.
Definition: WindowRenderer.h:52
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1