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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_ARCH_DEMANGLE_H
25 #define PXR_BASE_ARCH_DEMANGLE_H
26 
27 #if !defined(__cplusplus)
28 #error This include file can only be included in C++ programs.
29 #endif
30 
31 /// \file arch/demangle.h
32 /// \ingroup group_arch_Strings
33 /// Demangle C++ typenames generated by the \c typeid() facility.
34 
35 #include "pxr/pxr.h"
36 #include "pxr/base/arch/api.h"
37 #include <string>
38 #include <typeinfo>
39 #include <typeindex>
40 
42 
43 /// \addtogroup group_arch_Strings
44 ///@{
45 
46 /// Demangle RTTI-generated type name.
47 ///
48 /// Given a variable \c v, the construct \c typeid(v).name() returns
49 /// the type-name of \c v; unfortunately, the returned type-name is
50 /// sometimes extremely encoded (otherwise known as "mangled").
51 /// \c ArchDemangle parses the passed in type-name \c typeName into a
52 /// readable form, and overwrites \c typeName. If \c typeName
53 /// cannot be unmangled, the function returns \c false without altering
54 /// \c typeName. Otherwise \c true is returned.
55 ARCH_API bool ArchDemangle(std::string* typeName);
56 
57 /// Return demangled RTTI-generated type name.
58 ///
59 /// If \c typeName can be demangled, the function returns the demangled
60 /// string; otherwise, the function returns the empty string.
61 ///
62 /// \see ArchDemangle()
64 ArchGetDemangled(const std::string& typeName);
65 
66 /// Return demangled RTTI-generated type name.
67 ///
68 /// \see ArchDemangle()
69 /// \overload
71 ArchGetDemangled(const char *typeName);
72 
73 /// Return demangled RTTI-generated type name.
74 ///
75 /// Returns the demangled name associated with typeInfo (i.e. typeInfo.name()).
76 ///
77 /// \see ArchDemangle()
78 /// \overload
79 inline std::string
80 ArchGetDemangled(const std::type_info& typeInfo) {
81  return ArchGetDemangled(typeInfo.name());
82 }
83 
84 /// Return demangled RTTI-generated type name.
85 ///
86 /// Returns the demangled name associated with typeIndex (i.e. typeIndex.name()).
87 ///
88 /// \see ArchDemangle()
89 /// \overload
90 inline std::string
91 ArchGetDemangled(const std::type_index& typeIndex) {
92  return ArchGetDemangled(typeIndex.name());
93 }
94 
95 /// Return demangled RTTI generated-type name.
96 ///
97 /// Returns the demangled name of type T.
98 ///
99 /// \see ArchDemangle()
100 /// \overload
101 template <typename T>
102 inline std::string
104  return ArchGetDemangled(typeid(T).name());
105 }
106 
107 ///@}
108 
109 /// \private
110 ARCH_API
111 void Arch_DemangleFunctionName(std::string* functionName);
112 
114 
115 #endif // PXR_BASE_ARCH_DEMANGLE_H
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
#define ARCH_API
Definition: api.h:40