comparison DEPENDENCIES/generic/include/boost/units/detail/utility.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
9 // http://www.boost.org/LICENSE_1_0.txt) 9 // http://www.boost.org/LICENSE_1_0.txt)
10 10
11 #ifndef BOOST_UNITS_UTILITY_HPP 11 #ifndef BOOST_UNITS_UTILITY_HPP
12 #define BOOST_UNITS_UTILITY_HPP 12 #define BOOST_UNITS_UTILITY_HPP
13 13
14 #include <cstdlib>
15 #include <typeinfo> 14 #include <typeinfo>
16 #include <string> 15 #include <string>
17 16 #include <boost/core/demangle.hpp>
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 <boost/algorithm/string/replace.hpp>
26 17
27 namespace boost { 18 namespace boost {
28 19
29 namespace units { 20 namespace units {
30 21
32 23
33 inline 24 inline
34 std::string 25 std::string
35 demangle(const char* name) 26 demangle(const char* name)
36 { 27 {
37 // need to demangle C++ symbols 28 std::string demangled = core::demangle(name);
38 char* realname; 29
39 std::size_t len; 30 const std::string::size_type prefix_len = sizeof("boost::units::") - 1;
40 int stat; 31 std::string::size_type i = 0;
41 32 for (;;)
42 realname = abi::__cxa_demangle(name,NULL,&len,&stat);
43
44 if (realname != NULL)
45 { 33 {
46 std::string out(realname); 34 std::string::size_type pos = demangled.find("boost::units::", i, prefix_len);
47 35 if (pos == std::string::npos)
48 std::free(realname); 36 break;
49 37
50 boost::replace_all(out,"boost::units::",""); 38 demangled.erase(pos, prefix_len);
51 39 i = pos;
52 return out;
53 } 40 }
54 41
55 return std::string("demangle :: error - unable to demangle specified symbol"); 42 return demangled;
56 } 43 }
57 44
58 } // namespace detail 45 } // namespace detail
59 46
60 template<class L> 47 template<class L>
61 std::string simplify_typename(const L& /*source*/) 48 inline std::string simplify_typename(const L& /*source*/)
62 { 49 {
63 const std::string demangled = detail::demangle(typeid(L).name()); 50 return detail::demangle(typeid(L).name());
64
65 return demangled;
66 } 51 }
67 52
68 } // namespace units 53 } // namespace units
69 54
70 } // namespace boost 55 } // namespace boost
71 56
72 #else // BOOST_UNITS_USE_DEMANGLING
73
74 namespace boost {
75
76 namespace units {
77
78 namespace detail {
79
80 inline
81 std::string
82 demangle(const char* name)
83 {
84 return name;
85 }
86
87 } // namespace detail
88
89 template<class L>
90 std::string simplify_typename(const L& /*source*/)
91 {
92 return std::string(typeid(L).name());
93 }
94
95 } // namespace units
96
97 } // namespace boost
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 57 #endif // BOOST_UNITS_UTILITY_HPP