| 1 | #ifndef BOOST_CORE_TYPEINFO_HPP_INCLUDED |
| 2 | #define BOOST_CORE_TYPEINFO_HPP_INCLUDED |
| 3 | |
| 4 | // MS compatible compilers support #pragma once |
| 5 | |
| 6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 7 | # pragma once |
| 8 | #endif |
| 9 | |
| 10 | // core::typeinfo, BOOST_CORE_TYPEID |
| 11 | // |
| 12 | // Copyright 2007, 2014 Peter Dimov |
| 13 | // |
| 14 | // Distributed under the Boost Software License, Version 1.0. |
| 15 | // See accompanying file LICENSE_1_0.txt or copy at |
| 16 | // http://www.boost.org/LICENSE_1_0.txt) |
| 17 | |
| 18 | #include <boost/config.hpp> |
| 19 | |
| 20 | #if defined( BOOST_NO_TYPEID ) |
| 21 | |
| 22 | #include <boost/current_function.hpp> |
| 23 | #include <functional> |
| 24 | |
| 25 | namespace boost |
| 26 | { |
| 27 | |
| 28 | namespace core |
| 29 | { |
| 30 | |
| 31 | class typeinfo |
| 32 | { |
| 33 | private: |
| 34 | |
| 35 | typeinfo( typeinfo const& ); |
| 36 | typeinfo& operator=( typeinfo const& ); |
| 37 | |
| 38 | char const * name_; |
| 39 | |
| 40 | public: |
| 41 | |
| 42 | explicit typeinfo( char const * name ): name_( name ) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | bool operator==( typeinfo const& rhs ) const |
| 47 | { |
| 48 | return this == &rhs; |
| 49 | } |
| 50 | |
| 51 | bool operator!=( typeinfo const& rhs ) const |
| 52 | { |
| 53 | return this != &rhs; |
| 54 | } |
| 55 | |
| 56 | bool before( typeinfo const& rhs ) const |
| 57 | { |
| 58 | return std::less< typeinfo const* >()( this, &rhs ); |
| 59 | } |
| 60 | |
| 61 | char const* name() const |
| 62 | { |
| 63 | return name_; |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | inline char const * demangled_name( core::typeinfo const & ti ) |
| 68 | { |
| 69 | return ti.name(); |
| 70 | } |
| 71 | |
| 72 | } // namespace core |
| 73 | |
| 74 | namespace detail |
| 75 | { |
| 76 | |
| 77 | template<class T> struct core_typeid_ |
| 78 | { |
| 79 | static boost::core::typeinfo ti_; |
| 80 | |
| 81 | static char const * name() |
| 82 | { |
| 83 | return BOOST_CURRENT_FUNCTION; |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | #if defined(__SUNPRO_CC) |
| 88 | // see #4199, the Sun Studio compiler gets confused about static initialization |
| 89 | // constructor arguments. But an assignment works just fine. |
| 90 | template<class T> boost::core::typeinfo core_typeid_< T >::ti_ = core_typeid_< T >::name(); |
| 91 | #else |
| 92 | template<class T> boost::core::typeinfo core_typeid_< T >::ti_(core_typeid_< T >::name()); |
| 93 | #endif |
| 94 | |
| 95 | template<class T> struct core_typeid_< T & >: core_typeid_< T > |
| 96 | { |
| 97 | }; |
| 98 | |
| 99 | template<class T> struct core_typeid_< T const >: core_typeid_< T > |
| 100 | { |
| 101 | }; |
| 102 | |
| 103 | template<class T> struct core_typeid_< T volatile >: core_typeid_< T > |
| 104 | { |
| 105 | }; |
| 106 | |
| 107 | template<class T> struct core_typeid_< T const volatile >: core_typeid_< T > |
| 108 | { |
| 109 | }; |
| 110 | |
| 111 | } // namespace detail |
| 112 | |
| 113 | } // namespace boost |
| 114 | |
| 115 | #define BOOST_CORE_TYPEID(T) (boost::detail::core_typeid_<T>::ti_) |
| 116 | |
| 117 | #else |
| 118 | |
| 119 | #include <boost/core/demangle.hpp> |
| 120 | #include <typeinfo> |
| 121 | |
| 122 | namespace boost |
| 123 | { |
| 124 | |
| 125 | namespace core |
| 126 | { |
| 127 | |
| 128 | #if defined( BOOST_NO_STD_TYPEINFO ) |
| 129 | |
| 130 | typedef ::type_info typeinfo; |
| 131 | |
| 132 | #else |
| 133 | |
| 134 | typedef std::type_info typeinfo; |
| 135 | |
| 136 | #endif |
| 137 | |
| 138 | inline std::string demangled_name( core::typeinfo const & ti ) |
| 139 | { |
| 140 | return core::demangle( ti.name() ); |
| 141 | } |
| 142 | |
| 143 | } // namespace core |
| 144 | |
| 145 | } // namespace boost |
| 146 | |
| 147 | #define BOOST_CORE_TYPEID(T) typeid(T) |
| 148 | |
| 149 | #endif |
| 150 | |
| 151 | #endif // #ifndef BOOST_CORE_TYPEINFO_HPP_INCLUDED |
| 152 | |