Skip to content

Commit 093aae1

Browse files
committed
Further rationalized conversion registry
[SVN r14441]
1 parent e431318 commit 093aae1

17 files changed

Lines changed: 104 additions & 217 deletions

include/boost/python/converter/arg_from_python.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# include <boost/python/converter/rvalue_from_python_data.hpp>
1515
# include <boost/mpl/select_type.hpp>
1616
# include <boost/python/converter/registry.hpp>
17-
# include <boost/python/converter/from_python.hpp>
18-
# include <boost/python/converter/pointee_from_python.hpp>
17+
# include <boost/python/converter/registered.hpp>
18+
# include <boost/python/converter/registered_pointee.hpp>
1919
# include <boost/python/detail/void_ptr.hpp>
2020
# include <boost/python/back_reference.hpp>
2121
# include <boost/python/detail/referent_storage.hpp>
@@ -229,7 +229,7 @@ inline pointer_cref_arg_from_python<T>::pointer_cref_arg_from_python(PyObject* p
229229
// a U object.
230230
python::detail::write_void_ptr_reference(
231231
m_result.bytes
232-
, p == Py_None ? p : converter::get_lvalue_from_python(p, pointee_from_python<T>::converters)
232+
, p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee<T>::converters)
233233
, (T(*)())0);
234234
}
235235

@@ -252,7 +252,7 @@ inline T pointer_cref_arg_from_python<T>::operator()(PyObject* p) const
252252
template <class T>
253253
inline pointer_arg_from_python<T>::pointer_arg_from_python(PyObject* p)
254254
: arg_lvalue_from_python_base(
255-
p == Py_None ? p : converter::get_lvalue_from_python(p, pointee_from_python<T>::converters))
255+
p == Py_None ? p : converter::get_lvalue_from_python(p, registered_pointee<T>::converters))
256256
{
257257
}
258258

@@ -266,7 +266,7 @@ inline T pointer_arg_from_python<T>::operator()(PyObject* p) const
266266
//
267267
template <class T>
268268
inline reference_arg_from_python<T>::reference_arg_from_python(PyObject* p)
269-
: arg_lvalue_from_python_base(converter::get_lvalue_from_python(p,from_python<T>::converters))
269+
: arg_lvalue_from_python_base(converter::get_lvalue_from_python(p,registered<T>::converters))
270270
{
271271
}
272272

@@ -281,7 +281,7 @@ inline T reference_arg_from_python<T>::operator()(PyObject*) const
281281
//
282282
template <class T>
283283
inline arg_rvalue_from_python<T>::arg_rvalue_from_python(PyObject* obj)
284-
: m_data(converter::rvalue_from_python_stage1(obj, from_python<T>::converters))
284+
: m_data(converter::rvalue_from_python_stage1(obj, registered<T>::converters))
285285
{
286286
}
287287

include/boost/python/converter/arg_to_python.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# define ARG_TO_PYTHON_DWA200265_HPP
88

99
# include <boost/python/ptr.hpp>
10-
# include <boost/python/converter/to_python_function.hpp>
11-
# include <boost/python/converter/pointee_to_python_function.hpp>
10+
# include <boost/python/converter/registered.hpp>
11+
# include <boost/python/converter/registered_pointee.hpp>
1212
# include <boost/python/converter/arg_to_python_base.hpp>
1313
# include <boost/python/converter/object_manager.hpp>
1414
# include <boost/python/to_python_indirect.hpp>
@@ -180,13 +180,13 @@ namespace detail
180180

181181
template <class T>
182182
inline value_arg_to_python<T>::value_arg_to_python(T const& x)
183-
: arg_to_python_base(&x, to_python_function<T>::value)
183+
: arg_to_python_base(&x, registered<T>::converters.to_python)
184184
{
185185
}
186186

187187
template <class Ptr>
188188
inline pointer_deep_arg_to_python<Ptr>::pointer_deep_arg_to_python(Ptr x)
189-
: arg_to_python_base(x, pointee_to_python_function<Ptr>::value)
189+
: arg_to_python_base(x, registered_pointee<Ptr>::converters.to_python)
190190
{
191191
detail::reject_raw_object_ptr((Ptr)0);
192192
}

include/boost/python/converter/callback_from_python_base.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
namespace boost { namespace python { namespace converter {
1010

1111
struct rvalue_from_python_stage1_data;
12-
struct from_python_registration;
12+
struct registration;
1313

1414
namespace detail
1515
{
1616
BOOST_PYTHON_DECL void* convert_rvalue(PyObject*, rvalue_from_python_stage1_data&, void* storage);
17-
BOOST_PYTHON_DECL void* callback_convert_reference(PyObject*, from_python_registration const&);
18-
BOOST_PYTHON_DECL void* callback_convert_pointer(PyObject*, from_python_registration const&);
17+
BOOST_PYTHON_DECL void* callback_convert_reference(PyObject*, registration const&);
18+
BOOST_PYTHON_DECL void* callback_convert_pointer(PyObject*, registration const&);
1919
BOOST_PYTHON_DECL void absorb_result(PyObject*);
2020
}
2121

include/boost/python/converter/find_from_python.hpp

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

1313
namespace boost { namespace python { namespace converter {
1414

15-
struct from_python_registration;
15+
struct registration;
1616
struct rvalue_from_python_chain;
1717

1818
BOOST_PYTHON_DECL void* get_lvalue_from_python(
19-
PyObject* source, from_python_registration const&);
19+
PyObject* source, registration const&);
2020

2121
BOOST_PYTHON_DECL rvalue_from_python_stage1_data rvalue_from_python_stage1(
22-
PyObject* source, from_python_registration const&);
22+
PyObject* source, registration const&);
2323

2424
BOOST_PYTHON_DECL rvalue_from_python_chain const* implicit_conversion_chain(
25-
PyObject* source, from_python_registration const&);
25+
PyObject* source, registration const&);
2626

2727
}}} // namespace boost::python::converter
2828

include/boost/python/converter/implicit.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# define IMPLICIT_DWA2002326_HPP
88
# include <boost/python/converter/rvalue_from_python_data.hpp>
99
# include <boost/python/converter/registrations.hpp>
10+
# include <boost/python/converter/registered.hpp>
1011

1112
namespace boost { namespace python { namespace converter {
1213

@@ -15,27 +16,27 @@ struct implicit
1516
{
1617
static void* convertible(PyObject* obj)
1718
{
18-
// Find a converter registration which can produce a Source
19-
// instance from obj. The user has told us that Source can be
20-
// converted to Target, and instantiating construct() below,
21-
// ensures that at compile-time.
19+
// Find a converter chain which can produce a Source instance
20+
// from obj. The user has told us that Source can be converted
21+
// to Target, and instantiating construct() below, ensures
22+
// that at compile-time.
2223
return const_cast<rvalue_from_python_chain*>(
23-
converter::implicit_conversion_chain(obj, from_python<Source>::converters));
24+
converter::implicit_conversion_chain(obj, registered<Source>::converters));
2425
}
2526

2627
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
2728
{
28-
// This is the registration we got from the convertible step
29-
rvalue_from_python_chain const* registration
29+
// This is the chain we got from the convertible step
30+
rvalue_from_python_chain const* chain
3031
= static_cast<rvalue_from_python_chain*>(data->convertible);
3132

3233
// Call the convertible function again
33-
rvalue_from_python_data<Source> intermediate_data(registration->convertible(obj));
34+
rvalue_from_python_data<Source> intermediate_data(chain->convertible(obj));
3435

3536
// Use the result to construct the source type if the first
3637
// converter was an rvalue converter.
37-
if (registration->construct != 0)
38-
registration->construct(obj, &intermediate_data.stage1);
38+
if (chain->construct != 0)
39+
chain->construct(obj, &intermediate_data.stage1);
3940

4041
void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
4142
# if !defined(BOOST_MSVC) || _MSC_FULL_VER != 13012108 // vc7.01 alpha workaround

include/boost/python/converter/pointee_to_python_function.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

include/boost/python/converter/from_python.hpp renamed to include/boost/python/converter/registered.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@
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-
#ifndef FROM_PYTHON_DWA2002710_HPP
7-
# define FROM_PYTHON_DWA2002710_HPP
6+
#ifndef REGISTERED_DWA2002710_HPP
7+
# define REGISTERED_DWA2002710_HPP
88
# include <boost/python/type_id.hpp>
99
# include <boost/python/converter/registry.hpp>
10+
# include <boost/python/converter/registrations.hpp>
1011
# include <boost/type_traits/transform_traits.hpp>
1112
# include <boost/type_traits/cv_traits.hpp>
1213

1314
namespace boost { namespace python { namespace converter {
1415

15-
struct from_python_registration;
16+
struct registration;
1617

1718
namespace detail
1819
{
1920
template <class T>
20-
struct from_python_base
21+
struct registered_base
2122
{
22-
static from_python_registration const& converters;
23+
static registration const& converters;
2324
};
2425
}
2526

2627
template <class T>
27-
struct from_python
28-
: detail::from_python_base<
28+
struct registered
29+
: detail::registered_base<
2930
typename add_reference<
3031
typename add_cv<T>::type
3132
>::type
@@ -36,7 +37,7 @@ struct from_python
3637
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
3738
// collapses a few more types to the same static instance
3839
template <class T>
39-
struct from_python<T&> : from_python<T> {};
40+
struct registered<T&> : registered<T> {};
4041
# endif
4142

4243
//
@@ -45,9 +46,9 @@ struct from_python<T&> : from_python<T> {};
4546
namespace detail
4647
{
4748
template <class T>
48-
from_python_registration const& from_python_base<T>::converters
49-
= registry::from_python_converters(type_id<T>());
49+
registration const& registered_base<T>::converters
50+
= registry::lookup(type_id<T>());
5051
}
5152
}}} // namespace boost::python::converter
5253

53-
#endif // FROM_PYTHON_DWA2002710_HPP
54+
#endif // REGISTERED_DWA2002710_HPP

include/boost/python/converter/pointee_from_python.hpp renamed to include/boost/python/converter/registered_pointee.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
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-
#ifndef POINTEE_FROM_PYTHON_DWA2002710_HPP
7-
# define POINTEE_FROM_PYTHON_DWA2002710_HPP
8-
# include <boost/python/converter/from_python.hpp>
6+
#ifndef REGISTERED_POINTEE_DWA2002710_HPP
7+
# define REGISTERED_POINTEE_DWA2002710_HPP
8+
# include <boost/python/converter/registered.hpp>
99
# include <boost/python/converter/pointer_type_id.hpp>
1010
# include <boost/python/converter/registry.hpp>
1111
# include <boost/type_traits/transform_traits.hpp>
1212
# include <boost/type_traits/cv_traits.hpp>
1313

1414
namespace boost { namespace python { namespace converter {
1515

16-
struct from_python_registration;
16+
struct registration;
1717

1818
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1919
template <class T>
20-
struct pointee_from_python
21-
: from_python<
20+
struct registered_pointee
21+
: registered<
2222
typename remove_pointer<
2323
typename remove_cv<
2424
typename remove_reference<T>::type
@@ -31,15 +31,15 @@ struct pointee_from_python
3131
namespace detail
3232
{
3333
template <class T>
34-
struct pointee_from_python_base
34+
struct registered_pointee_base
3535
{
36-
static from_python_registration const& converters;
36+
static registration const& converters;
3737
};
3838
}
3939

4040
template <class T>
41-
struct pointee_from_python
42-
: detail::pointee_from_python_base<
41+
struct registered_pointee
42+
: detail::registered_pointee_base<
4343
typename add_reference<
4444
typename add_cv<T>::type
4545
>::type
@@ -53,11 +53,11 @@ struct pointee_from_python
5353
namespace detail
5454
{
5555
template <class T>
56-
from_python_registration const& pointee_from_python_base<T>::converters
57-
= registry::from_python_converters(pointer_type_id<T>());
56+
registration const& registered_pointee_base<T>::converters
57+
= registry::lookup(pointer_type_id<T>());
5858
}
5959

6060
# endif
6161
}}} // namespace boost::python::converter
6262

63-
#endif // POINTEE_FROM_PYTHON_DWA2002710_HPP
63+
#endif // REGISTERED_POINTEE_DWA2002710_HPP

include/boost/python/converter/registrations.hpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#ifndef REGISTRATIONS_DWA2002223_HPP
77
# define REGISTRATIONS_DWA2002223_HPP
88

9+
# include <boost/python/detail/wrap_python.hpp>
910
# include <boost/python/converter/convertible_function.hpp>
1011
# include <boost/python/converter/constructor_function.hpp>
12+
# include <boost/python/converter/to_python_function_type.hpp>
1113
# include <boost/python/type_id.hpp>
1214

1315
namespace boost { namespace python { namespace converter {
@@ -25,24 +27,41 @@ struct rvalue_from_python_chain
2527
rvalue_from_python_chain* next;
2628
};
2729

28-
struct from_python_registration
30+
struct registration
2931
{
30-
explicit from_python_registration(type_info);
32+
explicit registration(type_info);
3133

3234
const python::type_info target_type;
35+
36+
// The chain of eligible from_python converters when an lvalue is required
3337
lvalue_from_python_chain* lvalue_chain;
38+
39+
// The chain of eligible from_python converters when an rvalue is acceptable
3440
rvalue_from_python_chain* rvalue_chain;
41+
42+
// The unique to_python converter for the associated C++ type.
43+
to_python_function_t to_python;
44+
45+
// The class object associated with this type
46+
PyTypeObject* class_object;
3547
};
3648

3749
//
3850
// implementations
3951
//
40-
inline from_python_registration::from_python_registration(type_info target_type)
52+
inline registration::registration(type_info target_type)
4153
: target_type(target_type)
4254
, lvalue_chain(0)
4355
, rvalue_chain(0)
56+
, to_python(0)
57+
, class_object(0)
4458
{}
4559

60+
inline bool operator<(registration const& lhs, registration const& rhs)
61+
{
62+
return lhs.target_type < rhs.target_type;
63+
}
64+
4665
}}} // namespace boost::python::converter
4766

4867
#endif // REGISTRATIONS_DWA2002223_HPP

0 commit comments

Comments
 (0)