Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIFactoryModule.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIFactoryModule.cpp
00003         created:        12/4/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implements FactoryModule for Win32 systems
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "CEGUIBase.h"
00027 #include "CEGUIString.h"
00028 #include "CEGUIExceptions.h"
00029 #include "CEGUIFactoryModule.h"
00030 
00031 #if defined(__WIN32__) || defined(_WIN32)
00032 #       if defined(_MSC_VER)
00033 #               pragma warning(disable : 4552)  // warning: operator has no effect; expected operator with side-effect
00034 #       endif
00035 #   define WIN32_LEAN_AND_MEAN
00036 #   include <windows.h>
00037 #endif
00038 
00039 #if defined(__APPLE_CC__)
00040 #   include "macPlugins.h"
00041 #endif
00042 
00043 #if defined(__linux__)
00044 #   include "dlfcn.h"
00045 #endif
00046 
00047 // Start of CEGUI namespace section
00048 namespace CEGUI
00049 {
00050 /*************************************************************************
00051         Constants
00052 *************************************************************************/
00053 const char      FactoryModule::RegisterFactoryFunctionName[] = "registerFactory";
00054 const char  FactoryModule::RegisterAllFunctionName[]     = "registerAllFactories";
00055 
00056 
00057 /*************************************************************************
00058         Construct the FactoryModule object by loading the dynamic loadable
00059         module specified.
00060 *************************************************************************/
00061 FactoryModule::FactoryModule(const String& filename) :
00062         d_moduleName(filename)
00063 {
00064 #if defined(__linux__)
00065         // dlopen() does not add .so to the filename, like windows does for .dll
00066         if (d_moduleName.substr(d_moduleName.length() - 3, 3) != (utf8*)".so")
00067         {
00068                 d_moduleName += (utf8*)".so";
00069         }
00070 
00071         // see if we need to add the leading 'lib'
00072         if (d_moduleName.substr(0, 3) != (utf8*)"lib")
00073         {
00074                 d_moduleName.insert(0, (utf8*)"lib");
00075         }
00076 #endif
00077 
00079 #if defined(__WIN32__) || defined(_WIN32)
00080 #       if defined (_DEBUG) && defined (CEGUI_LOAD_MODULE_APPEND_SUFFIX_FOR_DEBUG)
00081         // if name has .dll extension, assume it's complete and do not touch it.
00082         if (d_moduleName.substr(d_moduleName.length() - 4, 4) != (utf8*)".dll")
00083         {
00084                 d_moduleName += (utf8*)CEGUI_LOAD_MODULE_DEBUG_SUFFIX;
00085         }
00086 #       endif
00087 #endif
00088 
00089         d_handle = DYNLIB_LOAD(d_moduleName.c_str());
00090 
00091         // check for library load failure
00092         if (d_handle == NULL)
00093         {
00094                 throw   GenericException((utf8*)"FactoryModule::FactoryModule - Failed to load module '" + d_moduleName + "'.");
00095         }
00096 
00097     // functions are now optional, and only throw upon the first attempt to use a missing function.
00098     d_regFunc = (FactoryRegisterFunction)DYNLIB_GETSYM(d_handle, RegisterFactoryFunctionName);
00099     d_regAllFunc = (RegisterAllFunction)DYNLIB_GETSYM(d_handle, RegisterAllFunctionName);
00100 }
00101 
00102 
00103 /*************************************************************************
00104         Destroys the FactoryModule object and unloads any loadable module.
00105 *************************************************************************/
00106 FactoryModule::~FactoryModule(void)
00107 {
00108         DYNLIB_UNLOAD(d_handle);
00109 }
00110 
00111 
00112 /*************************************************************************
00113         Register a WindowFactory for 'type' Windows.
00114 *************************************************************************/
00115 void FactoryModule::registerFactory(const String& type) const
00116 {
00117     // are we attempting to use a missing function export
00118     if (!d_regFunc)
00119     {
00120         throw InvalidRequestException("FactoryModule::registerFactory - Required function export 'void registerFactory(const String& type)' was not found in module '" + d_moduleName + "'.");
00121     }
00122 
00123         d_regFunc(type);
00124 }
00125 
00126 uint FactoryModule::registerAllFactories() const
00127 {
00128     // are we attempting to use a missing function export
00129     if (!d_regAllFunc)
00130     {
00131         throw InvalidRequestException("FactoryModule::registerAllFactories - Required function export 'uint registerAllFactories(void)' was not found in module '" + d_moduleName + "'.");
00132     }
00133 
00134     return d_regAllFunc();
00135 }
00136 
00137 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:31 2005 for Crazy Eddies GUI System by  doxygen 1.4.3