type_info.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //Copyright (c) 2006-2010 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef UUID_C3E1741C754311DDB2834CCA55D89593
  5. #define UUID_C3E1741C754311DDB2834CCA55D89593
  6. #include <boost/config.hpp>
  7. #include <boost/core/typeinfo.hpp>
  8. #include <boost/core/demangle.hpp>
  9. #include <boost/current_function.hpp>
  10. #include <string>
  11. #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  12. #pragma GCC system_header
  13. #endif
  14. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  15. #pragma warning(push,1)
  16. #endif
  17. namespace
  18. boost
  19. {
  20. template <class T>
  21. inline
  22. std::string
  23. tag_type_name()
  24. {
  25. #ifdef BOOST_NO_TYPEID
  26. return BOOST_CURRENT_FUNCTION;
  27. #else
  28. return core::demangle(typeid(T*).name());
  29. #endif
  30. }
  31. template <class T>
  32. inline
  33. std::string
  34. type_name()
  35. {
  36. #ifdef BOOST_NO_TYPEID
  37. return BOOST_CURRENT_FUNCTION;
  38. #else
  39. return core::demangle(typeid(T).name());
  40. #endif
  41. }
  42. namespace
  43. exception_detail
  44. {
  45. struct
  46. type_info_
  47. {
  48. core::typeinfo const * type_;
  49. explicit
  50. type_info_( core::typeinfo const & type ):
  51. type_(&type)
  52. {
  53. }
  54. friend
  55. bool
  56. operator<( type_info_ const & a, type_info_ const & b )
  57. {
  58. return 0!=(a.type_->before(*b.type_));
  59. }
  60. };
  61. }
  62. }
  63. #define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::exception_detail::type_info_(BOOST_CORE_TYPEID(T))
  64. #ifndef BOOST_NO_RTTI
  65. #define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::exception_detail::type_info_(typeid(x))
  66. #endif
  67. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  68. #pragma warning(pop)
  69. #endif
  70. #endif