77# define ARG_TO_PYTHON_DWA200265_HPP
88
99# include < boost/python/ptr.hpp>
10+ # include < boost/python/tag.hpp>
11+ # include < boost/python/to_python_indirect.hpp>
12+
1013# include < boost/python/converter/registered.hpp>
1114# include < boost/python/converter/registered_pointee.hpp>
1215# include < boost/python/converter/arg_to_python_base.hpp>
13- # include < boost/python/to_python_indirect.hpp>
14- # include < boost/type_traits/cv_traits.hpp>
15- # include < boost/type_traits/composite_traits.hpp>
16- # include < boost/type_traits/function_traits.hpp>
17- # include < boost/python/detail/indirect_traits.hpp>
18- # include < boost/python/detail/convertible.hpp>
19- # include < boost/python/detail/string_literal.hpp>
20- # include < boost/python/base_type_traits.hpp>
16+ # include < boost/python/converter/shared_ptr_to_python.hpp>
2117// Bring in specializations
2218# include < boost/python/converter/builtin_converters.hpp>
23- # include < boost/python/tag.hpp >
19+
2420# include < boost/python/object/function_handle.hpp>
2521
22+ # include < boost/python/base_type_traits.hpp>
23+
24+ # include < boost/python/detail/indirect_traits.hpp>
25+ # include < boost/python/detail/convertible.hpp>
26+ # include < boost/python/detail/string_literal.hpp>
27+ # include < boost/python/detail/value_is_shared_ptr.hpp>
28+
29+ # include < boost/type_traits/cv_traits.hpp>
30+ # include < boost/type_traits/composite_traits.hpp>
31+ # include < boost/type_traits/function_traits.hpp>
32+
33+
34+ # include < boost/mpl/logical/or.hpp>
35+
2636namespace boost { namespace python { namespace converter {
2737
2838template <class T > struct is_object_manager ;
@@ -43,6 +53,14 @@ namespace detail
4353 static PyObject* get_object (T& x);
4454 };
4555
56+ template <class T >
57+ struct shared_ptr_arg_to_python : handle<>
58+ {
59+ shared_ptr_arg_to_python (T const & x);
60+ private:
61+ static PyObject* get_object (T& x);
62+ };
63+
4664 template <class T >
4765 struct value_arg_to_python : arg_to_python_base
4866 {
@@ -84,54 +102,51 @@ namespace detail
84102 template <class T >
85103 struct select_arg_to_python
86104 {
87- // Special handling for char const[N]; interpret them as char
88- // const* for the sake of conversion
89- BOOST_STATIC_CONSTANT (
90- bool , is_string = python::detail::is_string_literal<T const >::value);
91-
92- BOOST_STATIC_CONSTANT (
93- bool , function = is_function<T>::value | python::detail::is_pointer_to_function<T>::value | is_member_function_pointer<T>::value);
94-
95- BOOST_STATIC_CONSTANT (
96- bool , manager = is_object_manager<T>::value);
97-
98- BOOST_STATIC_CONSTANT (
99- bool , ptr = is_pointer<T>::value);
105+ typedef typename unwrap_reference<T>::type unwrapped_referent;
106+ typedef typename unwrap_pointer<T>::type unwrapped_ptr;
107+
108+ typedef typename mpl::if_<
109+ // Special handling for char const[N]; interpret them as char
110+ // const* for the sake of conversion
111+ python::detail::is_string_literal<T const >
112+ , arg_to_python<char const *>
113+
114+ , typename mpl::if_<
115+ python::detail::value_is_shared_ptr<T>
116+ , shared_ptr_arg_to_python<T>
100117
101- BOOST_STATIC_CONSTANT (
102- bool , ref_wrapper = is_reference_wrapper<T>::value);
118+ , typename mpl::if_<
119+ mpl::logical_or<
120+ is_function<T>
121+ , python::detail::is_pointer_to_function<T>
122+ , is_member_function_pointer<T>
123+ >
124+ , function_arg_to_python<T>
103125
104- BOOST_STATIC_CONSTANT (
105- bool , ptr_wrapper = is_pointer_wrapper<T>::value);
126+ , typename mpl::if_<
127+ is_object_manager<T>
128+ , object_manager_arg_to_python<T>
106129
107- typedef typename unwrap_reference<T>::type unwrapped_referent;
108- typedef typename unwrap_pointer<T>::type unwrapped_ptr;
130+ , typename mpl::if_<
131+ is_pointer<T>
132+ , pointer_deep_arg_to_python<T>
133+
134+ , typename mpl::if_<
135+ is_pointer_wrapper<T>
136+ , pointer_shallow_arg_to_python<unwrapped_ptr>
109137
110- typedef typename mpl::if_c<
111- is_string
112- , arg_to_python<char const *>
113- , typename mpl::if_c<
114- function
115- , function_arg_to_python<T>
116- , typename mpl::if_c<
117- manager
118- , object_manager_arg_to_python<T>
119- , typename mpl::if_c<
120- ptr
121- , pointer_deep_arg_to_python<T>
122- , typename mpl::if_c<
123- ptr_wrapper
124- , pointer_shallow_arg_to_python<unwrapped_ptr>
125- , typename mpl::if_c<
126- ref_wrapper
127- , reference_arg_to_python<unwrapped_referent>
128- , value_arg_to_python<T>
129- >::type
130- >::type
131- >::type
132- >::type
133- >::type
134- >::type
138+ , typename mpl::if_<
139+ is_reference_wrapper<T>
140+ , reference_arg_to_python<unwrapped_referent>
141+ , value_arg_to_python<T>
142+ >::type
143+ >::type
144+ >::type
145+ >::type
146+ >::type
147+ >::type
148+ >::type
149+
135150 type;
136151 };
137152}
@@ -216,6 +231,12 @@ namespace detail
216231 {
217232 }
218233
234+ template <class T >
235+ inline shared_ptr_arg_to_python<T>::shared_ptr_arg_to_python(T const & x)
236+ : handle<>(shared_ptr_to_python(x))
237+ {
238+ }
239+
219240 template <class Ptr >
220241 inline pointer_shallow_arg_to_python<Ptr>::pointer_shallow_arg_to_python(Ptr x)
221242 : handle<>(pointer_shallow_arg_to_python<Ptr>::get_object(x))
0 commit comments