utility.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // 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. #ifndef BOOST_UNITS_UTILITY_HPP
  11. #define BOOST_UNITS_UTILITY_HPP
  12. #include <typeinfo>
  13. #include <string>
  14. #include <boost/core/demangle.hpp>
  15. namespace boost {
  16. namespace units {
  17. namespace detail {
  18. inline
  19. std::string
  20. demangle(const char* name)
  21. {
  22. std::string demangled = core::demangle(name);
  23. const std::string::size_type prefix_len = sizeof("boost::units::") - 1;
  24. std::string::size_type i = 0;
  25. for (;;)
  26. {
  27. std::string::size_type pos = demangled.find("boost::units::", i, prefix_len);
  28. if (pos == std::string::npos)
  29. break;
  30. demangled.erase(pos, prefix_len);
  31. i = pos;
  32. }
  33. return demangled;
  34. }
  35. } // namespace detail
  36. template<class L>
  37. inline std::string simplify_typename(const L& /*source*/)
  38. {
  39. return detail::demangle(typeid(L).name());
  40. }
  41. } // namespace units
  42. } // namespace boost
  43. #endif // BOOST_UNITS_UTILITY_HPP