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_NONUNIQUE_RTTI_BIT)
73 #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
75 #define _LIBCPP_HAS_UNIQUE_TYPEINFO
78 namespace std // purposefully not using versioning namespace
81 class _LIBCPP_EXCEPTION_ABI type_info
83 type_info& operator=(const type_info&);
84 type_info(const type_info&);
86 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
87 _LIBCPP_INLINE_VISIBILITY
88 int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
89 { return __builtin_strcmp(name(), __arg.name()); }
93 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
94 // A const char* with the non-unique RTTI bit possibly set.
95 uintptr_t __type_name;
97 _LIBCPP_INLINE_VISIBILITY
98 explicit type_info(const char* __n)
99 : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
101 const char *__type_name;
103 _LIBCPP_INLINE_VISIBILITY
104 explicit type_info(const char* __n) : __type_name(__n) {}
108 virtual ~type_info();
110 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
111 _LIBCPP_INLINE_VISIBILITY
112 const char* name() const _NOEXCEPT
114 return reinterpret_cast<const char*>(__type_name &
115 ~_LIBCPP_NONUNIQUE_RTTI_BIT);
118 _LIBCPP_INLINE_VISIBILITY
119 bool before(const type_info& __arg) const _NOEXCEPT
121 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
122 return __type_name < __arg.__type_name;
123 return __compare_nonunique_names(__arg) < 0;
126 _LIBCPP_INLINE_VISIBILITY
127 size_t hash_code() const _NOEXCEPT
129 if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT))
132 const char* __ptr = name();
133 size_t __hash = 5381;
134 while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
135 __hash = (__hash * 33) ^ __c;
139 _LIBCPP_INLINE_VISIBILITY
140 bool operator==(const type_info& __arg) const _NOEXCEPT
142 if (__type_name == __arg.__type_name)
145 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
147 return __compare_nonunique_names(__arg) == 0;
150 _LIBCPP_INLINE_VISIBILITY
151 const char* name() const _NOEXCEPT
152 { return __type_name; }
154 _LIBCPP_INLINE_VISIBILITY
155 bool before(const type_info& __arg) const _NOEXCEPT
156 { return __type_name < __arg.__type_name; }
158 _LIBCPP_INLINE_VISIBILITY
159 size_t hash_code() const _NOEXCEPT
160 { return reinterpret_cast<size_t>(__type_name); }
162 _LIBCPP_INLINE_VISIBILITY
163 bool operator==(const type_info& __arg) const _NOEXCEPT
164 { return __type_name == __arg.__type_name; }
167 _LIBCPP_INLINE_VISIBILITY
168 bool operator!=(const type_info& __arg) const _NOEXCEPT
169 { return !operator==(__arg); }
172 class _LIBCPP_EXCEPTION_ABI bad_cast
176 bad_cast() _NOEXCEPT;
177 virtual ~bad_cast() _NOEXCEPT;
178 virtual const char* what() const _NOEXCEPT;
181 class _LIBCPP_EXCEPTION_ABI bad_typeid
185 bad_typeid() _NOEXCEPT;
186 virtual ~bad_typeid() _NOEXCEPT;
187 virtual const char* what() const _NOEXCEPT;
192 _LIBCPP_BEGIN_NAMESPACE_STD
193 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
194 void __throw_bad_cast()
196 #ifndef _LIBCPP_NO_EXCEPTIONS
202 _LIBCPP_END_NAMESPACE_STD
204 #endif // __LIBCPP_TYPEINFO