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

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 
00055 
00056 /*************************************************************************
00057         Construct the FactoryModule object by loading the dynamic loadable
00058         module specified.
00059 *************************************************************************/
00060 FactoryModule::FactoryModule(const String& filename) :
00061         d_moduleName(filename)
00062 {
00063 #if defined(__linux__)
00064         // dlopen() does not add .so to the filename, like windows does for .dll
00065         if (d_moduleName.substr(d_moduleName.length() - 3, 3) != (utf8*)".so")
00066         {
00067                 d_moduleName += (utf8*)".so";
00068         }
00069 
00070         // see if we need to add the leading 'lib'
00071         if (d_moduleName.substr(0, 3) != (utf8*)"lib")
00072         {
00073                 d_moduleName.insert(0, (utf8*)"lib");
00074         }
00075 #endif
00076 
00078 #if defined(__WIN32__) || defined(_WIN32)
00079 #       if defined (_DEBUG) && defined (CEGUI_LOAD_MODULE_APPEND_SUFFIX_FOR_DEBUG)
00080         // if name has .dll extension, assume it's complete and do not touch it.
00081         if (d_moduleName.substr(d_moduleName.length() - 4, 4) != (utf8*)".dll")
00082         {
00083                 d_moduleName += (utf8*)CEGUI_LOAD_MODULE_DEBUG_SUFFIX;
00084         }
00085 #       endif
00086 #endif
00087 
00088         d_handle = DYNLIB_LOAD(d_moduleName.c_str());
00089 
00090         // check for library load failure
00091         if (d_handle == NULL)
00092         {
00093                 throw   GenericException((utf8*)"FactoryModule::FactoryModule - Failed to load module '" + d_moduleName + "'.");
00094         }
00095 
00096         d_regFunc = (FactoryRegisterFunction)DYNLIB_GETSYM(d_handle, RegisterFactoryFunctionName);
00097 
00098         // check for failure to find required function export
00099         if (d_regFunc == NULL)
00100         {
00101                 DYNLIB_UNLOAD(d_handle);
00102 
00103                 throw   GenericException((utf8*)"FactoryModule::FactoryModule - Required function export 'registerFactory' was not found in module '" + d_moduleName + "'.");
00104         }
00105 
00106 }
00107 
00108 
00109 /*************************************************************************
00110         Destroys the FactoryModule object and unloads any loadable module.
00111 *************************************************************************/
00112 FactoryModule::~FactoryModule(void)
00113 {
00114         DYNLIB_UNLOAD(d_handle);
00115 }
00116 
00117 
00118 /*************************************************************************
00119         Register a WindowFactory for 'type' Windows.
00120 *************************************************************************/
00121 void FactoryModule::registerFactory(const String& type) const
00122 {
00123         d_regFunc(type);
00124 }
00125 
00126 } // End of  CEGUI namespace section

Generated on Wed Feb 16 12:41:06 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1