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 
9 #include "drake/drakeCommon_export.h"
10 
11 namespace drake {
12 
37 class NiceTypeName {
38  public:
47  template <typename T>
48  static const std::string& Get() {
49  static const std::string* canonical = // never deleted
50  new std::string(Canonicalize(Demangle(typeid(T).name())));
51  return *canonical;
52  }
53  DRAKECOMMON_EXPORT
59  static std::string Demangle(const char* typeid_name);
60  DRAKECOMMON_EXPORT
68  static std::string Canonicalize(const std::string& demangled_name);
69 
70  private:
71  // No instances of this class should be created.
72  NiceTypeName() = delete;
73 };
74 
75 } // namespace drake
Obtains canonicalized, platform-independent, human-readable names for arbitrarily-complicated C++ typ...
Definition: nice_type_name.h:37
Definition: constants.h:3
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:46
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:29
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:48