library.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00035 #ifndef __library__header__
00036 #define __library__header__
00037
00038 #include "gpucalc/object.h"
00039
00040 #if PLATFORM == PLATFORM_LINUX
00041
00042 #define LIBRARY_HANDLE void *
00043 #define LIBRARY_LOAD(a) dlopen(a, RTLD_LAZY | RTLD_GLOBAL)
00044 #define LIBRARY_GETSYM(a, b) dlsym(a, b)
00045 #define LIBRARY_UNLOAD(a) dlclose(a)
00046
00047 #elif PLATFORM == PLATFORM_WIN32
00048
00049 #define LIBRARY_HANDLE hInstance
00050 #define LIBRARY_LOAD( a ) LoadLibraryA( a )
00051 #define LIBRARY_GETSYM( a, b ) GetProcAddress( a, b )
00052 #define LIBRARY_UNLOAD( a ) !FreeLibrary( a )
00053
00054 struct HINSTANCE__;
00055 typedef struct HINSTANCE__* hInstance;
00056
00057 #elif PLATFORM == PLATFORM_APPLE
00058
00059 #define LIBRARY_HANDLE CFBundleRef
00060 #define LIBRARY_LOAD( a ) mac_loadExeBundle( a )
00061 #define LIBRARY_GETSYM( a, b ) mac_getBundleSym( a, b )
00062 #define LIBRARY_UNLOAD( a ) mac_unloadExeBundle( a )
00063
00064 #endif
00065
00066 namespace gpucalc
00067 {
00068
00069
00070 const char _LibraryClassName [] = "Library";
00071
00072
00078 class _GpuCalcExport Library: public Object
00079 {
00080
00081
00082 OBJ_DISABLE_COPY(Library)
00083
00084
00085 public:
00091 Library(const std::string & LibraryName):
00092 Object(_LibraryClassName, LibraryName), mhInst(0), mIsLoaded(false)
00093 {
00094 }
00095
00096
00097 ~Library()
00098 {
00099 if (mIsLoaded)
00100 {
00101 unload();
00102 }
00103 }
00104
00105
00111 void load();
00112
00113
00119 void unload();
00120
00121
00122 bool isLoaded() const
00123 {
00124 return mIsLoaded;
00125 }
00126
00127
00133 LIBRARY_HANDLE getSymbol(const std::string & SymbolName) const;
00134
00135
00136 private:
00137 LIBRARY_HANDLE mhInst;
00138
00139
00140 std::string libraryError() const;
00141
00142
00143 bool mIsLoaded;
00144 };
00145 }
00146
00147 #endif