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 namespace std // purposefully not using versioning namespace
75 class _LIBCPP_EXCEPTION_ABI type_info
77 type_info& operator=(const type_info&);
78 type_info(const type_info&);
81 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
82 const char* __type_name;
84 // A const char* with the non-unique RTTI bit possibly set.
85 uintptr_t __type_name;
88 _LIBCPP_INLINE_VISIBILITY
89 explicit type_info(const char* __n)
90 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
93 : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
99 _LIBCPP_INLINE_VISIBILITY
100 const char* name() const _NOEXCEPT
101 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
102 {return __type_name;}
104 {return reinterpret_cast<const char*>(__type_name & ~_LIBCPP_NONUNIQUE_RTTI_BIT);}
107 _LIBCPP_INLINE_VISIBILITY
108 bool before(const type_info& __arg) const _NOEXCEPT
109 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
110 {return __type_name < __arg.__type_name;}
112 {if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
113 return __type_name < __arg.__type_name;
114 return __compare_nonunique_names(__arg) < 0;}
117 _LIBCPP_INLINE_VISIBILITY
118 size_t hash_code() const _NOEXCEPT
119 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
120 {return reinterpret_cast<size_t>(__type_name);}
122 {if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) return __type_name;
123 const char *__ptr = name();
124 size_t __hash = 5381;
125 while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
126 __hash = (__hash * 33) ^ __c;
130 _LIBCPP_INLINE_VISIBILITY
131 bool operator==(const type_info& __arg) const _NOEXCEPT
132 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
133 {return __type_name == __arg.__type_name;}
135 {if (__type_name == __arg.__type_name) return true;
136 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
138 return __compare_nonunique_names(__arg) == 0;}
140 _LIBCPP_INLINE_VISIBILITY
141 bool operator!=(const type_info& __arg) const _NOEXCEPT
142 {return !operator==(__arg);}
144 #ifdef _LIBCPP_NONUNIQUE_RTTI_BIT
146 _LIBCPP_INLINE_VISIBILITY
147 int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
148 {return __builtin_strcmp(name(), __arg.name());}
152 class _LIBCPP_EXCEPTION_ABI bad_cast
156 bad_cast() _NOEXCEPT;
157 virtual ~bad_cast() _NOEXCEPT;
158 virtual const char* what() const _NOEXCEPT;
161 class _LIBCPP_EXCEPTION_ABI bad_typeid
165 bad_typeid() _NOEXCEPT;
166 virtual ~bad_typeid() _NOEXCEPT;
167 virtual const char* what() const _NOEXCEPT;
172 _LIBCPP_BEGIN_NAMESPACE_STD
173 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
174 void __throw_bad_cast()
176 #ifndef _LIBCPP_NO_EXCEPTIONS
182 _LIBCPP_END_NAMESPACE_STD
184 #endif // __LIBCPP_TYPEINFO