]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/libsupc++/typeinfo
howto.html: Add anchor name.
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / typeinfo
1 // RTTI support for -*- C++ -*-
2 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001 Free Software Foundation
3 //
4 // This file is part of GNU CC.
5 //
6 // GNU CC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10 //
11 // GNU CC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with GNU CC; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file typeinfo
31 * This header provides RTTI support.
32 */
33
34 #ifndef __TYPEINFO__
35 #define __TYPEINFO__
36
37 #include <exception>
38
39 extern "C++" {
40
41 namespace __cxxabiv1
42 {
43 class __class_type_info;
44 } // namespace __cxxabiv1
45
46 #if !__GXX_WEAK__
47 // If weak symbols are not supported, typeinfo names are not merged.
48 #define __GXX_MERGED_TYPEINFO_NAMES 0
49 #else
50 // On platforms that support weak symbols, typeinfo names are merged.
51 #define __GXX_MERGED_TYPEINFO_NAMES 1
52 #endif
53
54 namespace std
55 {
56 /** The @c type_info class describes type information generated by
57 * an implementation.
58 * @brief Used in RTTI. */
59 class type_info
60 {
61 public:
62 /** Destructor. Being the first non-inline virtual function, this
63 * controls in which translation unit the vtable is emitted. The
64 * compiler makes use of that information to know where to emit
65 * the runtime-mandated type_info structures in the new-abi. */
66 virtual ~type_info();
67
68 private:
69 /// Assigning type_info is not supported. Made private.
70 type_info& operator=(const type_info&);
71 type_info(const type_info&);
72
73 protected:
74 const char *__name;
75
76 protected:
77 explicit type_info(const char *__n): __name(__n) { }
78
79 public:
80 // the public interface
81 /** Returns an @e implementation-defined byte string; this is not
82 * portable between compilers! */
83 const char* name() const
84 { return __name; }
85
86 #if !__GXX_MERGED_TYPEINFO_NAMES
87 bool before(const type_info& arg) const;
88 // In old abi, or when weak symbols are not supported, there can
89 // be multiple instances of a type_info object for one
90 // type. Uniqueness must use the _name value, not object address.
91 bool operator==(const type_info& __arg) const;
92 #else
93 /** Returns true if @c *this preceeds @c __arg in the implementation's
94 * collation order. */
95 // In new abi we can rely on type_info's NTBS being unique,
96 // and therefore address comparisons are sufficient.
97 bool before(const type_info& __arg) const
98 { return __name < __arg.__name; }
99 bool operator==(const type_info& __arg) const
100 { return __name == __arg.__name; }
101 #endif
102 bool operator!=(const type_info& __arg) const
103 { return !operator==(__arg); }
104
105 // the internal interface
106 public:
107 // return true if this is a pointer type of some kind
108 virtual bool __is_pointer_p() const;
109 // return true if this is a function type
110 virtual bool __is_function_p() const;
111
112 // Try and catch a thrown type. Store an adjusted pointer to the
113 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
114 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
115 // type, then THR_OBJ is the pointer itself. OUTER indicates the
116 // number of outer pointers, and whether they were const
117 // qualified.
118 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
119 unsigned __outer) const;
120
121 // internally used during catch matching
122 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
123 void **__obj_ptr) const;
124 };
125
126 /** If you attempt an invalid @c dynamic_cast expression, an instance of
127 * this class (or something derived from this class) is thrown. */
128 class bad_cast : public exception
129 {
130 public:
131 bad_cast() throw() { }
132 virtual ~bad_cast() throw();
133 };
134
135 /** If you use a NULL pointer in a @c typeid expression, this is thrown. */
136 class bad_typeid : public exception
137 {
138 public:
139 bad_typeid () throw() { }
140 virtual ~bad_typeid () throw();
141 };
142 } // namespace std
143
144 } // extern "C++"
145 #endif