Skip to content

Commit 8ff5450

Browse files
committed
moved contents of builtin_to_python_converters.hpp to builtin_converters.hpp
[SVN r12705]
1 parent 5d30dda commit 8ff5450

3 files changed

Lines changed: 58 additions & 66 deletions

File tree

include/boost/python/converter/builtin_converters.hpp

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,65 @@
55
// to its suitability for any purpose.
66
#ifndef BUILTIN_CONVERTERS_DWA2002124_HPP
77
# define BUILTIN_CONVERTERS_DWA2002124_HPP
8+
# include <boost/python/detail/wrap_python.hpp>
9+
# include <string>
810

9-
namespace boost { namespace python { namespace converter {
11+
namespace boost { namespace python {
1012

11-
void initialize_builtin_converters();
13+
// Provide specializations of to_python_value
14+
template <class T> struct to_python_value;
1215

13-
}}} // namespace boost::python::converter
16+
namespace detail
17+
{
18+
struct builtin_to_python
19+
{
20+
static bool convertible() { return true; }
21+
};
22+
}
23+
24+
# define BOOST_PYTHON_TO_PYTHON_BY_VALUE(T, expr) \
25+
template <> struct to_python_value<T&> \
26+
: detail::builtin_to_python \
27+
{ \
28+
PyObject* operator()(T const& x) const \
29+
{ \
30+
return (expr); \
31+
} \
32+
}; \
33+
template <> struct to_python_value<T const&> \
34+
: detail::builtin_to_python \
35+
{ \
36+
PyObject* operator()(T const& x) const \
37+
{ \
38+
return (expr); \
39+
} \
40+
};
41+
42+
43+
# define BOOST_PYTHON_TO_INT(T) \
44+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, PyInt_FromLong(x)) \
45+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned T, PyInt_FromLong(x))
46+
47+
BOOST_PYTHON_TO_INT(char)
48+
BOOST_PYTHON_TO_INT(short)
49+
BOOST_PYTHON_TO_INT(int)
50+
BOOST_PYTHON_TO_INT(long)
51+
# undef BOOST_TO_PYTHON_INT
52+
53+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, PyString_FromString(x))
54+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, PyString_FromString(x.c_str()))
55+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, PyFloat_FromDouble(x))
56+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, PyFloat_FromDouble(x))
57+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, PyFloat_FromDouble(x))
58+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(PyObject*, x)
59+
60+
namespace converter
61+
{
62+
63+
void initialize_builtin_converters();
64+
65+
}
66+
67+
}} // namespace boost::python::converter
1468

1569
#endif // BUILTIN_CONVERTERS_DWA2002124_HPP

include/boost/python/converter/builtin_to_python_converters.hpp

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

include/boost/python/to_python_value.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# include <boost/python/converter/type_id.hpp>
1111
# include <boost/python/converter/registry.hpp>
1212
# include <boost/python/converter/to_python_function.hpp>
13-
# include <boost/python/converter/builtin_to_python_converters.hpp>
13+
# include <boost/python/converter/builtin_converters.hpp>
1414

1515
namespace boost { namespace python {
1616

0 commit comments

Comments
 (0)