typeinfo 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright 2010-2011 PathScale, Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. *
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
  15. * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  21. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  23. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef _LINUX_TYPEINFO_
  27. #define _LINUX_TYPEINFO_
  28. #include <stddef.h>
  29. #include "exception"
  30. namespace __cxxabiv1
  31. {
  32. struct __class_type_info;
  33. }
  34. namespace std
  35. {
  36. /**
  37. * Standard type info class. The layout of this class is specified by the
  38. * ABI. The layout of the vtable is not, but is intended to be
  39. * compatible with the GNU ABI.
  40. *
  41. * Unlike the GNU version, the vtable layout is considered semi-private.
  42. */
  43. class type_info
  44. {
  45. public:
  46. /**
  47. * Virtual destructor. This class must have one virtual function to
  48. * ensure that it has a vtable.
  49. */
  50. virtual ~type_info();
  51. bool operator==(const type_info &) const;
  52. bool operator!=(const type_info &) const;
  53. bool before(const type_info &) const;
  54. const char* name() const;
  55. type_info();
  56. private:
  57. type_info(const type_info& rhs);
  58. type_info& operator= (const type_info& rhs);
  59. const char *__type_name;
  60. /*
  61. * The following functions are in this order to match the
  62. * vtable layout of libsupc++. This allows libcxxrt to be used
  63. * with libraries that depend on this.
  64. *
  65. * These functions are in the public headers for libstdc++, so
  66. * we have to assume that someone will probably call them and
  67. * expect them to work. Their names must also match the names used in
  68. * libsupc++, so that code linking against this library can subclass
  69. * type_info and correctly fill in the values in the vtables.
  70. */
  71. public:
  72. /**
  73. * Returns true if this is some pointer type, false otherwise.
  74. */
  75. virtual bool __is_pointer_p() const { return false; }
  76. /**
  77. * Returns true if this is some function type, false otherwise.
  78. */
  79. virtual bool __is_function_p() const { return false; }
  80. /**
  81. * Catch function. Allows external libraries to implement
  82. * their own basic types. This is used, for example, in the
  83. * GNUstep Objective-C runtime to allow Objective-C types to be
  84. * caught in G++ catch blocks.
  85. *
  86. * The outer parameter indicates the number of outer pointers
  87. * in the high bits. The low bit indicates whether the
  88. * pointers are const qualified.
  89. */
  90. virtual bool __do_catch(const type_info *thrown_type,
  91. void **thrown_object,
  92. unsigned outer) const;
  93. /**
  94. * Performs an upcast. This is used in exception handling to
  95. * cast from subclasses to superclasses. If the upcast is
  96. * possible, it returns true and adjusts the pointer. If the
  97. * upcast is not possible, it returns false and does not adjust
  98. * the pointer.
  99. */
  100. virtual bool __do_upcast(
  101. const __cxxabiv1::__class_type_info *target,
  102. void **thrown_object) const
  103. {
  104. (void)target, (void)thrown_object;
  105. return false;
  106. }
  107. };
  108. /**
  109. * Bad cast exception. Thrown by the __cxa_bad_cast() helper function.
  110. */
  111. class bad_cast: public exception {
  112. public:
  113. bad_cast() throw();
  114. bad_cast(const bad_cast&) throw();
  115. bad_cast& operator=(const bad_cast&) throw();
  116. virtual ~bad_cast();
  117. virtual const char* what() const throw();
  118. };
  119. /**
  120. * Bad typeidexception. Thrown by the __cxa_bad_typeid() helper function.
  121. */
  122. class bad_typeid: public exception
  123. {
  124. public:
  125. bad_typeid() throw();
  126. bad_typeid(const bad_typeid &__rhs) throw();
  127. virtual ~bad_typeid();
  128. bad_typeid& operator=(const bad_typeid &__rhs) throw();
  129. virtual const char* what() const throw();
  130. };
  131. class bad_array_new_length: public bad_alloc
  132. {
  133. public:
  134. bad_array_new_length() throw();
  135. bad_array_new_length(const bad_array_new_length&) throw();
  136. bad_array_new_length& operator=(const bad_array_new_length&) throw();
  137. virtual ~bad_array_new_length();
  138. virtual const char *what() const throw();
  139. };
  140. }
  141. #endif /* _LINUX_TYPEINFO_ */