JeVois  1.2
JeVois Smart Embedded Machine Vision Toolkit
DemangleImpl.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 // This code is inspired by the Neuromorphic Robotics Toolkit (http://nrtkit.org)
19 
20 #pragma once
21 
22 #include <string>
23 #include <stdlib.h>
24 
25 // ######################################################################
26 #if (__GNUC__ && __GNUC__ >= 3)
27 #include <cxxabi.h>
28 
29 inline std::string jevois::demangle(std::string const & mangledName)
30 {
31  int status = 0; char *demangledName = nullptr; std::size_t len;
32 
33  demangledName = abi::__cxa_demangle(mangledName.c_str(), 0, &len, &status);
34 
35  std::string retName(demangledName);
36  free(demangledName);
37  return retName;
38 }
39 
40 inline std::string jevois::demangle(char const * mangledName)
41 {
42  int status = 0; char *demangledName = nullptr; std::size_t len;
43 
44  demangledName = abi::__cxa_demangle(mangledName, 0, &len, &status);
45 
46  std::string retName(demangledName);
47  free(demangledName);
48  return retName;
49 }
50 
51 #else // (__GNUC__ && __GNUC__ >= 3)
52 
53 // We don't know how to demangle on other compilers than gcc...
54 inline std::string jevois::demangle(std::string const & mangledName)
55 { return mangledName; }
56 
57 inline std::string jevois::demangle(char const * mangledName)
58 { return std::string(mangledName); }
59 
60 #endif // (__GNUC__ && __GNUC__ >= 3)
61 
62 // ######################################################################
63 template <typename T> inline
64 std::string jevois::demangledName()
65 { return jevois::demangle(typeid(T).name()); }
66 
67 // ######################################################################
68 namespace jevois
69 {
70  template <> inline
71  std::string demangledName<std::string>() { return "string"; }
72 }
73 
std::string demangle(std::string const &mangledName)
Demangle a mangled name.
Definition: DemangleImpl.H:54
std::string demangledName()
Get the demangled type name of type T.
Definition: DemangleImpl.H:64