HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
demangle.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_ARCH_DEMANGLE_H
8 #define PXR_BASE_ARCH_DEMANGLE_H
9 
10 #if !defined(__cplusplus)
11 #error This include file can only be included in C++ programs.
12 #endif
13 
14 /// \file arch/demangle.h
15 /// \ingroup group_arch_Strings
16 /// Demangle C++ typenames generated by the \c typeid() facility.
17 
18 #include "pxr/pxr.h"
19 #include "pxr/base/arch/api.h"
20 #include <string>
21 #include <typeinfo>
22 #include <typeindex>
23 
25 
26 /// \addtogroup group_arch_Strings
27 ///@{
28 
29 /// Demangle RTTI-generated type name.
30 ///
31 /// Given a variable \c v, the construct \c typeid(v).name() returns
32 /// the type-name of \c v; unfortunately, the returned type-name is
33 /// sometimes extremely encoded (otherwise known as "mangled").
34 /// \c ArchDemangle parses the passed in type-name \c typeName into a
35 /// readable form, and overwrites \c typeName. If \c typeName
36 /// cannot be unmangled, the function returns \c false without altering
37 /// \c typeName. Otherwise \c true is returned.
38 ARCH_API bool ArchDemangle(std::string* typeName);
39 
40 /// Return demangled RTTI-generated type name.
41 ///
42 /// If \c typeName can be demangled, the function returns the demangled
43 /// string; otherwise, the function returns the empty string.
44 ///
45 /// \see ArchDemangle()
46 ARCH_API std::string
47 ArchGetDemangled(const std::string& typeName);
48 
49 /// Return demangled RTTI-generated type name.
50 ///
51 /// \see ArchDemangle()
52 /// \overload
53 ARCH_API std::string
54 ArchGetDemangled(const char *typeName);
55 
56 /// Return demangled RTTI-generated type name.
57 ///
58 /// Returns the demangled name associated with typeInfo (i.e. typeInfo.name()).
59 ///
60 /// \see ArchDemangle()
61 /// \overload
62 inline std::string
63 ArchGetDemangled(const std::type_info& typeInfo) {
64  return ArchGetDemangled(typeInfo.name());
65 }
66 
67 /// Return demangled RTTI-generated type name.
68 ///
69 /// Returns the demangled name associated with typeIndex (i.e. typeIndex.name()).
70 ///
71 /// \see ArchDemangle()
72 /// \overload
73 inline std::string
74 ArchGetDemangled(const std::type_index& typeIndex) {
75  return ArchGetDemangled(typeIndex.name());
76 }
77 
78 /// Return demangled RTTI generated-type name.
79 ///
80 /// Returns the demangled name of type T.
81 ///
82 /// \see ArchDemangle()
83 /// \overload
84 template <typename T>
85 inline std::string
87  return ArchGetDemangled(typeid(T).name());
88 }
89 
90 ///@}
91 
92 /// \private
94 void Arch_DemangleFunctionName(std::string* functionName);
95 
97 
98 #endif // PXR_BASE_ARCH_DEMANGLE_H
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
GLuint const GLchar * name
Definition: glcorearb.h:786
ARCH_API bool ArchDemangle(std::string *typeName)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define ARCH_API
Definition: api.h:23