Skip to content

Commit 14917c9

Browse files
committed
initial checkin
[SVN r12633]
1 parent 25c5616 commit 14917c9

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef TO_PYTHON_CONVERTER_DWA200221_HPP
7+
# define TO_PYTHON_CONVERTER_DWA200221_HPP
8+
9+
# include <boost/python/converter/registry.hpp>
10+
# include <boost/python/converter/to_python_function.hpp>
11+
# include <boost/python/converter/type_id.hpp>
12+
13+
namespace boost { namespace python {
14+
15+
template <class T, class Derived>
16+
struct to_python_converter
17+
{
18+
to_python_converter();
19+
};
20+
21+
//
22+
// implementation
23+
//
24+
25+
template <class T, class Derived>
26+
to_python_converter<T,Derived>::to_python_converter()
27+
{
28+
typedef converter::as_to_python_value_function<
29+
T, Derived
30+
> normalized;
31+
32+
converter::registry::insert(
33+
&normalized::convert
34+
, converter::undecorated_type_id<T>());
35+
}
36+
37+
}} // namespace boost::python
38+
39+
#endif // TO_PYTHON_CONVERTER_DWA200221_HPP
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef TO_PYTHON_VALUE_DWA200221_HPP
7+
# define TO_PYTHON_VALUE_DWA200221_HPP
8+
9+
# include <boost/type_traits/transform_traits.hpp>
10+
# include <boost/python/converter/type_id.hpp>
11+
# include <boost/python/converter/registry.hpp>
12+
# include <boost/python/converter/to_python_function.hpp>
13+
# include <boost/python/converter/builtin_to_python_converters.hpp>
14+
15+
namespace boost { namespace python {
16+
17+
template <class T>
18+
struct to_python_value
19+
{
20+
typedef typename add_reference<
21+
typename add_const<T>::type
22+
>::type argument_type;
23+
24+
static bool convertible();
25+
PyObject* operator()(argument_type) const;
26+
27+
private:
28+
// Note that this is a pointer to a function pointer
29+
static converter::to_python_value_function const* fconvert;
30+
};
31+
32+
33+
template <class T>
34+
converter::to_python_value_function const*
35+
to_python_value<T>::fconvert
36+
= &converter::registry::to_python_function(converter::undecorated_type_id<T>());
37+
38+
39+
template <class T>
40+
bool to_python_value<T>::convertible()
41+
{
42+
// if this assert fires, our static variable hasn't been set up yet.
43+
assert(fconvert != 0);
44+
return *fconvert != 0;
45+
}
46+
47+
template <class T>
48+
PyObject* to_python_value<T>::operator()(argument_type x) const
49+
{
50+
// This might be further optimized on platforms which dynamically
51+
// link without specific imports/exports
52+
converter::to_python_value_function f = *fconvert;
53+
return f(&x);
54+
}
55+
56+
}} // namespace boost::python
57+
58+
#endif // TO_PYTHON_VALUE_DWA200221_HPP

0 commit comments

Comments
 (0)