dlxjj/imradv3
0263
1#pragma once2#include <string>3#include <imgui.h>4#include <sstream>5#ifndef WIN326#include <cxxabi.h>7#endif8 9//negative values allowed10struct dimension_t {};11 12//positive or zero dimension (so that neg values represent empty value)13struct pzdimension_t {};14 15struct pzdimension2_t {};16 17struct font_name_t {};18 19struct shortcut_t {};20 21struct color_t {};22 23//------------------------------------------------------------------24 25template <class T>26struct typeid_func_name;27 28template <class T>29std::string typeid_name()30{31 if constexpr (std::is_const_v<T>)32 return "const " + typeid_name<std::remove_const_t<T>>();33 else if constexpr (std::is_pointer_v<T>)34 return typeid_name<std::remove_pointer_t<T>>() + "*";35 else if constexpr (std::is_lvalue_reference_v<T>)36 return typeid_name<std::remove_reference_t<T>>() + "&";37 else if constexpr (std::is_rvalue_reference_v<T>)38 return typeid_name<std::remove_reference_t<T>>() + "&&";39 else if constexpr (std::is_function_v<T>)40 return typeid_func_name<T>::str();41 42 else if constexpr (std::is_same_v<T, void>)43 return "void";44 else if constexpr (std::is_same_v<T, std::string>)45 return "std::string";46 else if constexpr (std::is_same_v<T, color_t>)47 return "color4";48 else if constexpr (std::is_same_v<T, dimension_t>)49 return "float";50 else if constexpr (std::is_same_v<T, int>)51 return "int";52 else if constexpr (std::is_same_v<T, float>)53 return "float";54 else if constexpr (std::is_same_v<T, double>)55 return "double";56 else if constexpr (std::is_same_v<T, size_t>)57 return "size_t";58 else if constexpr (std::is_same_v<T, bool>)59 return "bool";60 else if constexpr (std::is_same_v<T, ImVec2> || std::is_same_v<T, pzdimension2_t>)61 return "ImVec2";62 else if constexpr (std::is_same_v<T, font_name_t>)63 return "ImFont*";64 else if constexpr (std::is_same_v<T, std::vector<std::string>>)65 return "std::vector<std::string>";66 else67 {68 std::string str = typeid(T).name();69#ifdef WIN3270 auto i = str.find(' ');71 if (i != std::string::npos)72 str.erase(0, i + 1); //erase leading struct etc.73#else74 int status;75 char* ptr = abi::__cxa_demangle(str.c_str(), nullptr, nullptr, &status);76 str = ptr;77 free(ptr);78#endif79 return str;80 }81}82 83 84template <class R>85struct typeid_func_name<R()>86{87 static std::string str()88 {89 return typeid_name<R>() + "()";90 }91};92 93template <class R, class A>94struct typeid_func_name<R(A)>95{96 static std::string str()97 {98 return typeid_name<R>() + "(" + typeid_name<A>() + ")";99 }100};101 