fw4spl
Stringizer.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 WIN32
8 #include <cxxabi.h>
9 #include <stdlib.h>
10 #endif
11 
12 #include "fwTools/Stringizer.hpp"
13 
14 
15 namespace fwTools
16 {
17 
18 //------------------------------------------------------------------------------
19 
20 template<>
21 std::string getString(const std::string &aString)
22 {
23  return aString;
24 }
25 
26 //------------------------------------------------------------------------------
27 
28 template<>
29 std::string getString(const std::type_info &ti)
30 {
31 #ifndef WIN32
32  char *demangled = abi::__cxa_demangle(ti.name(),0,0,0);
33  if (demangled)
34  {
35  std::string res(demangled);
36  free(demangled);
37  return res;
38  }
39  else
40  {
41  return ti.name();
42  }
43 #else
44  return ti.name();
45 #endif
46 }
47 
48 //------------------------------------------------------------------------------
49 
50 template<>
51 std::string getString(const TypeInfo &ti)
52 {
53  return getString(ti.type_info());
54 }
55 
56 //------------------------------------------------------------------------------
57 
58 template<>
59 std::string getString(const signed char &c)
60 {
61  return boost::lexical_cast<std::string>((short)c);
62 }
63 
64 //------------------------------------------------------------------------------
65 
66 template<>
67 std::string getString(const char &c)
68 {
69  return boost::lexical_cast<std::string>((short)c);
70 }
71 
72 //------------------------------------------------------------------------------
73 
74 template<>
75 std::string getString(const unsigned char &c)
76 {
77  return boost::lexical_cast<std::string>((short)c);
78 }
79 
80 //------------------------------------------------------------------------------
81 
82 }
Purpose: offer a first-class, comparable wrapper over std::type_info ( but copy construcible ) ...
Definition: TypeInfo.hpp:22
FWTOOLS_API const std::type_info & type_info() const
access for the wrapped std::type_info
Definition: TypeInfo.cpp:42
The namespace fwTools contains several tools like UUID, factory, dispatche, stringizer, macros, helper.