Drake
nice_type_name.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <typeinfo>
6 #include <utility>
7 #include <vector>
8 
10 
11 namespace drake {
12 
44 class NiceTypeName {
45  public:
52  template <typename T>
53  static const std::string& Get() {
54  static const never_destroyed<std::string> canonical(
55  Canonicalize(Demangle(typeid(T).name())));
56  return canonical.access();
57  }
58 
65  template <typename T>
66  static std::string Get(const T& thing) {
67  return Canonicalize(Demangle(typeid(thing).name()));
68  }
69 
74  static std::string Demangle(const char* typeid_name);
75 
82  static std::string Canonicalize(const std::string& demangled_name);
83 
84  private:
85  // No instances of this class should be created.
86  NiceTypeName() = delete;
87 };
88 
89 } // namespace drake
Obtains canonicalized, platform-independent, human-readable names for arbitrarily-complicated C++ typ...
Definition: nice_type_name.h:44
Definition: automotive_demo.cc:88
static std::string Canonicalize(const std::string &demangled_name)
Given a compiler-dependent demangled type name string as returned by Demangle(), attempts to form a c...
Definition: nice_type_name.cc:50
static std::string Demangle(const char *typeid_name)
Using the algorithm appropriate to the current compiler, demangles a type name as returned by typeid(...
Definition: nice_type_name.cc:33
static std::string Get(const T &thing)
Returns the type name of the most-derived type of an object of type T, typically but not necessarily ...
Definition: nice_type_name.h:66
static const std::string & Get()
Attempts to return a nicely demangled and canonicalized type name that is the same on all platforms...
Definition: nice_type_name.h:53
Wraps an underlying type T such that its storage is a direct member field of this object (i...
Definition: never_destroyed.h:25
T & access()
Returns the underlying T reference.
Definition: never_destroyed.h:40