22 #if defined(__APPLE__)
23 #define PLATFORM_APPLE
26 #if defined(unix) || defined(__unix) || defined(__APPLE__)
32 #define PLATFORM_WINDOWS
34 #error Unsupported platform
39 class SharedLibraryHandle
42 SharedLibraryHandle() : m_Handle(0) {}
43 SharedLibraryHandle(
const std::string &name) : m_Name(name), m_Handle(0) {}
44 virtual ~SharedLibraryHandle() {}
45 void Load() { Load(m_Name); }
46 void Load(
const std::string &name)
49 throw std::logic_error(std::string(
"Library already loaded: ") + name);
50 std::string libPath = GetAbsolutePath(name);
52 m_Handle = dlopen(libPath.c_str(), RTLD_LAZY | RTLD_GLOBAL);
55 const char *err = dlerror();
56 throw std::runtime_error(err ? std::string(err) : libPath);
59 m_Handle = LoadLibrary(libPath.c_str());
65 DWORD dw = GetLastError();
67 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
70 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
77 lpDisplayBuf = (LPVOID)LocalAlloc(
78 LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)libPath.c_str()) + 50) *
sizeof(TCHAR));
79 StringCchPrintf((LPTSTR)lpDisplayBuf,
80 LocalSize(lpDisplayBuf) /
sizeof(TCHAR),
81 TEXT(
"Loading %s failed with error %d: %s"),
86 std::string errMsg((LPCTSTR)lpDisplayBuf);
89 LocalFree(lpDisplayBuf);
91 throw std::runtime_error(errMsg);
105 FreeLibrary((HMODULE)m_Handle);
111 std::string GetAbsolutePath(
const std::string &name) {
return GetLibraryPath() +
"/" + Prefix() + name + Suffix(); }
112 std::string GetAbsolutePath() {
return GetLibraryPath() +
"/" + Prefix() + m_Name + Suffix(); }
114 static std::string Suffix()
116 #ifdef PLATFORM_WINDOWS
118 #elif defined(PLATFORM_APPLE)
125 static std::string Prefix()
127 #if defined(PLATFORM_UNIX)
135 SharedLibraryHandle(
const SharedLibraryHandle &);
136 SharedLibraryHandle &operator=(
const SharedLibraryHandle &);
#define MITK_RUNTIME_OUTPUT_DIR
DataCollection - Class to facilitate loading/accessing structured data.