CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TypeID.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 
3 ----------------------------------------------------------------------*/
4 #include <ostream>
11 #include "Reflex/Type.h"
12 #include "boost/thread/tss.hpp"
13 
14 namespace edm {
15  void
16  TypeID::print(std::ostream& os) const {
17  try {
18  os << className();
19  } catch (cms::Exception const& e) {
20  os << typeInfo().name();
21  }
22  }
23 
24 namespace {
25 
26  std::string typeToClassName(std::type_info const& iType) {
27  Reflex::Type t = Reflex::Type::ByTypeInfo(iType);
28  if (!bool(t)) {
29 #if GCC_PREREQUISITE(3,0,0)
30  // demangling supported for currently supported gcc compilers.
31  try {
32  std::string result;
33  typeDemangle(iType.name(), result);
34  return result;
35  } catch (cms::Exception const& e) {
36  edm::Exception theError(errors::DictionaryNotFound,"NoMatch");
37  theError << "TypeID::className: No dictionary for class " << iType.name() << '\n';
38  theError.append(e);
39  throw theError;
40  }
41 #else
43  << "TypeID::className: No dictionary for class " << iType.name() << '\n';
44 #endif
45  }
46  return t.Name(Reflex::SCOPED);
47  }
48 }
49 
50  std::string
52  typedef std::map<edm::TypeID, std::string> Map;
53  static boost::thread_specific_ptr<Map> s_typeToName;
54  if(0 == s_typeToName.get()){
55  s_typeToName.reset(new Map);
56  }
57  Map::const_iterator itFound = s_typeToName->find(*this);
58  if(s_typeToName->end() == itFound) {
59  itFound = s_typeToName->insert(Map::value_type(*this, typeToClassName(typeInfo()))).first;
60  }
61  return itFound->second;
62  }
63 
64  std::string
66  std::string theName = className();
67  if (theName.find("edm::Wrapper") == 0) {
68  stripTemplate(theName);
69  }
70  return theName;
71  }
72 
73  std::string
76  }
77 
78  bool
79  TypeID::stripTemplate(std::string& theName) {
80  std::string const spec("<,>");
81  char const space = ' ';
82  std::string::size_type idx = theName.find_first_of(spec);
83  if (idx == std::string::npos) {
84  return false;
85  }
87  std::string::size_type after = idx;
88  if (theName[idx] == '<') {
89  after = theName.rfind('>');
90  assert (after != std::string::npos);
91  first = ++idx;
92  } else {
93  theName = theName.substr(0, idx);
94  }
95  std::string::size_type idxa = after;
96  while (space == theName[--idxa]) --after;
98  while (space == theName[idxf++]) ++first;
99  theName = theName.substr(first, after - first);
100  return true;
101  }
102 
103  bool
104  TypeID::stripNamespace(std::string& theName) {
105  std::string::size_type idx = theName.rfind(':');
106  bool ret = (idx != std::string::npos);
107  if (ret) {
108  ++idx;
109  theName = theName.substr(idx);
110  }
111  return ret;
112  }
113 
114  bool
116  return bool(Reflex::Type::ByTypeInfo(typeInfo()));
117  }
118 
119  std::ostream&
120  operator<<(std::ostream& os, TypeID const& id) {
121  id.print(os);
122  return os;
123  }
124 }
125 
void print(std::ostream &os) const
Definition: TypeID.cc:16
static bool stripNamespace(std::string &theName)
Definition: TypeID.cc:104
const std::type_info & typeInfo() const
Definition: TypeIDBase.h:54
uint16_t size_type
bool hasDictionary() const
Definition: TypeID.cc:115
void typeDemangle(char const *mangledName, std::string &demangledName)
std::string friendlyName(std::string const &iFullName)
tuple result
Definition: query.py:137
Container::value_type value_type
std::string className() const
Definition: TypeID.cc:51
static bool stripTemplate(std::string &theName)
Definition: TypeID.cc:79
std::string userClassName() const
Definition: TypeID.cc:65
T first(std::pair< T, U > const &p)
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
std::string friendlyClassName() const
Definition: TypeID.cc:74