fw4spl
Demangler.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWCORE_DEMANGLER_HPP__
8 #define __FWCORE_DEMANGLER_HPP__
9 
10 #include "fwCore/config.hpp"
11 
12 #include <string>
13 #include <typeinfo>
14 
15 namespace fwCore
16 {
17 
23 class FWCORE_CLASS_API Demangler
24 {
25 public:
26 
36  FWCORE_API Demangler(const std::type_info& t);
37 
43  FWCORE_API Demangler(const std::string& s);
44 
50  template<typename T> Demangler(T& s) :
51  m_name(typeid(s).name())
52  {
53  }
54 
58  FWCORE_API virtual ~Demangler();
59 
67  FWCORE_API std::string getLeafClassname() const;
68 
74  FWCORE_API std::string getClassname() const;
75 
76 protected:
80  const std::string m_name;
81 
87  std::string demangle() const;
88 };
89 
94 template <class T>
95 class TypeDemangler : public Demangler
96 {
97 public:
107  Demangler(typeid(T))
108  {
109  }
110 
112 };
113 
122 template <class T>
123 inline std::string getLeafClassname()
124 {
125  return TypeDemangler<T>().getLeafClassname();
126 }
127 //------------------------------------------------------------------------------
128 
129 template <class T>
130 inline std::string getClassname()
131 {
132  return TypeDemangler<T>().getClassname();
133 }
136 } // namespace fwCore
137 
138 #endif // __FWCORE_DEMANGLER_HPP__
This namespace fwCore provides common foundations for FW4SPL.
Definition: BaseObject.hpp:16
Type demangler. Use Demangler class to get a demangled string for the type T.
Definition: Demangler.hpp:95
TypeDemangler()
Constructor.
Definition: Demangler.hpp:106
Demangler(T &s)
Constructor from any type.
Definition: Demangler.hpp:50
const std::string m_name
Store the name to demangle.
Definition: Demangler.hpp:80
typeid, string or object name demangler.
Definition: Demangler.hpp:23