00001 // RTTI support for -*- C++ -*- 00002 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002 00003 // Free Software Foundation 00004 // 00005 // This file is part of GNU CC. 00006 // 00007 // GNU CC is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 // 00012 // GNU CC is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GNU CC; see the file COPYING. If not, write to 00019 // the Free Software Foundation, 59 Temple Place - Suite 330, 00020 // Boston, MA 02111-1307, USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00035 #ifndef __TYPEINFO__ 00036 #define __TYPEINFO__ 00037 00038 #include <exception> 00039 00040 extern "C++" { 00041 00042 namespace __cxxabiv1 00043 { 00044 class __class_type_info; 00045 } // namespace __cxxabiv1 00046 00047 #if !__GXX_WEAK__ 00048 // If weak symbols are not supported, typeinfo names are not merged. 00049 #define __GXX_MERGED_TYPEINFO_NAMES 0 00050 #else 00051 // On platforms that support weak symbols, typeinfo names are merged. 00052 #define __GXX_MERGED_TYPEINFO_NAMES 1 00053 #endif 00054 00055 namespace std 00056 { 00060 class type_info 00061 { 00062 public: 00067 virtual ~type_info(); 00068 00069 private: 00071 type_info& operator=(const type_info&); 00072 type_info(const type_info&); 00073 00074 protected: 00075 const char *__name; 00076 00077 protected: 00078 explicit type_info(const char *__n): __name(__n) { } 00079 00080 public: 00081 // the public interface 00084 const char* name() const 00085 { return __name; } 00086 00087 #if !__GXX_MERGED_TYPEINFO_NAMES 00088 bool before(const type_info& __arg) const; 00089 // In old abi, or when weak symbols are not supported, there can 00090 // be multiple instances of a type_info object for one 00091 // type. Uniqueness must use the _name value, not object address. 00092 bool operator==(const type_info& __arg) const; 00093 #else 00094 00096 // In new abi we can rely on type_info's NTBS being unique, 00097 // and therefore address comparisons are sufficient. 00098 bool before(const type_info& __arg) const 00099 { return __name < __arg.__name; } 00100 bool operator==(const type_info& __arg) const 00101 { return __name == __arg.__name; } 00102 #endif 00103 bool operator!=(const type_info& __arg) const 00104 { return !operator==(__arg); } 00105 00106 // the internal interface 00107 public: 00108 // return true if this is a pointer type of some kind 00109 virtual bool __is_pointer_p() const; 00110 // return true if this is a function type 00111 virtual bool __is_function_p() const; 00112 00113 // Try and catch a thrown type. Store an adjusted pointer to the 00114 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then 00115 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer 00116 // type, then THR_OBJ is the pointer itself. OUTER indicates the 00117 // number of outer pointers, and whether they were const 00118 // qualified. 00119 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, 00120 unsigned __outer) const; 00121 00122 // internally used during catch matching 00123 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target, 00124 void **__obj_ptr) const; 00125 }; 00126 00129 class bad_cast : public exception 00130 { 00131 public: 00132 bad_cast() throw() { } 00133 // This declaration is not useless: 00134 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00135 virtual ~bad_cast() throw(); 00136 }; 00137 00139 class bad_typeid : public exception 00140 { 00141 public: 00142 bad_typeid () throw() { } 00143 // This declaration is not useless: 00144 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00145 virtual ~bad_typeid() throw(); 00146 }; 00147 } // namespace std 00148 00149 } // extern "C++" 00150 #endif