typeinfo

Go to the documentation of this file.
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 {
00063   class type_info 
00064   {
00065   public:
00070     virtual ~type_info();
00071 
00072   private:
00074     type_info& operator=(const type_info&);
00075     type_info(const type_info&);
00076     
00077   protected:
00078     const char *__name;
00079     
00080   protected:
00081     explicit type_info(const char *__n): __name(__n) { }
00082     
00083   public:
00084     // the public interface
00087     const char* name() const
00088     { return __name; }
00089 
00090 #if !__GXX_MERGED_TYPEINFO_NAMES
00091     bool before(const type_info& __arg) const;
00092     // In old abi, or when weak symbols are not supported, there can
00093     // be multiple instances of a type_info object for one
00094     // type. Uniqueness must use the _name value, not object address.
00095     bool operator==(const type_info& __arg) const;
00096 #else
00097 
00099     // In new abi we can rely on type_info's NTBS being unique,
00100     // and therefore address comparisons are sufficient.
00101     bool before(const type_info& __arg) const
00102     { return __name < __arg.__name; }
00103     bool operator==(const type_info& __arg) const
00104     { return __name == __arg.__name; }
00105 #endif
00106     bool operator!=(const type_info& __arg) const
00107     { return !operator==(__arg); }
00108     
00109     // the internal interface
00110   public:
00111     // return true if this is a pointer type of some kind
00112     virtual bool __is_pointer_p() const;
00113     // return true if this is a function type
00114     virtual bool __is_function_p() const;
00115 
00116     // Try and catch a thrown type. Store an adjusted pointer to the
00117     // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
00118     // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
00119     // type, then THR_OBJ is the pointer itself. OUTER indicates the
00120     // number of outer pointers, and whether they were const
00121     // qualified.
00122     virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
00123                 unsigned __outer) const;
00124 
00125     // internally used during catch matching
00126     virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
00127                  void **__obj_ptr) const;
00128   };
00129 
00135   class bad_cast : public exception 
00136   {
00137   public:
00138     bad_cast() throw() { }
00139     // This declaration is not useless:
00140     // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
00141     virtual ~bad_cast() throw();
00142   };
00143   
00145   class bad_typeid : public exception 
00146   {
00147   public:
00148     bad_typeid () throw() { }
00149     // This declaration is not useless:
00150     // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
00151     virtual ~bad_typeid() throw();
00152   };
00153 } // namespace std
00154 
00155 } // extern "C++"
00156 #endif

Generated on Tue Apr 29 20:16:24 2003 for libstdc++-v3 Source by doxygen1.3