Refactor demangle.hpp to look a bit nicer

This commit is contained in:
Rapptz 2014-04-25 20:19:31 -04:00
parent 23ed27df89
commit 44eab5a164

View File

@ -24,42 +24,29 @@
#include <string>
#ifdef _MSC_VER
/*#include <windows.h>
#include <DbgHelp.h>
*/
#if defined(__GNUC__) || defined(__clang__)
#include <cxxabi.h>
#endif
namespace sol {
namespace detail {
#ifdef _MSC_VER
std::string demangle(const std::type_info& id) {
/*std::string realname(2048, '\0');
DWORD result = UnDecorateSymbolName(id.raw_name(), &realname[0],
static_cast<DWORD>(realname.size()), UNDNAME_NAME_ONLY | UNDNAME_32_BIT_DECODE);
if (result == 0)
return "";
realname.resize(result);
*/
const static std::string removals[ 2 ] = {
"struct ",
"class "
};
const static std::string removals[2] = { "struct ", "class " };
std::string realname = id.name();
for(std::size_t r = 0; r < 2; ++r) {
auto found = realname.find(removals[r]);
if (found == std::string::npos)
if(found == std::string::npos) {
continue;
}
realname.erase(found, removals[r].size());
}
return realname;
}
#elif __GNUC__ || __clang__
#include <cxxabi.h>
namespace sol {
namespace detail {
#elif defined(__GNUC__) || defined(__clang__)
std::string demangle(const std::type_info& id) {
int status;
char* unmangled = abi::__cxa_demangle(id.name(), 0, 0, &status);
@ -69,12 +56,8 @@ namespace detail {
}
#else
namespace sol {
namespace detail {
#error Implement demangling for this platform
#endif // VC++ || GCC || Others
#error Compiler not supported for demangling
#endif // compilers
} // detail
} // sol