Badminton-Scoreboard/Libraries/libil2cpp/include/utils/BaselibHandleUtils.h

35 lines
1.2 KiB
C
Raw Normal View History

2023-10-08 02:24:48 +00:00
#pragma once
#include <string.h>
namespace il2cpp
{
namespace utils
{
class BaselibHandleUtils
{
public:
template<typename BaselibHandleType>
static void* HandleToVoidPtr(BaselibHandleType baselibHandle)
{
// following asserts check that the handle fits into void* in its entirety
static_assert(sizeof(BaselibHandleType) <= sizeof(void*), "baselib handle does not fit void*");
static_assert(sizeof(BaselibHandleType::handle) <= sizeof(void*), "baselib handle does not fit void*");
void* result = nullptr;
memcpy(&result, &baselibHandle.handle, sizeof(result));
return result;
}
template<typename BaselibHandleType>
static BaselibHandleType VoidPtrToHandle(void* ptr)
{
static_assert(sizeof(BaselibHandleType) <= sizeof(void*), "baselib handle does not fit void*");
static_assert(sizeof(BaselibHandleType::handle) <= sizeof(void*), "baselib handle does not fit void*");
decltype(BaselibHandleType::handle)result = {};
memcpy(&result, &ptr, sizeof(ptr));
return BaselibHandleType { result };
}
};
}
}