1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 18:19:55 +00:00
openmw-tes3mp/apps/openmw-mp/Script/SystemInterface.hpp
2016-07-07 23:50:48 +08:00

44 lines
935 B
C++

//
// Created by koncord on 19.03.16.
//
#ifndef PLUGINSYSTEM3_SYSTEMINTERFACE_HPP
#define PLUGINSYSTEM3_SYSTEMINTERFACE_HPP
#ifdef __WIN32__
#include <winsock2.h>
#else
#include <dlfcn.h>
#endif
template<typename R = void*>
struct SystemInterface
{
#ifdef __WIN32__
typedef HMODULE lib_t;
#else
typedef void* lib_t;
#endif
union
{
R result;
#ifdef __WIN32__
decltype(GetProcAddress(lib_t(), nullptr)) data;
#else
decltype(dlsym(lib_t(), nullptr)) data;
#endif
};
static_assert(sizeof(result) == sizeof(data), "R should have the same size");
SystemInterface() : data(nullptr) {}
explicit operator bool() { return data; }
#ifdef __WIN32__
SystemInterface(lib_t handle, const char* name) : data(GetProcAddress(handle, name)) {}
#else
SystemInterface(lib_t handle, const char* name) : data(dlsym(handle, name)) {}
#endif
};
#endif //PLUGINSYSTEM3_SYSTEMINTERFACE_HPP