registered.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef REGISTERED_DWA2002710_HPP
  6. # define REGISTERED_DWA2002710_HPP
  7. # include <boost/python/type_id.hpp>
  8. # include <boost/python/converter/registry.hpp>
  9. # include <boost/python/converter/registrations.hpp>
  10. # include <boost/type_traits/transform_traits.hpp>
  11. # include <boost/type_traits/cv_traits.hpp>
  12. # include <boost/type_traits/is_void.hpp>
  13. # include <boost/detail/workaround.hpp>
  14. # include <boost/python/type_id.hpp>
  15. # include <boost/type.hpp>
  16. namespace boost {
  17. // You'll see shared_ptr mentioned in this header because we need to
  18. // note which types are shared_ptrs in their registrations, to
  19. // implement special shared_ptr handling for rvalue conversions.
  20. template <class T> class shared_ptr;
  21. namespace python { namespace converter {
  22. struct registration;
  23. namespace detail
  24. {
  25. template <class T>
  26. struct registered_base
  27. {
  28. static registration const& converters;
  29. };
  30. }
  31. template <class T>
  32. struct registered
  33. : detail::registered_base<
  34. typename add_reference<
  35. typename add_cv<T>::type
  36. >::type
  37. >
  38. {
  39. };
  40. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
  41. && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
  42. // collapses a few more types to the same static instance. MSVC7.1
  43. // fails to strip cv-qualification from array types in typeid. For
  44. // some reason we can't use this collapse there or array converters
  45. // will not be found.
  46. template <class T>
  47. struct registered<T&>
  48. : registered<T> {};
  49. # endif
  50. //
  51. // implementations
  52. //
  53. namespace detail
  54. {
  55. inline void
  56. register_shared_ptr0(...)
  57. {
  58. }
  59. template <class T>
  60. inline void
  61. register_shared_ptr0(shared_ptr<T>*)
  62. {
  63. registry::lookup_shared_ptr(type_id<shared_ptr<T> >());
  64. }
  65. template <class T>
  66. inline void
  67. register_shared_ptr1(T const volatile*)
  68. {
  69. detail::register_shared_ptr0((T*)0);
  70. }
  71. template <class T>
  72. inline registration const&
  73. registry_lookup2(T&(*)())
  74. {
  75. detail::register_shared_ptr1((T*)0);
  76. return registry::lookup(type_id<T&>());
  77. }
  78. template <class T>
  79. inline registration const&
  80. registry_lookup1(type<T>)
  81. {
  82. return registry_lookup2((T(*)())0);
  83. }
  84. inline registration const&
  85. registry_lookup1(type<const volatile void>)
  86. {
  87. detail::register_shared_ptr1((void*)0);
  88. return registry::lookup(type_id<void>());
  89. }
  90. template <class T>
  91. registration const& registered_base<T>::converters = detail::registry_lookup1(type<T>());
  92. }
  93. }}} // namespace boost::python::converter
  94. #endif // REGISTERED_DWA2002710_HPP