Nugget
GetTypeName.h
1 // Copyright (c) Electronic Arts Inc. All rights reserved.
4 
5 
6 #ifndef GETTYPENAME_H
7 #define GETTYPENAME_H
8 
9 
10 #include <EABase/eabase.h>
11 #include <EASTL/type_traits.h>
12 #include <EASTL/string.h>
13 #include <stdlib.h>
14 #include <typeinfo>
15 
16 
18 // EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE
19 //
20 // Defined as 0 or 1. The value depends on the compilation environment.
21 // Indicates if we can use system-provided abi::__cxa_demangle() at runtime.
22 //
23 #if !defined(EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE)
24  #if (defined(EA_PLATFORM_LINUX) || defined(EA_PLATFORM_APPLE)) && defined(EA_PLATFORM_DESKTOP)
25  #define EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE 1
26  #else
27  #define EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE 0
28  #endif
29 #endif
30 
31 
32 #if EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE
33  #include <cxxabi.h>
34 #elif EA_WINAPI_FAMILY_PARTITION(EA_WINAPI_PARTITION_DESKTOP)
35  EA_DISABLE_ALL_VC_WARNINGS();
36  #include <Windows.h>
37  #include <DbgHelp.h>
38  #pragma comment(lib, "dbghelp.lib")
39  EA_RESTORE_ALL_VC_WARNINGS();
40 #endif
41 
42 
44 // EASTLTEST_GETTYPENAME_AVAILABLE
45 //
46 // Defined as 0 or 1. The value depends on the compilation environment.
47 // Indicates if we can use system-provided abi::__cxa_demangle() at runtime.
48 //
49 #if !defined(EASTLTEST_GETTYPENAME_AVAILABLE)
50  #if (EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE || EA_WINAPI_FAMILY_PARTITION(EA_WINAPI_PARTITION_DESKTOP)) && (!defined(EA_COMPILER_NO_RTTI) || defined(_MSC_VER)) // VC++ works without RTTI enabled.
51  #define EASTLTEST_GETTYPENAME_AVAILABLE 1
52  #else
53  #define EASTLTEST_GETTYPENAME_AVAILABLE 0
54  #endif
55 #endif
56 
57 
62 template <typename T>
63 eastl::string GetTypeName()
64 {
65  eastl::string result;
66 
67  #if !defined(EA_COMPILER_NO_RTTI) || defined(_MSC_VER) // VC++ works without RTTI enabled.
68  typedef typename eastl::remove_reference<T>::type TR;
69 
70  const char* pName = typeid(TR).name();
71 
72  #if EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE
73  const char* pDemangledName = abi::__cxa_demangle(pName, NULL, NULL, NULL);
74 
75  #elif EA_WINAPI_FAMILY_PARTITION(EA_WINAPI_PARTITION_DESKTOP)
76  char pDemangledName[1024];
77  DWORD count = UnDecorateSymbolName(pName, pDemangledName, (DWORD)EAArrayCount(pDemangledName), UNDNAME_NO_THISTYPE | UNDNAME_NO_ACCESS_SPECIFIERS | UNDNAME_NO_MEMBER_TYPE);
78  if(count == 0)
79  pDemangledName[0] = 0;
80  #else
81  const char* pDemangledName = NULL;
82  #endif
83 
84  if(pDemangledName && pDemangledName[0])
85  result = pDemangledName;
86  else
87  result = pName;
88 
90  result += " const";
91 
93  result += " volatile";
94 
96  result += "&";
98  result += "&&";
99 
100  if(pDemangledName)
101  {
102  #if EASTL_LIBSTDCPP_DEMANGLE_AVAILABLE
103  free((void*)(pDemangledName));
104  #endif
105  }
106  #endif
107 
108  return result;
109 }
110 
111 
112 #endif // Header include guard
113 
114 
115 
116 
117 
118 
119 
Definition: string.h:280
Definition: type_traits.h:628
Definition: type_properties.h:328
Definition: type_properties.h:344
Definition: type_traits.h:650