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