Free Electron
type_name.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __platform_type_name_h__
8 #define __platform_type_name_h__
9 
10 namespace fe
11 {
12 
13 //* WARNING having a function templated on T and then calling another
14 //* templated function on a standard container of T, like std::deque<T>
15 //* can inconsistently add the allocator arg to the container type string.
16 
17 // for more complexity, see:
18 // https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c
19 
20 template <class T>
21 fe::String FE_CDECL fe_type_name()
22 {
23 #ifdef __clang__
24  fe::String signature = __PRETTY_FUNCTION__;
25  return signature.prechop(35).chop(1);
26 
27 #elif defined(__GNUC__)
28  fe::String signature = __PRETTY_FUNCTION__;
29 
30 #if FE_CPLUSPLUS < 201402L
31  return signature.prechop(40).chop(1);
32 #else
33  return signature.prechop(50).chop(1);
34 #endif
35 
36 #elif defined(_MSC_VER)
37  fe::String signature = __FUNCSIG__;
38  return signature.prechop(42).chop(7).substitute("class ","").substitute("<class","<");
39 #endif
40 }
41 
42 } /* namespace */
43 
44 #if FE_RTTI && FE_TYPEID
45 #include <typeinfo>
46 #define FE_TYPESTRING(T) fe::System::demangle(typeid(T).name())
47 #else
48 #define FE_TYPESTRING(T) fe::fe_type_name<T>()
49 #endif
50 
51 #endif /* __platform_type_name_h__ */
String prechop(const String &prefix) const
Return the substring after the prefix.
Definition: String.cc:118
kernel
Definition: namespace.dox:3
String substitute(String find, String replace) const
Return a string with replaced substrings.
Definition: String.cc:205
Automatically reference-counted string container.
Definition: String.h:128
String chop(const String &suffix) const
Return the substring before the suffix.
Definition: String.cc:159