18 #if defined(__APPLE__) 19 #define PLATFORM_APPLE 22 #if defined(unix) || defined(__unix) || defined(__APPLE__) 28 #define PLATFORM_WINDOWS 30 #error Unsupported platform 35 class SharedLibraryHandle
38 SharedLibraryHandle() : m_Handle(0) {}
39 SharedLibraryHandle(
const std::string &name) : m_Name(name), m_Handle(0) {}
40 virtual ~SharedLibraryHandle() {}
41 void Load() { Load(m_Name); }
42 void Load(
const std::string &name)
45 throw std::logic_error(std::string(
"Library already loaded: ") + name);
46 std::string libPath = GetAbsolutePath(name);
48 m_Handle = dlopen(libPath.c_str(), RTLD_LAZY | RTLD_GLOBAL);
51 const char *err = dlerror();
52 throw std::runtime_error(err ? std::string(err) : libPath);
55 m_Handle = LoadLibrary(libPath.c_str());
61 DWORD dw = GetLastError();
63 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
66 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
73 lpDisplayBuf = (LPVOID)LocalAlloc(
74 LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)libPath.c_str()) + 50) *
sizeof(TCHAR));
75 StringCchPrintf((LPTSTR)lpDisplayBuf,
76 LocalSize(lpDisplayBuf) /
sizeof(TCHAR),
77 TEXT(
"Loading %s failed with error %d: %s"),
82 std::string errMsg((LPCTSTR)lpDisplayBuf);
85 LocalFree(lpDisplayBuf);
87 throw std::runtime_error(errMsg);
101 FreeLibrary((HMODULE)m_Handle);
107 std::string GetAbsolutePath(
const std::string &name) {
return GetLibraryPath() +
"/" + Prefix() + name + Suffix(); }
108 std::string GetAbsolutePath() {
return GetLibraryPath() +
"/" + Prefix() + m_Name + Suffix(); }
110 static std::string Suffix()
112 #ifdef PLATFORM_WINDOWS 114 #elif defined(PLATFORM_APPLE) 121 static std::string Prefix()
123 #if defined(PLATFORM_UNIX) 131 SharedLibraryHandle(
const SharedLibraryHandle &);
132 SharedLibraryHandle &operator=(
const SharedLibraryHandle &);
#define MITK_RUNTIME_OUTPUT_DIR
DataCollection - Class to facilitate loading/accessing structured data.