annotate DEPENDENCIES/generic/include/boost/units/detail/utility.hpp @ 16:2665513ce2d3

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