typeinfo.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef BOOST_CORE_TYPEINFO_HPP_INCLUDED
  2. #define BOOST_CORE_TYPEINFO_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. // core::typeinfo, BOOST_CORE_TYPEID
  8. //
  9. // Copyright 2007, 2014 Peter Dimov
  10. //
  11. // Distributed under the Boost Software License, Version 1.0.
  12. // See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #include <boost/config.hpp>
  15. #if defined( BOOST_NO_TYPEID )
  16. #include <boost/current_function.hpp>
  17. #include <functional>
  18. #include <cstring>
  19. namespace boost
  20. {
  21. namespace core
  22. {
  23. class typeinfo
  24. {
  25. private:
  26. typeinfo( typeinfo const& );
  27. typeinfo& operator=( typeinfo const& );
  28. char const * name_;
  29. void (*lib_id_)();
  30. public:
  31. typeinfo( char const * name, void (*lib_id)() ): name_( name ), lib_id_( lib_id )
  32. {
  33. }
  34. bool operator==( typeinfo const& rhs ) const
  35. {
  36. #if ( defined(_WIN32) || defined(__CYGWIN__) ) && ( defined(__GNUC__) || defined(__clang__) ) && !defined(BOOST_DISABLE_CURRENT_FUNCTION)
  37. return lib_id_ == rhs.lib_id_? this == &rhs: std::strcmp( name_, rhs.name_ ) == 0;
  38. #else
  39. return this == &rhs;
  40. #endif
  41. }
  42. bool operator!=( typeinfo const& rhs ) const
  43. {
  44. return !( *this == rhs );
  45. }
  46. bool before( typeinfo const& rhs ) const
  47. {
  48. #if ( defined(_WIN32) || defined(__CYGWIN__) ) && ( defined(__GNUC__) || defined(__clang__) ) && !defined(BOOST_DISABLE_CURRENT_FUNCTION)
  49. return lib_id_ == rhs.lib_id_? std::less< typeinfo const* >()( this, &rhs ): std::strcmp( name_, rhs.name_ ) < 0;
  50. #else
  51. return std::less< typeinfo const* >()( this, &rhs );
  52. #endif
  53. }
  54. char const* name() const
  55. {
  56. return name_;
  57. }
  58. };
  59. inline char const * demangled_name( core::typeinfo const & ti )
  60. {
  61. return ti.name();
  62. }
  63. } // namespace core
  64. namespace detail
  65. {
  66. template<class T> struct BOOST_SYMBOL_VISIBLE core_typeid_
  67. {
  68. static boost::core::typeinfo ti_;
  69. static char const * name()
  70. {
  71. return BOOST_CURRENT_FUNCTION;
  72. }
  73. };
  74. BOOST_SYMBOL_VISIBLE inline void core_typeid_lib_id()
  75. {
  76. }
  77. template<class T> boost::core::typeinfo core_typeid_< T >::ti_( core_typeid_< T >::name(), &core_typeid_lib_id );
  78. template<class T> struct core_typeid_< T & >: core_typeid_< T >
  79. {
  80. };
  81. template<class T> struct core_typeid_< T const >: core_typeid_< T >
  82. {
  83. };
  84. template<class T> struct core_typeid_< T volatile >: core_typeid_< T >
  85. {
  86. };
  87. template<class T> struct core_typeid_< T const volatile >: core_typeid_< T >
  88. {
  89. };
  90. } // namespace detail
  91. } // namespace boost
  92. #define BOOST_CORE_TYPEID(T) (boost::detail::core_typeid_<T>::ti_)
  93. #else
  94. #include <boost/core/demangle.hpp>
  95. #include <typeinfo>
  96. namespace boost
  97. {
  98. namespace core
  99. {
  100. #if defined( BOOST_NO_STD_TYPEINFO )
  101. typedef ::type_info typeinfo;
  102. #else
  103. typedef std::type_info typeinfo;
  104. #endif
  105. inline std::string demangled_name( core::typeinfo const & ti )
  106. {
  107. return core::demangle( ti.name() );
  108. }
  109. } // namespace core
  110. } // namespace boost
  111. #define BOOST_CORE_TYPEID(T) typeid(T)
  112. #endif
  113. #endif // #ifndef BOOST_CORE_TYPEINFO_HPP_INCLUDED