OSDN Git Service

2001-03-13 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.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 #ifndef __TYPEINFO__
31 #define __TYPEINFO__
32
33 #include <exception>
34
35 extern "C++" {
36
37 namespace __cxxabiv1
38 {
39   class __class_type_info;
40 } // namespace __cxxabiv1
41
42 #if !__GXX_WEAK__
43   // If weak symbols are not supported, typeinfo names are not merged.
44   #define __GXX_MERGED_TYPEINFO_NAMES 0
45 #else
46   // On platforms that support weak symbols, typeinfo names are merged.
47   #define __GXX_MERGED_TYPEINFO_NAMES 1
48 #endif
49
50 namespace std 
51 {
52   class type_info 
53   {
54   public:
55     // Destructor. Being the first non-inline virtual function, this
56     // controls in which translation unit the vtable is emitted. The
57     // compiler makes use of that information to know where to emit
58     // the runtime-mandated type_info structures in the new-abi.
59     virtual ~type_info();
60
61   private:
62     // Assigning type_info is not supported.  made private.
63     type_info& operator=(const type_info&);
64     type_info(const type_info&);
65     
66   protected:
67     const char *__name;
68     
69   protected:
70     explicit type_info(const char *__n): __name(__n) { }
71     
72   public:
73     // the public interface
74     const char* name() const
75     { return __name; }
76
77 #if !__GXX_MERGED_TYPEINFO_NAMES
78     bool before(const type_info& arg) const;
79     // In old abi, or when weak symbols are not supported, there can
80     // be multiple instances of a type_info object for one
81     // type. Uniqueness must use the _name value, not object address.
82     bool operator==(const type_info& __arg) const;
83 #else
84     // In new abi we can rely on type_info's NTBS being unique,
85     // and therefore address comparisons are sufficient.
86     bool before(const type_info& __arg) const
87     { return __name < __arg.__name; }
88     bool operator==(const type_info& __arg) const
89     { return __name == __arg.__name; }
90 #endif
91     bool operator!=(const type_info& __arg) const
92     { return !operator==(__arg); }
93     
94     // the internal interface
95   public:
96     // return true if this is a pointer type of some kind
97     virtual bool __is_pointer_p() const;
98     // return true if this is a function type
99     virtual bool __is_function_p() const;
100
101     // Try and catch a thrown type. Store an adjusted pointer to the
102     // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
103     // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
104     // type, then THR_OBJ is the pointer itself. OUTER indicates the
105     // number of outer pointers, and whether they were const
106     // qualified.
107     virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
108                             unsigned __outer) const;
109
110     // internally used during catch matching
111     virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
112                              void **__obj_ptr) const;
113   };
114
115   class bad_cast : public exception 
116   {
117   public:
118     bad_cast() throw() { }
119     virtual ~bad_cast() throw();
120   };
121   
122   class bad_typeid : public exception 
123   {
124   public:
125     bad_typeid () throw() { }
126     virtual ~bad_typeid () throw();
127   };
128 } // namespace std
129
130 } // extern "C++"
131 #endif