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 | #include <cstring> |
25 | |
26 | namespace boost |
27 | { |
28 | |
29 | namespace core |
30 | { |
31 | |
32 | class typeinfo |
33 | { |
34 | private: |
35 | |
36 | typeinfo( typeinfo const& ); |
37 | typeinfo& operator=( typeinfo const& ); |
38 | |
39 | char const * name_; |
40 | void (*lib_id_)(); |
41 | |
42 | public: |
43 | |
44 | typeinfo( char const * name, void (*lib_id)() ): name_( name ), lib_id_( lib_id ) |
45 | { |
46 | } |
47 | |
48 | bool operator==( typeinfo const& rhs ) const |
49 | { |
50 | #if ( defined(_WIN32) || defined(__CYGWIN__) ) && ( defined(__GNUC__) || defined(__clang__) ) && !defined(BOOST_DISABLE_CURRENT_FUNCTION) |
51 | |
52 | return lib_id_ == rhs.lib_id_? this == &rhs: std::strcmp( name_, rhs.name_ ) == 0; |
53 | |
54 | #else |
55 | |
56 | return this == &rhs; |
57 | |
58 | #endif |
59 | } |
60 | |
61 | bool operator!=( typeinfo const& rhs ) const |
62 | { |
63 | return !( *this == rhs ); |
64 | } |
65 | |
66 | bool before( typeinfo const& rhs ) const |
67 | { |
68 | #if ( defined(_WIN32) || defined(__CYGWIN__) ) && ( defined(__GNUC__) || defined(__clang__) ) && !defined(BOOST_DISABLE_CURRENT_FUNCTION) |
69 | |
70 | return lib_id_ == rhs.lib_id_? std::less< typeinfo const* >()( this, &rhs ): std::strcmp( name_, rhs.name_ ) < 0; |
71 | |
72 | #else |
73 | |
74 | return std::less< typeinfo const* >()( this, &rhs ); |
75 | |
76 | #endif |
77 | } |
78 | |
79 | char const* name() const |
80 | { |
81 | return name_; |
82 | } |
83 | }; |
84 | |
85 | inline char const * demangled_name( core::typeinfo const & ti ) |
86 | { |
87 | return ti.name(); |
88 | } |
89 | |
90 | } // namespace core |
91 | |
92 | namespace detail |
93 | { |
94 | |
95 | template<class T> struct BOOST_SYMBOL_VISIBLE core_typeid_ |
96 | { |
97 | static boost::core::typeinfo ti_; |
98 | |
99 | static char const * name() |
100 | { |
101 | return BOOST_CURRENT_FUNCTION; |
102 | } |
103 | }; |
104 | |
105 | BOOST_SYMBOL_VISIBLE inline void core_typeid_lib_id() |
106 | { |
107 | } |
108 | |
109 | template<class T> boost::core::typeinfo core_typeid_< T >::ti_( core_typeid_< T >::name(), &core_typeid_lib_id ); |
110 | |
111 | template<class T> struct core_typeid_< T & >: core_typeid_< T > |
112 | { |
113 | }; |
114 | |
115 | template<class T> struct core_typeid_< T const >: core_typeid_< T > |
116 | { |
117 | }; |
118 | |
119 | template<class T> struct core_typeid_< T volatile >: core_typeid_< T > |
120 | { |
121 | }; |
122 | |
123 | template<class T> struct core_typeid_< T const volatile >: core_typeid_< T > |
124 | { |
125 | }; |
126 | |
127 | } // namespace detail |
128 | |
129 | } // namespace boost |
130 | |
131 | #define BOOST_CORE_TYPEID(T) (boost::detail::core_typeid_<T>::ti_) |
132 | |
133 | #else |
134 | |
135 | #include <boost/core/demangle.hpp> |
136 | #include <typeinfo> |
137 | |
138 | namespace boost |
139 | { |
140 | |
141 | namespace core |
142 | { |
143 | |
144 | #if defined( BOOST_NO_STD_TYPEINFO ) |
145 | |
146 | typedef ::type_info typeinfo; |
147 | |
148 | #else |
149 | |
150 | typedef std::type_info typeinfo; |
151 | |
152 | #endif |
153 | |
154 | inline std::string demangled_name( core::typeinfo const & ti ) |
155 | { |
156 | return core::demangle( name: ti.name() ); |
157 | } |
158 | |
159 | } // namespace core |
160 | |
161 | } // namespace boost |
162 | |
163 | #define BOOST_CORE_TYPEID(T) typeid(T) |
164 | |
165 | #endif |
166 | |
167 | #endif // #ifndef BOOST_CORE_TYPEINFO_HPP_INCLUDED |
168 | |