2 //===-------------------------- typeinfo ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef __LIBCPP_TYPEINFO
12 #define __LIBCPP_TYPEINFO
25 bool operator==(const type_info& rhs) const noexcept;
26 bool operator!=(const type_info& rhs) const noexcept;
28 bool before(const type_info& rhs) const noexcept;
29 size_t hash_code() const noexcept;
30 const char* name() const noexcept;
32 type_info(const type_info& rhs) = delete;
33 type_info& operator=(const type_info& rhs) = delete;
41 bad_cast(const bad_cast&) noexcept;
42 bad_cast& operator=(const bad_cast&) noexcept;
43 virtual const char* what() const noexcept;
50 bad_typeid() noexcept;
51 bad_typeid(const bad_typeid&) noexcept;
52 bad_typeid& operator=(const bad_typeid&) noexcept;
53 virtual const char* what() const noexcept;
64 #ifdef _LIBCPP_NO_EXCEPTIONS
68 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
69 #pragma GCC system_header
72 #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
73 #include <vcruntime_typeinfo.h>
76 #if !defined(_LIBCPP_ABI_MICROSOFT)
77 #if defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
78 #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
80 #define _LIBCPP_HAS_UNIQUE_TYPEINFO
84 namespace std // purposefully not using versioning namespace
87 class _LIBCPP_EXCEPTION_ABI type_info
89 type_info& operator=(const type_info&);
90 type_info(const type_info&);
92 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
93 _LIBCPP_INLINE_VISIBILITY
94 int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
95 { return __builtin_strcmp(name(), __arg.name()); }
98 #if defined(_LIBCPP_ABI_MICROSOFT)
100 const char *__undecorated_name;
101 const char __decorated_name[1];
104 int __compare(const type_info &__rhs) const _NOEXCEPT;
105 #endif // _LIBCPP_ABI_MICROSOFT
108 #if !defined(_LIBCPP_ABI_MICROSOFT)
109 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
110 // A const char* with the non-unique RTTI bit possibly set.
111 uintptr_t __type_name;
113 _LIBCPP_INLINE_VISIBILITY
114 explicit type_info(const char* __n)
115 : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
117 const char *__type_name;
119 _LIBCPP_INLINE_VISIBILITY
120 explicit type_info(const char* __n) : __type_name(__n) {}
122 #endif // ! _LIBCPP_ABI_MICROSOFT
125 _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
126 virtual ~type_info();
128 #if defined(_LIBCPP_ABI_MICROSOFT)
129 const char *name() const _NOEXCEPT;
131 _LIBCPP_INLINE_VISIBILITY
132 bool before(const type_info& __arg) const _NOEXCEPT {
133 return __compare(__arg) < 0;
136 size_t hash_code() const _NOEXCEPT;
138 _LIBCPP_INLINE_VISIBILITY
139 bool operator==(const type_info& __arg) const _NOEXCEPT {
140 return __compare(__arg) == 0;
143 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
144 _LIBCPP_INLINE_VISIBILITY
145 const char* name() const _NOEXCEPT
147 return reinterpret_cast<const char*>(__type_name &
148 ~_LIBCPP_NONUNIQUE_RTTI_BIT);
151 _LIBCPP_INLINE_VISIBILITY
152 bool before(const type_info& __arg) const _NOEXCEPT
154 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
155 return __type_name < __arg.__type_name;
156 return __compare_nonunique_names(__arg) < 0;
159 _LIBCPP_INLINE_VISIBILITY
160 size_t hash_code() const _NOEXCEPT
162 if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT))
165 const char* __ptr = name();
166 size_t __hash = 5381;
167 while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
168 __hash = (__hash * 33) ^ __c;
172 _LIBCPP_INLINE_VISIBILITY
173 bool operator==(const type_info& __arg) const _NOEXCEPT
175 if (__type_name == __arg.__type_name)
178 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
180 return __compare_nonunique_names(__arg) == 0;
183 _LIBCPP_INLINE_VISIBILITY
184 const char* name() const _NOEXCEPT
185 { return __type_name; }
187 _LIBCPP_INLINE_VISIBILITY
188 bool before(const type_info& __arg) const _NOEXCEPT
189 { return __type_name < __arg.__type_name; }
191 _LIBCPP_INLINE_VISIBILITY
192 size_t hash_code() const _NOEXCEPT
193 { return reinterpret_cast<size_t>(__type_name); }
195 _LIBCPP_INLINE_VISIBILITY
196 bool operator==(const type_info& __arg) const _NOEXCEPT
197 { return __type_name == __arg.__type_name; }
199 #endif // _LIBCPP_ABI_MICROSOFT
201 _LIBCPP_INLINE_VISIBILITY
202 bool operator!=(const type_info& __arg) const _NOEXCEPT
203 { return !operator==(__arg); }
206 class _LIBCPP_EXCEPTION_ABI bad_cast
210 bad_cast() _NOEXCEPT;
211 virtual ~bad_cast() _NOEXCEPT;
212 virtual const char* what() const _NOEXCEPT;
215 class _LIBCPP_EXCEPTION_ABI bad_typeid
219 bad_typeid() _NOEXCEPT;
220 virtual ~bad_typeid() _NOEXCEPT;
221 virtual const char* what() const _NOEXCEPT;
226 #endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
228 _LIBCPP_BEGIN_NAMESPACE_STD
229 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
230 void __throw_bad_cast()
232 #ifndef _LIBCPP_NO_EXCEPTIONS
238 _LIBCPP_END_NAMESPACE_STD
240 #endif // __LIBCPP_TYPEINFO