CEGUIWindowRendererModule.h

00001 /***********************************************************************
00002     filename:   CEGUIWindowRendererModule.h
00003     created:    Fri Jan 13 2006
00004     author:     Paul D Turner <paul@cegui.org.uk>
00005                 Tomas Lindquist Olsen <tomas@famolsen.dk>
00006 *************************************************************************/
00007 /***************************************************************************
00008  *   Copyright (C) 2004 - 2006 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 _CEGUIWindowRendererModule_h_
00030 #define _CEGUIWindowRendererModule_h_
00031 
00032 #include "CEGUIExceptions.h"
00033 #include "CEGUIWindowRendererManager.h"
00034 #include "CEGUILogger.h"
00035 
00036 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
00037 #   ifdef CEGUIWRMODULE_EXPORTS
00038 #       define CEGUIWRMODULE_API __declspec(dllexport)
00039 #   else
00040 #       define CEGUIWRMODULE_API __declspec(dllimport)
00041 #   endif
00042 #else
00043 #   define CEGUIWRMODULE_API 
00044 #endif
00045 
00046 // declare module
00047 #define CEGUI_DECLARE_WR_MODULE( moduleName )\
00048 \
00049 class CEGUI::WindowRendererFactory;\
00050 \
00051 extern "C" CEGUIWRMODULE_API void registerFactoryFunction(const CEGUI::String& type_name);\
00052 extern "C" CEGUIWRMODULE_API CEGUI::uint registerAllFactoriesFunction(void);\
00053 void doSafeFactoryRegistration(CEGUI::WindowRendererFactory* factory);
00054 
00055 // define factory
00056 #define CEGUI_DEFINE_WR_FACTORY( className )\
00057 namespace CEGUI {\
00058 class className ## WRFactory : public WindowRendererFactory\
00059 {\
00060 public:\
00061     className ## WRFactory(void) : WindowRendererFactory(className::TypeName) { }\
00062     WindowRenderer* create(void)\
00063     { return new className(className::TypeName); }\
00064     void destroy(WindowRenderer* wr)\
00065     { delete wr; }\
00066 };\
00067 }\
00068 static CEGUI::className ## WRFactory  s_ ## className ## WRFactory;
00069 
00070 // start factory map
00071 #define CEGUI_START_WR_FACTORY_MAP( module )\
00072 struct module ## WRMapEntry\
00073 {\
00074     const CEGUI::utf8* d_name;\
00075     CEGUI::WindowRendererFactory* d_factory;\
00076 };\
00077 \
00078 module ## WRMapEntry module ## WRFactoriesMap[] =\
00079 {\
00080 
00081 // end factory map
00082 #define CEGUI_END_WR_FACTORY_MAP {0,0}};
00083 
00084 // map entry
00085 #define CEGUI_WR_FACTORY_MAP_ENTRY( class )\
00086 {CEGUI::class::TypeName, &s_ ## class ## WRFactory},
00087 
00088 // define module
00089 #define CEGUI_DEFINE_WR_MODULE( module )\
00090 void registerFactoryFunction(const CEGUI::String& type_name)\
00091 {\
00092     module ## WRMapEntry* entry = module ## WRFactoriesMap;\
00093     while (entry->d_name)\
00094     {\
00095         if (entry->d_name == type_name)\
00096         {\
00097             doSafeFactoryRegistration(entry->d_factory);\
00098             return;\
00099         }\
00100         ++entry;\
00101     }\
00102 \
00103     throw CEGUI::UnknownObjectException("::registerFactory - The window renderer factory for type '" + type_name + "' is not known in this module.");\
00104 }\
00105 \
00106 extern "C" CEGUI::uint registerAllFactoriesFunction(void)\
00107 {\
00108     CEGUI::uint count = 0;\
00109     module ## WRMapEntry* entry = module ## WRFactoriesMap;\
00110     while (entry->d_name)\
00111     {\
00112         doSafeFactoryRegistration(entry->d_factory);\
00113         ++entry;\
00114         ++count;\
00115     }\
00116     return count;\
00117 }\
00118 \
00119 void doSafeFactoryRegistration(CEGUI::WindowRendererFactory* factory)\
00120 {\
00121     assert(factory != 0);\
00122 \
00123     CEGUI::WindowRendererManager& wfm = CEGUI::WindowRendererManager::getSingleton();\
00124     if (wfm.isFactoryPresent(factory->getName()))\
00125     {\
00126         CEGUI::Logger::getSingleton().logEvent(\
00127             "WindowRenderer factory '" + factory->getName() + "' appears to be already registered, skipping.",\
00128             CEGUI::Informative);\
00129     }\
00130     else\
00131     {\
00132         wfm.addFactory(factory);\
00133     }\
00134 }
00135 
00136 #endif  // end of guard _CEGUIWindowRendererModule_h_

Generated on Sat Jun 28 14:35:44 2008 for Crazy Eddies GUI System by  doxygen 1.5.4