00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00048 namespace CEGUI
00049 {
00050
00051
00052
00053 const char FactoryModule::RegisterFactoryFunctionName[] = "registerFactory";
00054
00055
00056
00057
00058
00059
00060 FactoryModule::FactoryModule(const String& filename) :
00061 d_moduleName(filename)
00062 {
00063 #if defined(__linux__)
00064
00065 if (d_moduleName.substr(d_moduleName.length() - 3, 3) != (utf8*)".so")
00066 {
00067 d_moduleName += (utf8*)".so";
00068 }
00069
00070
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
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
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
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
00111
00112 FactoryModule::~FactoryModule(void)
00113 {
00114 DYNLIB_UNLOAD(d_handle);
00115 }
00116
00117
00118
00119
00120
00121 void FactoryModule::registerFactory(const String& type) const
00122 {
00123 d_regFunc(type);
00124 }
00125
00126 }