blob: 47946be563244b5e97e3baf5b753eba016292694 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// Boost.Units - A C++ library for zero-overhead dimensional analysis and
2// unit/quantity manipulation and conversion
3//
4// Copyright (C) 2003-2008 Matthias Christian Schabel
5// Copyright (C) 2008 Steven Watanabe
6//
7// Distributed under the Boost Software License, Version 1.0. (See
8// accompanying file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10
11#ifndef BOOST_UNITS_UTILITY_HPP
12#define BOOST_UNITS_UTILITY_HPP
13
14#include <cstdlib>
15#include <typeinfo>
16#include <string>
17
18#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
19#define BOOST_UNITS_USE_DEMANGLING
20#include <cxxabi.h>
21#endif // __GNUC__
22
23#ifdef BOOST_UNITS_USE_DEMANGLING
24
25#include <ndnboost/algorithm/string/replace.hpp>
26
27namespace ndnboost {
28
29namespace units {
30
31namespace detail {
32
33inline
34std::string
35demangle(const char* name)
36{
37 // need to demangle C++ symbols
38 char* realname;
39 std::size_t len;
40 int stat;
41
42 realname = abi::__cxa_demangle(name,NULL,&len,&stat);
43
44 if (realname != NULL)
45 {
46 std::string out(realname);
47
48 std::free(realname);
49
50 ndnboost::replace_all(out,"ndnboost::units::","");
51
52 return out;
53 }
54
55 return std::string("demangle :: error - unable to demangle specified symbol");
56}
57
58} // namespace detail
59
60template<class L>
61std::string simplify_typename(const L& /*source*/)
62{
63 const std::string demangled = detail::demangle(typeid(L).name());
64
65 return demangled;
66}
67
68} // namespace units
69
70} // namespace ndnboost
71
72#else // BOOST_UNITS_USE_DEMANGLING
73
74namespace ndnboost {
75
76namespace units {
77
78namespace detail {
79
80inline
81std::string
82demangle(const char* name)
83{
84 return name;
85}
86
87} // namespace detail
88
89template<class L>
90std::string simplify_typename(const L& /*source*/)
91{
92 return std::string(typeid(L).name());
93}
94
95} // namespace units
96
97} // namespace ndnboost
98
99// To get system-specific predefined macros:
100// gcc -arch ppc -dM -E - < /dev/null | sort
101
102#endif // BOOST_UNITS_USE_DEMANGLING
103
104#endif // BOOST_UNITS_UTILITY_HPP