STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vcruntime_typeinfo.h
Go to the documentation of this file.
1 //
2 // vcruntime_typeinfo.h
3 //
4 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // <typeinfo> functionality that is implemented in the VCRuntime.
7 //
8 #pragma once
9 
10 #include <vcruntime.h>
11 #include <vcruntime_exception.h>
12 
13 #pragma pack(push, _CRT_PACKING)
14 #ifndef RC_INVOKED
15 
16 #if defined _M_CEE_MIXED && !defined _VCRT_BUILD
17  // Provide a fake definition of __type_info_node to suppress linker warning
18  // LNK4248: unresolved typeref token for '__type_info_node'; image may not run.
19  struct __type_info_node { };
20 #else
21  struct __type_info_node;
22 #endif
23 
24 #ifdef _M_CEE_PURE
25  extern System::IntPtr __type_info_root_node;
26 #else
27  extern __type_info_node __type_info_root_node;
28 #endif
29 
30 
31 
33 
34 
35 #pragma warning(push)
36 #pragma warning(disable: 4510 4512 4610) // This type can never be instantiated
38 {
39  char const* _UndecoratedName;
40  char const _DecoratedName[1];
41 };
42 #pragma warning(pop)
43 
45  _In_ __std_type_info_data const* _Lhs,
46  _In_ __std_type_info_data const* _Rhs
47  );
48 
49 _VCRTIMP size_t __cdecl __std_type_info_hash(
50  _In_ __std_type_info_data const* _Data
51  );
52 
53 _VCRTIMP char const* __cdecl __std_type_info_name(
55  _Inout_ __type_info_node* _RootNode
56  );
57 
59 
60 
61 
62 class type_info
63 {
64 public:
65 
66  type_info(type_info const&) = delete;
67  type_info& operator=(type_info const&) = delete;
68 
69  size_t hash_code() const throw()
70  {
71  return __std_type_info_hash(&_Data);
72  }
73 
74  bool operator==(type_info const& _Other) const throw()
75  {
76  return __std_type_info_compare(&_Data, &_Other._Data) == 0;
77  }
78 
79  bool operator!=(type_info const& _Other) const throw()
80  {
81  return __std_type_info_compare(&_Data, &_Other._Data) != 0;
82  }
83 
84  bool before(type_info const& _Other) const throw()
85  {
86  return __std_type_info_compare(&_Data, &_Other._Data) < 0;
87  }
88 
89  char const* name() const throw()
90  {
91  #ifdef _M_CEE_PURE
92  return __std_type_info_name(&_Data, static_cast<__type_info_node*>(__type_info_root_node.ToPointer()));
93  #else
94  return __std_type_info_name(&_Data, &__type_info_root_node);
95  #endif
96  }
97 
98  char const* raw_name() const throw()
99  {
100  return _Data._DecoratedName;
101  }
102 
103  virtual ~type_info() throw();
104 
105 private:
106 
108 };
109 
110 namespace std {
111  using ::type_info;
112 }
113 
114 #if _HAS_EXCEPTIONS
115 
116 namespace std {
117 
118 class bad_cast
119  : public exception
120 {
121 public:
122 
123  bad_cast() throw()
124  : exception("bad cast", 1)
125  {
126  }
127 
128  static bad_cast __construct_from_string_literal(char const* const _Message) throw()
129  {
130  return bad_cast(_Message, 1);
131  }
132 
133 private:
134 
135  bad_cast(char const* const _Message, int) throw()
136  : exception(_Message, 1)
137  {
138  }
139 };
140 
141 class bad_typeid
142  : public exception
143 {
144 public:
145 
146  bad_typeid() throw()
147  : exception("bad typeid", 1)
148  {
149  }
150 
151  static bad_typeid __construct_from_string_literal(char const* const _Message) throw()
152  {
153  return bad_typeid(_Message, 1);
154  }
155 
156 private:
157 
158  friend class __non_rtti_object;
159 
160  bad_typeid(char const* const _Message, int) throw()
161  : exception(_Message, 1)
162  {
163  }
164 };
165 
167  : public bad_typeid
168 {
169 public:
170 
171  static __non_rtti_object __construct_from_string_literal(char const* const _Message) throw()
172  {
173  return __non_rtti_object(_Message, 1);
174  }
175 
176 private:
177 
178  __non_rtti_object(char const* const _Message, int) throw()
179  : bad_typeid(_Message, 1)
180  {
181  }
182 };
183 
184 } // namespace std
185 
186 #endif // _HAS_EXCEPTIONS
187 #endif // !RC_INVOKED
188 #pragma pack(pop)
size_t hash_code() const
Definition: vcruntime_typeinfo.h:69
#define _VCRTIMP
Definition: vcruntime.h:115
Definition: vcruntime_typeinfo.h:37
char const * raw_name() const
Definition: vcruntime_typeinfo.h:98
char const * _UndecoratedName
Definition: vcruntime_typeinfo.h:39
Definition: typeinfo:36
char const * name() const
Definition: vcruntime_typeinfo.h:89
STL namespace.
_VCRTIMP int __cdecl __std_type_info_compare(_In_ __std_type_info_data const *_Lhs, _In_ __std_type_info_data const *_Rhs)
#define _CRT_BEGIN_C_HEADER
Definition: vcruntime.h:73
_VCRTIMP char const *__cdecl __std_type_info_name(_Inout_ __std_type_info_data *_Data, _Inout_ __type_info_node *_RootNode)
#define _In_
Definition: sal.h:305
bool operator==(type_info const &_Other) const
Definition: vcruntime_typeinfo.h:74
__std_type_info_data _Data
Definition: vcruntime_typeinfo.h:107
bool operator!=(type_info const &_Other) const
Definition: vcruntime_typeinfo.h:79
Definition: typeinfo:57
virtual ~type_info()
char const _DecoratedName[1]
Definition: vcruntime_typeinfo.h:40
Definition: typeinfo:77
bad_typeid(const char *_Message="bad typeid") _THROW0()
Definition: typeinfo:61
type_info(type_info const &)=delete
#define _CRT_END_C_HEADER
Definition: vcruntime.h:76
type_info & operator=(type_info const &)=delete
bool before(type_info const &_Other) const
Definition: vcruntime_typeinfo.h:84
Definition: exception:80
static __non_rtti_object __construct_from_string_literal(char const *const _Message)
Definition: vcruntime_typeinfo.h:171
#define _Inout_
Definition: sal.h:375
Definition: vcruntime_typeinfo.h:166
_VCRTIMP size_t __cdecl __std_type_info_hash(_In_ __std_type_info_data const *_Data)
__type_info_node __type_info_root_node
__non_rtti_object(char const *const _Message, int)
Definition: vcruntime_typeinfo.h:178
Definition: vcruntime_typeinfo.h:62