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_NONUNIQUE_RTTI_BIT) && !defined(_LIBCPP_ABI_MICROSOFT)
77 # define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
80 namespace std // purposefully not using versioning namespace
83 class _LIBCPP_EXCEPTION_ABI type_info
85 type_info& operator=(const type_info&);
86 type_info(const type_info&);
88 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
89 _LIBCPP_INLINE_VISIBILITY
90 int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
91 { return __builtin_strcmp(name(), __arg.name()); }
94 #if defined(_LIBCPP_ABI_MICROSOFT)
96 const char *__undecorated_name;
97 const char __decorated_name[1];
100 int __compare(const type_info &__rhs) const _NOEXCEPT;
101 #endif // _LIBCPP_ABI_MICROSOFT
104 #if !defined(_LIBCPP_ABI_MICROSOFT)
105 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
106 // A const char* with the non-unique RTTI bit possibly set.
107 uintptr_t __type_name;
109 _LIBCPP_INLINE_VISIBILITY
110 explicit type_info(const char* __n)
111 : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
113 const char *__type_name;
115 _LIBCPP_INLINE_VISIBILITY
116 explicit type_info(const char* __n) : __type_name(__n) {}
118 #endif // ! _LIBCPP_ABI_MICROSOFT
121 _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
122 virtual ~type_info();
124 #if defined(_LIBCPP_ABI_MICROSOFT)
125 const char *name() const _NOEXCEPT;
127 _LIBCPP_INLINE_VISIBILITY
128 bool before(const type_info& __arg) const _NOEXCEPT {
129 return __compare(__arg) < 0;
132 size_t hash_code() const _NOEXCEPT;
134 _LIBCPP_INLINE_VISIBILITY
135 bool operator==(const type_info& __arg) const _NOEXCEPT {
136 return __compare(__arg) == 0;
139 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
140 _LIBCPP_INLINE_VISIBILITY
141 const char* name() const _NOEXCEPT
143 return reinterpret_cast<const char*>(__type_name &
144 ~_LIBCPP_NONUNIQUE_RTTI_BIT);
147 _LIBCPP_INLINE_VISIBILITY
148 bool before(const type_info& __arg) const _NOEXCEPT
150 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
151 return __type_name < __arg.__type_name;
152 return __compare_nonunique_names(__arg) < 0;
155 _LIBCPP_INLINE_VISIBILITY
156 size_t hash_code() const _NOEXCEPT
158 if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT))
161 const char* __ptr = name();
162 size_t __hash = 5381;
163 while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
164 __hash = (__hash * 33) ^ __c;
168 _LIBCPP_INLINE_VISIBILITY
169 bool operator==(const type_info& __arg) const _NOEXCEPT
171 if (__type_name == __arg.__type_name)
174 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
176 return __compare_nonunique_names(__arg) == 0;
179 _LIBCPP_INLINE_VISIBILITY
180 const char* name() const _NOEXCEPT
181 { return __type_name; }
183 _LIBCPP_INLINE_VISIBILITY
184 bool before(const type_info& __arg) const _NOEXCEPT
185 { return __type_name < __arg.__type_name; }
187 _LIBCPP_INLINE_VISIBILITY
188 size_t hash_code() const _NOEXCEPT
189 { return reinterpret_cast<size_t>(__type_name); }
191 _LIBCPP_INLINE_VISIBILITY
192 bool operator==(const type_info& __arg) const _NOEXCEPT
193 { return __type_name == __arg.__type_name; }
195 #endif // _LIBCPP_ABI_MICROSOFT
197 _LIBCPP_INLINE_VISIBILITY
198 bool operator!=(const type_info& __arg) const _NOEXCEPT
199 { return !operator==(__arg); }
202 class _LIBCPP_EXCEPTION_ABI bad_cast
206 bad_cast() _NOEXCEPT;
207 virtual ~bad_cast() _NOEXCEPT;
208 virtual const char* what() const _NOEXCEPT;
211 class _LIBCPP_EXCEPTION_ABI bad_typeid
215 bad_typeid() _NOEXCEPT;
216 virtual ~bad_typeid() _NOEXCEPT;
217 virtual const char* what() const _NOEXCEPT;
222 #endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
224 _LIBCPP_BEGIN_NAMESPACE_STD
225 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
226 void __throw_bad_cast()
228 #ifndef _LIBCPP_NO_EXCEPTIONS
234 _LIBCPP_END_NAMESPACE_STD
236 #endif // __LIBCPP_TYPEINFO