Skip to content

Commit 479d8fc

Browse files
committed
shared_ptr deleter introspection support
miscellaneous cleanups and MPL idiom-izing [SVN r17622]
1 parent 1c346b2 commit 479d8fc

File tree

12 files changed

+168
-189
lines changed

12 files changed

+168
-189
lines changed

include/boost/python/converter/arg_to_python.hpp

Lines changed: 74 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@
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+
2636
namespace boost { namespace python { namespace converter {
2737

2838
template <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))

include/boost/python/converter/from_python.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace boost { namespace python { namespace converter {
1414

1515
struct registration;
16-
struct rvalue_from_python_chain;
16+
1717

1818
BOOST_PYTHON_DECL void* get_lvalue_from_python(
1919
PyObject* source, registration const&);

include/boost/python/converter/object_manager.hpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# include <boost/type_traits/object_traits.hpp>
1313
# include <boost/mpl/if.hpp>
1414
# include <boost/python/detail/indirect_traits.hpp>
15+
# include <boost/mpl/bool_c.hpp>
1516

1617
// Facilities for dealing with types which always manage Python
1718
// objects. Some examples are object, list, str, et. al. Different
@@ -117,16 +118,15 @@ struct object_manager_traits
117118

118119
template <class T>
119120
struct is_object_manager
121+
: mpl::bool_c<object_manager_traits<T>::is_specialized>
120122
{
121-
BOOST_STATIC_CONSTANT(
122-
bool, value = object_manager_traits<T>::is_specialized);
123123
};
124124

125125
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
126126
template <class T>
127127
struct is_reference_to_object_manager
128+
: mpl::false_c
128129
{
129-
BOOST_STATIC_CONSTANT(bool, value = false);
130130
};
131131

132132
template <class T>
@@ -164,8 +164,8 @@ namespace detail
164164
template <class T>
165165
struct is_object_manager_help
166166
{
167-
typedef typename mpl::if_c<
168-
is_object_manager<T>::value
167+
typedef typename mpl::if_<
168+
is_object_manager<T>
169169
, yes_reference_to_object_manager
170170
, no_reference_to_object_manager
171171
>::type type;
@@ -197,8 +197,8 @@ namespace detail
197197

198198
template <class T>
199199
struct is_reference_to_object_manager_nonref
200+
: mpl::false_c
200201
{
201-
BOOST_STATIC_CONSTANT(bool, value = false);
202202
};
203203

204204
template <class T>
@@ -211,19 +211,18 @@ namespace detail
211211
== sizeof(detail::yes_reference_to_object_manager)
212212
)
213213
);
214+
typedef mpl::bool_c<value> type;
214215
};
215216
}
216217

217218
template <class T>
218219
struct is_reference_to_object_manager
219-
{
220-
typedef typename mpl::if_c<
221-
is_reference<T>::value
220+
: mpl::if_<
221+
is_reference<T>
222222
, detail::is_reference_to_object_manager_ref<T>
223223
, detail::is_reference_to_object_manager_nonref<T>
224-
> chooser;
225-
226-
BOOST_STATIC_CONSTANT(bool, value = chooser::type::value);
224+
>::type
225+
{
227226
};
228227
# endif
229228

include/boost/python/converter/shared_ptr_deleter.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
namespace boost { namespace python { namespace converter {
1010

11-
struct shared_ptr_deleter
11+
struct BOOST_PYTHON_DECL shared_ptr_deleter
1212
{
13-
shared_ptr_deleter(handle<> owner)
14-
: owner(owner) {}
13+
shared_ptr_deleter(handle<> owner);
14+
~shared_ptr_deleter();
1515

16-
void operator()(void const*) { owner.reset(); }
16+
void operator()(void const*);
1717

1818
handle<> owner;
1919
};

include/boost/python/detail/copy_ctor_mutates_rhs.hpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,13 @@
33
// copyright notice appears in all copies. This software is provided
44
// "as is" without express or implied warranty, and with no claim as
55
// to its suitability for any purpose.
6-
#include <boost/mpl/bool_c.hpp>
7-
#ifndef BOOST_NO_AUTO_PTR
8-
# include <memory>
9-
#endif
10-
116
#ifndef COPY_CTOR_MUTATES_RHS_DWA2003219_HPP
127
# define COPY_CTOR_MUTATES_RHS_DWA2003219_HPP
138

14-
namespace boost { namespace python { namespace detail {
15-
16-
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_AUTO_PTR)
17-
18-
template <class T>
19-
struct is_auto_ptr
20-
{
21-
typedef char yes;
22-
typedef char (&no)[2];
23-
24-
static
25-
T& f();
26-
27-
template <class U>
28-
static yes test(std::auto_ptr<U>&, int);
29-
30-
template <class U>
31-
static no test(U&, ...);
32-
33-
BOOST_STATIC_CONSTANT(
34-
bool, value = sizeof(test(f(), 0)) == sizeof(yes));
35-
36-
typedef mpl::bool_c<value> type;
37-
38-
};
39-
40-
# else
41-
42-
template <class T>
43-
struct is_auto_ptr : mpl::false_c
44-
{
45-
};
46-
47-
# if !defined(BOOST_NO_AUTO_PTR)
48-
template <class T>
49-
struct is_auto_ptr<std::auto_ptr<T> > : mpl::true_c
50-
{
51-
};
9+
#include <boost/python/detail/is_auto_ptr.hpp>
10+
#include <boost/mpl/bool_c.hpp>
5211

53-
# endif
54-
# endif
12+
namespace boost { namespace python { namespace detail {
5513

5614
template <class T>
5715
struct copy_ctor_mutates_rhs

include/boost/python/detail/mpl_lambda.hpp

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,8 @@
66
#ifndef MPL_LAMBDA_DWA2002122_HPP
77
# define MPL_LAMBDA_DWA2002122_HPP
88

9+
// this header should go away soon
910
# include <boost/mpl/aux_/lambda_support.hpp>
10-
11-
# if 0 // defined(BOOST_MSVC) && BOOST_MSVC <= 1300
12-
// This approach fails, unfortunately
13-
14-
# include <boost/preprocessor/enum_params.hpp>
15-
# include <boost/preprocessor/comma_if.hpp>
16-
17-
# define BOOST_PYTHON_LAMBDA_SUPPORT_FORMAL_ARG(R,class_,i,param) \
18-
BOOST_PP_COMMA_IF(i) class_ param \
19-
/**/
20-
21-
# define BOOST_PYTHON_LAMBDA_SUPPORT_ACTUAL_ARG(R,_,i,param) \
22-
BOOST_PP_COMMA_IF(i) param \
23-
/**/
24-
25-
# define BOOST_PYTHON_MPL_LAMBDA_SUPPORT(i,name,params) \
26-
struct rebind; \
27-
}; \
28-
template < \
29-
BOOST_PP_LIST_FOR_EACH_I_R( \
30-
1 \
31-
, BOOST_PYTHON_LAMBDA_SUPPORT_FORMAL_ARG \
32-
, class \
33-
, BOOST_PP_TUPLE_TO_LIST(i,params) \
34-
) \
35-
> \
36-
struct name < \
37-
BOOST_PP_LIST_FOR_EACH_I_R( \
38-
1 \
39-
, BOOST_PYTHON_LAMBDA_SUPPORT_ACTUAL_ARG \
40-
, class \
41-
, BOOST_PP_TUPLE_TO_LIST(i,params) \
42-
) \
43-
>::rebind \
44-
{ \
45-
BOOST_STATIC_CONSTANT(int, arity = i); \
46-
BOOST_PP_LIST_FOR_EACH_I_R( \
47-
1 \
48-
, BOOST_MPL_AUX_LAMBDA_SUPPORT_ARG_TYPEDEF_FUNC \
49-
, typedef \
50-
, BOOST_PP_TUPLE_TO_LIST(i,params) \
51-
) \
52-
\
53-
template< BOOST_MPL_PP_PARAMS(i,typename U) > struct apply \
54-
: name< BOOST_MPL_PP_PARAMS(i,U) > \
55-
{ \
56-
}; \
57-
/**/
58-
# else
59-
# define BOOST_PYTHON_MPL_LAMBDA_SUPPORT BOOST_MPL_AUX_LAMBDA_SUPPORT
60-
# endif
11+
# define BOOST_PYTHON_MPL_LAMBDA_SUPPORT BOOST_MPL_AUX_LAMBDA_SUPPORT
6112

6213
#endif // MPL_LAMBDA_DWA2002122_HPP

0 commit comments

Comments
 (0)