# typeinfo

Go to the documentation of this file.

    00001 // RTTI support for -*- C++ -*-
    00002 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
    00003 // 2003, 2004, 2005, 2006, 2007
    00004 // Free Software Foundation
    00005 //
    00006 // This file is part of GCC.
    00007 //
    00008 // GCC is free software; you can redistribute it and/or modify
    00009 // it under the terms of the GNU General Public License as published by
    00010 // the Free Software Foundation; either version 2, or (at your option)
    00011 // any later version.
    00012 //
    00013 // GCC is distributed in the hope that it will be useful,
    00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00016 // GNU General Public License for more details.
    00017 //
    00018 // You should have received a copy of the GNU General Public License
    00019 // along with GCC; see the file COPYING.  If not, write to
    00020 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
    00021 // Boston, MA 02110-1301, USA.
    00022
    00023 // As a special exception, you may use this file as part of a free software
    00024 // library without restriction.  Specifically, if other files instantiate
    00025 // templates or use macros or inline functions from this file, or you compile
    00026 // this file and link it with other files to produce an executable, this
    00027 // file does not by itself cause the resulting executable to be covered by
    00028 // the GNU General Public License.  This exception does not however
    00029 // invalidate any other reasons why the executable file might be covered by
    00030 // the GNU General Public License.
    00031
    00032 /** @file typeinfo
    00033  *  This is a Standard C++ Library header.
    00034  */
    00035
    00036 #ifndef _TYPEINFO
    00037 #define _TYPEINFO
    00038
    00039 #include <exception>
    00040
    00041 #pragma GCC visibility push(default)
    00042
    00043 extern "C++" {
    00044
    00045 namespace __cxxabiv1
    00046 {
    00047   class __class_type_info;
    00048 } // namespace __cxxabiv1
    00049
    00050 #ifndef __GXX_MERGED_TYPEINFO_NAMES
    00051   #if !__GXX_WEAK__
    00052     // If weak symbols are not supported, typeinfo names are not merged.
    00053     #define __GXX_MERGED_TYPEINFO_NAMES 0
    00054   #else
    00055     // On platforms that support weak symbols, typeinfo names are merged.
    00056     #define __GXX_MERGED_TYPEINFO_NAMES 1
    00057   #endif
    00058 #endif
    00059
    00060 namespace std
    00061 {
    00062   /**
    00063    *  @brief  Part of RTTI.
    00064    *
    00065    *  The @c type_info class describes type information generated by
    00066    *  an implementation.
    00067   */
    00068   class type_info
    00069   {
    00070   public:
    00071     /** Destructor first. Being the first non-inline virtual function, this
    00072      *  controls in which translation unit the vtable is emitted. The
    00073      *  compiler makes use of that information to know where to emit
    00074      *  the runtime-mandated type_info structures in the new-abi.  */
    00075     virtual ~type_info();
    00076
    00077     /** Returns an @e implementation-defined byte string; this is not
    00078      *  portable between compilers!  */
    00079     const char* name() const
    00080     { return __name; }
    00081
    00082 #if !__GXX_MERGED_TYPEINFO_NAMES
    00083     bool before(const type_info& __arg) const;
    00084
    00085     // In old abi, or when weak symbols are not supported, there can
    00086     // be multiple instances of a type_info object for one
    00087     // type. Uniqueness must use the _name value, not object address.
    00088     bool operator==(const type_info& __arg) const;
    00089 #else
    00090     /** Returns true if @c *this precedes @c __arg in the implementation's
    00091      *  collation order.  */
    00092     // In new abi we can rely on type_info's NTBS being unique,
    00093     // and therefore address comparisons are sufficient.
    00094     bool before(const type_info& __arg) const
    00095     { return __name < __arg.__name; }
    00096
    00097     bool operator==(const type_info& __arg) const
    00098     { return __name == __arg.__name; }
    00099 #endif
    00100     bool operator!=(const type_info& __arg) const
    00101     { return !operator==(__arg); }
    00102
    00103     // Return true if this is a pointer type of some kind
    00104     virtual bool __is_pointer_p() const;
    00105
    00106     // Return true if this is a function type
    00107     virtual bool __is_function_p() const;
    00108
    00109     // Try and catch a thrown type. Store an adjusted pointer to the
    00110     // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
    00111     // THR_OBJ points to the thrown object. If THR_TYPE is a pointer
    00112     // type, then THR_OBJ is the pointer itself. OUTER indicates the
    00113     // number of outer pointers, and whether they were const
    00114     // qualified.
    00115     virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
    00116                 unsigned __outer) const;
    00117
    00118     // Internally used during catch matching
    00119     virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
    00120                  void **__obj_ptr) const;
    00121
    00122   protected:
    00123     const char *__name;
    00124
    00125     explicit type_info(const char *__n): __name(__n) { }
    00126
    00127   private:
    00128     /// Assigning type_info is not supported.
    00129     type_info& operator=(const type_info&);
    00130     type_info(const type_info&);
    00131   };
    00132
    00133   /**
    00134    *  @brief  Thrown during incorrect typecasting.
    00135    *
    00136    *  If you attempt an invalid @c dynamic_cast expression, an instance of
    00137    *  this class (or something derived from this class) is thrown.  */
    00138   class bad_cast : public exception
    00139   {
    00140   public:
    00141     bad_cast() throw() { }
    00142
    00143     // This declaration is not useless:
    00144     // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
    00145     virtual ~bad_cast() throw();
    00146
    00147     // See comment in eh_exception.cc.
    00148     virtual const char* what() const throw();
    00149   };
    00150
    00151   /** If you use a NULL pointer in a @c typeid expression, this is thrown.  */
    00152   class bad_typeid : public exception
    00153   {
    00154   public:
    00155     bad_typeid () throw() { }
    00156
    00157     // This declaration is not useless:
    00158     // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
    00159     virtual ~bad_typeid() throw();
    00160
    00161     // See comment in eh_exception.cc.
    00162     virtual const char* what() const throw();
    00163   };
    00164 } // namespace std
    00165
    00166 #pragma GCC visibility pop
    00167
    00168 } // extern "C++"
    00169 #endif