Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:42

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef TYPE_ID_DWA2002517_HPP
0006 # define TYPE_ID_DWA2002517_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/detail/msvc_typeinfo.hpp>
0011 # include <boost/operators.hpp>
0012 # include <typeinfo>
0013 # include <cstring>
0014 # include <ostream>
0015 # include <boost/static_assert.hpp>
0016 # include <boost/detail/workaround.hpp>
0017 # include <boost/python/detail/type_traits.hpp>
0018 
0019 #  ifndef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
0020 #   if defined(__GNUC__)                                                \
0021     && !defined(__EDG_VERSION__)
0022 #    define BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
0023 #   endif
0024 #  endif
0025 
0026 namespace boost { namespace python { 
0027 
0028 // for this compiler at least, cross-shared-library type_info
0029 // comparisons don't work, so use typeid(x).name() instead. It's not
0030 // yet clear what the best default strategy is.
0031 # if defined(__GNUC__) \
0032  || defined(_AIX) \
0033  || (   defined(__sgi) && defined(__host_mips)) \
0034  || (defined(__hpux) && defined(__HP_aCC)) \
0035  || (defined(linux) && defined(__INTEL_COMPILER) && defined(__ICC))
0036 #  define BOOST_PYTHON_TYPE_ID_NAME
0037 # endif 
0038 
0039 #ifdef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
0040 // Runtime detection of broken cxxabi::__cxa_demangle versions,
0041 // to avoid #ifdef clutter.
0042 bool cxxabi_cxa_demangle_is_broken();
0043 #define BOOST_PYTHON_HAVE_CXXABI_CXA_DEMANGLE_IS_BROKEN
0044 #endif
0045 
0046 // type ids which represent the same information as std::type_info
0047 // (i.e. the top-level reference and cv-qualifiers are stripped), but
0048 // which works across shared libraries.
0049 struct type_info : private totally_ordered<type_info>
0050 {
0051     inline type_info(std::type_info const& = typeid(void));
0052     
0053     inline bool operator<(type_info const& rhs) const;
0054     inline bool operator==(type_info const& rhs) const;
0055 
0056     char const* name() const;
0057     friend BOOST_PYTHON_DECL std::ostream& operator<<(
0058         std::ostream&, type_info const&);
0059     
0060  private: // data members
0061 #  ifdef BOOST_PYTHON_TYPE_ID_NAME
0062     typedef char const* base_id_t;
0063 #  else
0064     typedef std::type_info const* base_id_t;
0065 #  endif
0066     
0067     base_id_t m_base_type;
0068 };
0069 
0070 
0071 // This macro is obsolete. Port away and remove.
0072 # define BOOST_PYTHON_EXPLICIT_TT_DEF(T)
0073 
0074 template <class T>
0075 inline type_info type_id()
0076 {
0077     return type_info(
0078 #  if !defined(_MSC_VER)                                       \
0079       || !BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 700)
0080         typeid(T)
0081 #  else // strip the decoration which Intel mistakenly leaves in
0082         python::detail::msvc_typeid((boost::type<T>*)0)
0083 #  endif 
0084         );
0085 }
0086 
0087 #  if (defined(__EDG_VERSION__) && __EDG_VERSION__ < 245) \
0088    || (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 744)
0089 // Older EDG-based compilers seems to mistakenly distinguish "int" from
0090 // "signed int", etc., but only in typeid() expressions. However
0091 // though int == signed int, the "signed" decoration is propagated
0092 // down into template instantiations. Explicit specialization stops
0093 // that from taking hold.
0094 
0095 #   define BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(T)              \
0096 template <>                                                     \
0097 inline type_info type_id<T>()                                   \
0098 {                                                               \
0099     return type_info(typeid(T));                                \
0100 }
0101 
0102 BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(short)
0103 BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(int)
0104 BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(long)
0105 // using Python's macro instead of Boost's - we don't seem to get the
0106 // config right all the time.
0107 #   ifdef HAVE_LONG_LONG
0108 BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID(long long)
0109 #   endif
0110 #   undef BOOST_PYTHON_SIGNED_INTEGRAL_TYPE_ID
0111 #  endif
0112 
0113 //
0114 inline type_info::type_info(std::type_info const& id)
0115     : m_base_type(
0116 #  ifdef BOOST_PYTHON_TYPE_ID_NAME
0117         id.name()
0118 #  else
0119         &id
0120 #  endif
0121         )
0122 {
0123 }
0124 
0125 inline bool type_info::operator<(type_info const& rhs) const
0126 {
0127 #  ifdef BOOST_PYTHON_TYPE_ID_NAME
0128     return std::strcmp(m_base_type, rhs.m_base_type) < 0;
0129 #  else
0130     return m_base_type->before(*rhs.m_base_type);
0131 #  endif 
0132 }
0133 
0134 inline bool type_info::operator==(type_info const& rhs) const
0135 {
0136 #  ifdef BOOST_PYTHON_TYPE_ID_NAME
0137     return !std::strcmp(m_base_type, rhs.m_base_type);
0138 #  else
0139     return *m_base_type == *rhs.m_base_type;
0140 #  endif 
0141 }
0142 
0143 #  ifdef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
0144 namespace detail
0145 {
0146   BOOST_PYTHON_DECL char const* gcc_demangle(char const*);
0147 }
0148 #  endif
0149     
0150 inline char const* type_info::name() const
0151 {
0152     char const* raw_name
0153         = m_base_type
0154 #  ifndef BOOST_PYTHON_TYPE_ID_NAME
0155           ->name()
0156 #  endif
0157         ;
0158     
0159 #  ifdef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
0160     return detail::gcc_demangle(raw_name);
0161 #  else
0162     return raw_name;
0163 #  endif 
0164 }
0165 
0166 
0167 BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_info const&);
0168 
0169 template<>
0170 inline type_info type_id<void>()
0171 {
0172     return type_info (typeid (void *));
0173 }
0174 #   ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
0175 template<>
0176 inline type_info type_id<const volatile void>()
0177 {
0178     return type_info (typeid (void *));
0179 }
0180 #  endif
0181 
0182 }} // namespace boost::python
0183 
0184 #endif // TYPE_ID_DWA2002517_HPP