Crazy Eddie's GUI System  0.8.4
WindowRendererManager.h
00001 /***********************************************************************
00002     created:    Jan 11 2006
00003     author:     Tomas Lindquist Olsen
00004 
00005     purpose:    Defines interface for the WindowRendererManager class
00006 *************************************************************************/
00007 /***************************************************************************
00008  *   Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
00009  *
00010  *   Permission is hereby granted, free of charge, to any person obtaining
00011  *   a copy of this software and associated documentation files (the
00012  *   "Software"), to deal in the Software without restriction, including
00013  *   without limitation the rights to use, copy, modify, merge, publish,
00014  *   distribute, sublicense, and/or sell copies of the Software, and to
00015  *   permit persons to whom the Software is furnished to do so, subject to
00016  *   the following conditions:
00017  *
00018  *   The above copyright notice and this permission notice shall be
00019  *   included in all copies or substantial portions of the Software.
00020  *
00021  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00022  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00023  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00024  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00025  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00026  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00027  *   OTHER DEALINGS IN THE SOFTWARE.
00028  ***************************************************************************/
00029 #ifndef _CEGUIWindowRendererManager_h_
00030 #define _CEGUIWindowRendererManager_h_
00031 
00032 #include "CEGUI/Singleton.h"
00033 #include "CEGUI/WindowRenderer.h"
00034 #include "CEGUI/Logger.h"
00035 #include "CEGUI/Exceptions.h"
00036 #include "CEGUI/TplWindowRendererFactory.h"
00037 #include <map>
00038 #include <vector>
00039 
00040 #if defined(_MSC_VER)
00041 #   pragma warning(push)
00042 #   pragma warning(disable : 4251)
00043 #endif
00044 
00045 // Start of CEGUI namespace section
00046 namespace CEGUI
00047 {
00048 class CEGUIEXPORT WindowRendererManager :
00049     public Singleton<WindowRendererManager>,
00050     public AllocatedObject<WindowRendererManager>
00051 {
00052 public:
00053     /*************************************************************************
00054         Contructor / Destructor
00055     *************************************************************************/
00056     WindowRendererManager();
00057     ~WindowRendererManager();
00058 
00059     /*************************************************************************
00060         Singleton
00061     *************************************************************************/
00062     static WindowRendererManager& getSingleton();
00063     static WindowRendererManager* getSingletonPtr();
00064 
00065     /*************************************************************************
00066         Accessors
00067     *************************************************************************/
00068     bool isFactoryPresent(const String& name) const;
00069     WindowRendererFactory* getFactory(const String& name) const;
00070 
00071     /*************************************************************************
00072         Manipulators
00073     *************************************************************************/
00087     template <typename T>
00088     static void addFactory();
00089 
00104     template <typename T>
00105     static void addWindowRendererType();
00106 
00107     void addFactory(WindowRendererFactory* wr);
00108     void removeFactory(const String& name);
00109 
00110     /*************************************************************************
00111         Factory usage
00112     *************************************************************************/
00113     WindowRenderer* createWindowRenderer(const String& name);
00114     void destroyWindowRenderer(WindowRenderer* wr);
00115 
00116 private:
00117     /*************************************************************************
00118         Private implementation
00119     *************************************************************************/
00120 
00121     /*************************************************************************
00122         Implementation data
00123     *************************************************************************/
00124     typedef std::map<String, WindowRendererFactory*, StringFastLessCompare> WR_Registry;
00125     WR_Registry d_wrReg;
00126 
00128     typedef std::vector<WindowRendererFactory*
00129         CEGUI_VECTOR_ALLOC(WindowRendererFactory*)> OwnedFactoryList;
00131     static OwnedFactoryList d_ownedFactories;
00132 };
00133 
00134 //----------------------------------------------------------------------------//
00135 template <typename T>
00136 void WindowRendererManager::addFactory()
00137 {
00138     // create the factory object
00139     WindowRendererFactory* factory = CEGUI_NEW_AO T;
00140 
00141     // only do the actual add now if our singleton has already been created
00142     if (WindowRendererManager::getSingletonPtr())
00143     {
00144         Logger::getSingleton().logEvent("Created WindowRendererFactory for '" +
00145                                         factory->getName() +
00146                                         "' WindowRenderers.");
00147         // add the factory we just created
00148         CEGUI_TRY
00149         {
00150             WindowRendererManager::getSingleton().addFactory(factory);
00151         }
00152         CEGUI_CATCH (Exception&)
00153         {
00154             Logger::getSingleton().logEvent("Deleted WindowRendererFactory for "
00155                                             "'" + factory->getName() +
00156                                             "' WindowRenderers.");
00157             // delete the factory object
00158             CEGUI_DELETE_AO factory;
00159             CEGUI_RETHROW;
00160         }
00161     }
00162 
00163     d_ownedFactories.push_back(factory);
00164 }
00165 
00166 //----------------------------------------------------------------------------//
00167 template <typename T>
00168 void WindowRendererManager::addWindowRendererType()
00169 {
00170     WindowRendererManager::addFactory<TplWindowRendererFactory<T> >();
00171 }
00172 
00173 //----------------------------------------------------------------------------//
00174 
00175 
00176 } // End of CEGUI namespace
00177 
00178 #if defined(_MSC_VER)
00179 #   pragma warning(pop)
00180 #endif
00181 
00182 #endif // _CEGUIWindowRendererManager_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends