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 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
11 |
|
---|
12 | This library is free software; you can redistribute it and/or
|
---|
13 | modify it under the terms of the GNU Lesser General Public
|
---|
14 | License as published by the Free Software Foundation; either
|
---|
15 | version 2.1 of the License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This library is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | Lesser General Public License for more details.
|
---|
21 |
|
---|
22 | You should have received a copy of the GNU Lesser General Public
|
---|
23 | License along with this library; if not, write to the Free Software
|
---|
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | *************************************************************************/
|
---|
26 | #ifndef _CEGUIWindowFactoryManager_h_
|
---|
27 | #define _CEGUIWindowFactoryManager_h_
|
---|
28 |
|
---|
29 | #include "CEGUIBase.h"
|
---|
30 | #include "CEGUIString.h"
|
---|
31 | #include "CEGUISingleton.h"
|
---|
32 | #include "CEGUILogger.h"
|
---|
33 | #include "CEGUIIteratorBase.h"
|
---|
34 | #include <map>
|
---|
35 | #include <vector>
|
---|
36 |
|
---|
37 | #if defined(_MSC_VER)
|
---|
38 | # pragma warning(push)
|
---|
39 | # pragma warning(disable : 4275)
|
---|
40 | # pragma warning(disable : 4251)
|
---|
41 | #endif
|
---|
42 |
|
---|
43 |
|
---|
44 | // Start of CEGUI namespace section
|
---|
45 | namespace CEGUI
|
---|
46 | {
|
---|
47 | /*!
|
---|
48 | \brief
|
---|
49 | Class that manages WindowFactory objects
|
---|
50 | */
|
---|
51 | class CEGUIEXPORT WindowFactoryManager : public Singleton<WindowFactoryManager>
|
---|
52 | {
|
---|
53 | public:
|
---|
54 | /*************************************************************************
|
---|
55 | Class used to track active alias targets
|
---|
56 | *************************************************************************/
|
---|
57 | class CEGUIEXPORT AliasTargetStack
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | /*!
|
---|
61 | \brief
|
---|
62 | Constructor for WindowAliasTargetStack objects
|
---|
63 | */
|
---|
64 | AliasTargetStack(void) {}
|
---|
65 |
|
---|
66 |
|
---|
67 | /*!
|
---|
68 | \brief
|
---|
69 | Destructor for WindowAliasTargetStack objects
|
---|
70 | */
|
---|
71 | ~AliasTargetStack(void) {}
|
---|
72 |
|
---|
73 |
|
---|
74 | /*!
|
---|
75 | \brief
|
---|
76 | Return a String holding the current target type for this stack
|
---|
77 |
|
---|
78 | \return
|
---|
79 | reference to a String object holding the currently active target type name for this stack.
|
---|
80 | */
|
---|
81 | const String& getActiveTarget(void) const;
|
---|
82 |
|
---|
83 | /*!
|
---|
84 | \brief
|
---|
85 | Return the number of stacked target types in the stack
|
---|
86 |
|
---|
87 | \return
|
---|
88 | number of target types stacked for this alias.
|
---|
89 | */
|
---|
90 | uint getStackedTargetCount(void) const;
|
---|
91 |
|
---|
92 |
|
---|
93 | private:
|
---|
94 | friend class WindowFactoryManager;
|
---|
95 | typedef std::vector<String> TargetTypeStack; //!< Type used to implement stack of target type names.
|
---|
96 |
|
---|
97 | TargetTypeStack d_targetStack; //!< Container holding the target types.
|
---|
98 | };
|
---|
99 |
|
---|
100 |
|
---|
101 | /*************************************************************************
|
---|
102 | Construction and Destruction
|
---|
103 | *************************************************************************/
|
---|
104 | /*!
|
---|
105 | \brief
|
---|
106 | Constructs a new WindowFactoryManager object.
|
---|
107 | */
|
---|
108 | WindowFactoryManager(void)
|
---|
109 | {
|
---|
110 | Logger::getSingleton().logEvent((utf8*)"CEGUI::WindowFactoryManager singleton created");
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | /*!
|
---|
115 | \brief
|
---|
116 | Destructor for WindowFactoryManager objects
|
---|
117 | */
|
---|
118 | ~WindowFactoryManager(void)
|
---|
119 | {
|
---|
120 | Logger::getSingleton().logEvent((utf8*)"CEGUI::WindowFactoryManager singleton destroyed");
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | /*************************************************************************
|
---|
125 | Public Interface
|
---|
126 | *************************************************************************/
|
---|
127 | /*!
|
---|
128 | \brief
|
---|
129 | Return singleton WindowFactoryManager object
|
---|
130 |
|
---|
131 | \return
|
---|
132 | Singleton WindowFactoryManager object
|
---|
133 | */
|
---|
134 | static WindowFactoryManager& getSingleton(void);
|
---|
135 |
|
---|
136 |
|
---|
137 | /*!
|
---|
138 | \brief
|
---|
139 | Return pointer to singleton WindowFactoryManager object
|
---|
140 |
|
---|
141 | \return
|
---|
142 | Pointer to singleton WindowFactoryManager object
|
---|
143 | */
|
---|
144 | static WindowFactoryManager* getSingletonPtr(void);
|
---|
145 |
|
---|
146 |
|
---|
147 | /*!
|
---|
148 | \brief
|
---|
149 | Adds a new WindowFactory to the list of registered factories.
|
---|
150 |
|
---|
151 | \param factory
|
---|
152 | Pointer to the WindowFactory to be added to the WindowManager.
|
---|
153 |
|
---|
154 | \return
|
---|
155 | Nothing
|
---|
156 |
|
---|
157 | \exception NullObjectException \a factory was null.
|
---|
158 | \exception AlreadyExistsException \a factory provided a Window type name which is in use by another registered WindowFactory.
|
---|
159 | */
|
---|
160 | void addFactory(WindowFactory* factory);
|
---|
161 |
|
---|
162 |
|
---|
163 | /*!
|
---|
164 | \brief
|
---|
165 | Removes a WindowFactory from the list of registered factories.
|
---|
166 |
|
---|
167 | \note
|
---|
168 | The WindowFactory object is not destroyed (since it was created externally), instead it is just removed from the list.
|
---|
169 |
|
---|
170 | \param name
|
---|
171 | String which holds the name (technically, Window type name) of the WindowFactory to be removed. If \a name is not
|
---|
172 | in the list, no error occurs (nothing happens).
|
---|
173 |
|
---|
174 | \return
|
---|
175 | Nothing
|
---|
176 | */
|
---|
177 | void removeFactory(const String& name);
|
---|
178 |
|
---|
179 |
|
---|
180 | /*!
|
---|
181 | \brief
|
---|
182 | Removes a WindowFactory from the list of registered factories.
|
---|
183 |
|
---|
184 | \note
|
---|
185 | The WindowFactory object is not destroyed (since it was created externally), instead it is just removed from the list.
|
---|
186 |
|
---|
187 | \param factory
|
---|
188 | Pointer to the factory object to be removed. If \a factory is null, or if no such WindowFactory is in the list, no
|
---|
189 | error occurs (nothing happens).
|
---|
190 |
|
---|
191 | \return
|
---|
192 | Nothing
|
---|
193 | */
|
---|
194 | void removeFactory(WindowFactory* factory);
|
---|
195 |
|
---|
196 |
|
---|
197 | /*!
|
---|
198 | \brief
|
---|
199 | Remove all WindowFactory objects from the list.
|
---|
200 |
|
---|
201 | \return
|
---|
202 | Nothing
|
---|
203 | */
|
---|
204 | void removeAllFactories(void) {d_factoryRegistry.clear();}
|
---|
205 |
|
---|
206 |
|
---|
207 | /*!
|
---|
208 | \brief
|
---|
209 | Return a pointer to the specified WindowFactory object.
|
---|
210 |
|
---|
211 | \param type
|
---|
212 | String holding the Window object type to return the WindowFactory for.
|
---|
213 |
|
---|
214 | \return
|
---|
215 | Pointer to the WindowFactory object that creates Windows of the type \a type.
|
---|
216 |
|
---|
217 | \exception UnknownObjectException No WindowFactory object for Window objects of type \a type was found.
|
---|
218 | */
|
---|
219 | WindowFactory* getFactory(const String& type) const;
|
---|
220 |
|
---|
221 |
|
---|
222 | /*!
|
---|
223 | \brief
|
---|
224 | Checks the list of registered WindowFactory objects for one which creates Window objects of the specified type.
|
---|
225 |
|
---|
226 | \param name
|
---|
227 | String containing the name (technically, Window type name) of the WindowFactory to check for.
|
---|
228 |
|
---|
229 | \return
|
---|
230 | true if a WindowFactory that creates Window objects of type \a name is registered. Else, false.
|
---|
231 | */
|
---|
232 | bool isFactoryPresent(const String& name) const;
|
---|
233 |
|
---|
234 |
|
---|
235 | /*!
|
---|
236 | \brief
|
---|
237 | Adds an alias for a current window type.
|
---|
238 |
|
---|
239 | This method allows you to create an alias for a specified window type. This means that you can then use
|
---|
240 | either name as the type parameter when creating a window.
|
---|
241 |
|
---|
242 | \note
|
---|
243 | You need to be careful using this system. Creating an alias using a name that already exists will replace the previous
|
---|
244 | mapping for that alias. Each alias name maintains a stack, which means that it is possible to remove an alias and have the
|
---|
245 | previous alias restored. The windows created via an alias use the real type, so removing an alias after window creation is always
|
---|
246 | safe (i.e. it is not the same as removing a real factory, which would cause an exception when trying to destroy a window with a missing
|
---|
247 | factory).
|
---|
248 |
|
---|
249 | \param aliasName
|
---|
250 | String object holding the alias name. That is the name that \a targetType will also be known as from no on.
|
---|
251 |
|
---|
252 | \param targetType
|
---|
253 | String object holding the type window type name that is to be aliased. This type must already exist.
|
---|
254 |
|
---|
255 | \return
|
---|
256 | Nothing.
|
---|
257 |
|
---|
258 | \exception UnknownObjectException thrown if \a targetType is not known within the system.
|
---|
259 | */
|
---|
260 | void addWindowTypeAlias(const String& aliasName, const String& targetType);
|
---|
261 |
|
---|
262 |
|
---|
263 | /*!
|
---|
264 | \brief
|
---|
265 | Remove the specified alias mapping. If the alias mapping does not exist, nothing happens.
|
---|
266 |
|
---|
267 | \note
|
---|
268 | You are required to supply both the alias and target names because there may exist more than one entry for a given
|
---|
269 | alias - therefore you are required to be explicit about which alias is to be removed.
|
---|
270 |
|
---|
271 | \param aliasName
|
---|
272 | String object holding the alias name.
|
---|
273 |
|
---|
274 | \param targetType
|
---|
275 | String object holding the type window type name that was aliased.
|
---|
276 |
|
---|
277 | \return
|
---|
278 | Nothing.
|
---|
279 | */
|
---|
280 | void removeWindowTypeAlias(const String& aliasName, const String& targetType);
|
---|
281 |
|
---|
282 |
|
---|
283 | private:
|
---|
284 | /*************************************************************************
|
---|
285 | Implementation Data
|
---|
286 | *************************************************************************/
|
---|
287 | typedef std::map<String, WindowFactory*> WindowFactoryRegistry; //!< Type used to implement registry of WindowFactory objects
|
---|
288 | typedef std::map<String, AliasTargetStack> TypeAliasRegistry; //!< Type used to implement registry of window type aliases.
|
---|
289 |
|
---|
290 | WindowFactoryRegistry d_factoryRegistry; //!< The container that forms the WindowFactory registry
|
---|
291 | TypeAliasRegistry d_aliasRegistry; //!< The container that forms the window type alias registry.
|
---|
292 |
|
---|
293 | public:
|
---|
294 | /*************************************************************************
|
---|
295 | Iterator stuff
|
---|
296 | *************************************************************************/
|
---|
297 | typedef ConstBaseIterator<WindowFactoryRegistry> WindowFactoryIterator;
|
---|
298 | typedef ConstBaseIterator<TypeAliasRegistry> TypeAliasIterator;
|
---|
299 |
|
---|
300 | /*!
|
---|
301 | \brief
|
---|
302 | Return a WindowFactoryManager::WindowFactoryIterator object to iterate over the available WindowFactory types.
|
---|
303 | */
|
---|
304 | WindowFactoryIterator getIterator(void) const;
|
---|
305 |
|
---|
306 |
|
---|
307 | /*!
|
---|
308 | \brief
|
---|
309 | Return a WindowFactoryManager::TypeAliasIterator object to iterate over the defined aliases for window types.
|
---|
310 | */
|
---|
311 | TypeAliasIterator getAliasIterator(void) const;
|
---|
312 | };
|
---|
313 |
|
---|
314 | } // End of CEGUI namespace section
|
---|
315 |
|
---|
316 |
|
---|
317 | #if defined(_MSC_VER)
|
---|
318 | # pragma warning(pop)
|
---|
319 | #endif
|
---|
320 |
|
---|
321 | #endif // end of guard _CEGUIWindowFactoryManager_h_
|
---|