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 !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ |
---|
48 | && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) |
---|
49 | // collapses a few more types to the same static instance. MSVC7.1 |
---|
50 | // fails to strip cv-qualification from array types in typeid. For |
---|
51 | // some reason we can't use this collapse there or array converters |
---|
52 | // will not be found. |
---|
53 | template <class T> |
---|
54 | struct registered<T&> |
---|
55 | : registered<T> {}; |
---|
56 | # endif |
---|
57 | |
---|
58 | // |
---|
59 | // implementations |
---|
60 | // |
---|
61 | namespace detail |
---|
62 | { |
---|
63 | inline void |
---|
64 | register_shared_ptr0(...) |
---|
65 | { |
---|
66 | } |
---|
67 | |
---|
68 | template <class T> |
---|
69 | inline void |
---|
70 | register_shared_ptr0(shared_ptr<T>*) |
---|
71 | { |
---|
72 | registry::lookup_shared_ptr(type_id<shared_ptr<T> >()); |
---|
73 | } |
---|
74 | |
---|
75 | template <class T> |
---|
76 | inline void |
---|
77 | register_shared_ptr1(T const volatile*) |
---|
78 | { |
---|
79 | detail::register_shared_ptr0((T*)0); |
---|
80 | } |
---|
81 | |
---|
82 | template <class T> |
---|
83 | inline registration const& |
---|
84 | registry_lookup2(T&(*)()) |
---|
85 | { |
---|
86 | detail::register_shared_ptr1((T*)0); |
---|
87 | return registry::lookup(type_id<T&>()); |
---|
88 | } |
---|
89 | |
---|
90 | template <class T> |
---|
91 | inline registration const& |
---|
92 | registry_lookup1(type<T>) |
---|
93 | { |
---|
94 | return registry_lookup2((T(*)())0); |
---|
95 | } |
---|
96 | |
---|
97 | inline registration const& |
---|
98 | registry_lookup1(type<const volatile void>) |
---|
99 | { |
---|
100 | detail::register_shared_ptr1((void*)0); |
---|
101 | return registry::lookup(type_id<void>()); |
---|
102 | } |
---|
103 | |
---|
104 | template <class T> |
---|
105 | registration const& registered_base<T>::converters = detail::registry_lookup1(type<T>()); |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | }}} // namespace boost::python::converter |
---|
110 | |
---|
111 | #endif // REGISTERED_DWA2002710_HPP |
---|