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;
65 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
66 #pragma GCC system_header
69 namespace std // purposefully not using versioning namespace
72 class _LIBCPP_EXCEPTION_ABI type_info
74 type_info& operator=(const type_info&);
75 type_info(const type_info&);
77 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
78 const char* __type_name;
80 // A const char* with the non-unique RTTI bit possibly set.
81 uintptr_t __type_name;
84 _LIBCPP_INLINE_VISIBILITY
85 explicit type_info(const char* __n)
86 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
89 : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
95 _LIBCPP_INLINE_VISIBILITY
96 const char* name() const _NOEXCEPT
97 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
100 {return reinterpret_cast<const char*>(__type_name & ~_LIBCPP_NONUNIQUE_RTTI_BIT);}
103 _LIBCPP_INLINE_VISIBILITY
104 bool before(const type_info& __arg) const _NOEXCEPT
105 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
106 {return __type_name < __arg.__type_name;}
108 {if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
109 return __type_name < __arg.__type_name;
110 return __compare_nonunique_names(__arg) < 0;}
113 _LIBCPP_INLINE_VISIBILITY
114 size_t hash_code() const _NOEXCEPT
115 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
116 {return *reinterpret_cast<const size_t*>(&__type_name);}
118 {if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) return __type_name;
119 const char *__ptr = name();
120 size_t __hash = 5381;
121 while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
122 __hash = (__hash * 33) ^ __c;
126 _LIBCPP_INLINE_VISIBILITY
127 bool operator==(const type_info& __arg) const _NOEXCEPT
128 #ifndef _LIBCPP_NONUNIQUE_RTTI_BIT
129 {return __type_name == __arg.__type_name;}
131 {if (__type_name == __arg.__type_name) return true;
132 if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
134 return __compare_nonunique_names(__arg) == 0;}
136 _LIBCPP_INLINE_VISIBILITY
137 bool operator!=(const type_info& __arg) const _NOEXCEPT
138 {return !operator==(__arg);}
140 #ifdef _LIBCPP_NONUNIQUE_RTTI_BIT
142 _LIBCPP_INLINE_VISIBILITY
143 int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
144 {return __builtin_strcmp(name(), __arg.name());}
148 class _LIBCPP_EXCEPTION_ABI bad_cast
152 bad_cast() _NOEXCEPT;
153 virtual ~bad_cast() _NOEXCEPT;
154 virtual const char* what() const _NOEXCEPT;
157 class _LIBCPP_EXCEPTION_ABI bad_typeid
161 bad_typeid() _NOEXCEPT;
162 virtual ~bad_typeid() _NOEXCEPT;
163 virtual const char* what() const _NOEXCEPT;
168 #endif // __LIBCPP_TYPEINFO