From 5e837b50c4ae7e1062571ff655d30802dfed17f5 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sat, 27 Mar 2021 15:19:23 +0100 Subject: [PATCH] Add a fubction which converts a template typename to a string --- simgear/structure/intern.hxx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/simgear/structure/intern.hxx b/simgear/structure/intern.hxx index 5a1c0e47..3d3e1ef9 100644 --- a/simgear/structure/intern.hxx +++ b/simgear/structure/intern.hxx @@ -3,12 +3,33 @@ #include +#include +#if __linux__ +#include +#endif + namespace simgear { + +/* return the template name as a string */ +template +std::string getTypeName(void) +{ +#ifdef _WIN32 + std::string name = typeid(T).name(); +#else // __linux__ + int error = 0; + char *type = abi::__cxa_demangle(typeid(T).name(), 0, 0, &error); + std::string name = type; + free(type); +#endif + + return name; +} + /** * Return a pointer to a single string object for a given string. */ - const std::string* intern(const std::string& str); } #endif