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 
17 namespace boost {
18 
19 // You'll see shared_ptr mentioned in this header because we need to
20 // note which types are shared_ptrs in their registrations, to
21 // implement special shared_ptr handling for rvalue conversions.
22 template <class T> class shared_ptr;
23 
24 namespace python { namespace converter {
25 
26 struct registration;
27 
28 namespace detail
29 {
30   template <class T>
31   struct registered_base
32   {
33       static registration const& converters;
34   };
35 }
36 
37 template <class T>
38 struct registered
39   : detail::registered_base<
40         typename add_reference<
41             typename add_cv<T>::type
42         >::type
43     >
44 {
45 };
46 
47 # if !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
48 // collapses a few more types to the same static instance.  MSVC7.1
49 // fails to strip cv-qualification from array types in typeid.  For
50 // some reason we can't use this collapse there or array converters
51 // will not be found.
52 template <class T>
53 struct registered<T&>
54   : registered<T> {};
55 # endif
56 
57 //
58 // implementations
59 //
60 namespace detail
61 {
62   inline void
register_shared_ptr0(...)63   register_shared_ptr0(...)
64   {
65   }
66 
67   template <class T>
68   inline void
register_shared_ptr0(shared_ptr<T> *)69   register_shared_ptr0(shared_ptr<T>*)
70   {
71       registry::lookup_shared_ptr(type_id<shared_ptr<T> >());
72   }
73 
74   template <class T>
75   inline void
register_shared_ptr1(T const volatile *)76   register_shared_ptr1(T const volatile*)
77   {
78       detail::register_shared_ptr0((T*)0);
79   }
80 
81   template <class T>
82   inline registration const&
registry_lookup2(T & (*)())83   registry_lookup2(T&(*)())
84   {
85       detail::register_shared_ptr1((T*)0);
86       return registry::lookup(type_id<T&>());
87   }
88 
89   template <class T>
90   inline registration const&
registry_lookup1(type<T>)91   registry_lookup1(type<T>)
92   {
93       return registry_lookup2((T(*)())0);
94   }
95 
96   inline registration const&
registry_lookup1(type<const volatile void>)97   registry_lookup1(type<const volatile void>)
98   {
99       detail::register_shared_ptr1((void*)0);
100       return registry::lookup(type_id<void>());
101   }
102 
103   template <class T>
104   registration const& registered_base<T>::converters = detail::registry_lookup1(type<T>());
105 
106 }
107 
108 }}} // namespace boost::python::converter
109 
110 #endif // REGISTERED_DWA2002710_HPP
111