diff --git a/include/boost/python/to_python_converter.hpp b/include/boost/python/to_python_converter.hpp new file mode 100644 index 00000000..6bea9822 --- /dev/null +++ b/include/boost/python/to_python_converter.hpp @@ -0,0 +1,39 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef TO_PYTHON_CONVERTER_DWA200221_HPP +# define TO_PYTHON_CONVERTER_DWA200221_HPP + +# include +# include +# include + +namespace boost { namespace python { + +template +struct to_python_converter +{ + to_python_converter(); +}; + +// +// implementation +// + +template +to_python_converter::to_python_converter() +{ + typedef converter::as_to_python_value_function< + T, Derived + > normalized; + + converter::registry::insert( + &normalized::convert + , converter::undecorated_type_id()); +} + +}} // namespace boost::python + +#endif // TO_PYTHON_CONVERTER_DWA200221_HPP diff --git a/include/boost/python/to_python_value.hpp b/include/boost/python/to_python_value.hpp new file mode 100644 index 00000000..a222e9a9 --- /dev/null +++ b/include/boost/python/to_python_value.hpp @@ -0,0 +1,58 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef TO_PYTHON_VALUE_DWA200221_HPP +# define TO_PYTHON_VALUE_DWA200221_HPP + +# include +# include +# include +# include +# include + +namespace boost { namespace python { + +template +struct to_python_value +{ + typedef typename add_reference< + typename add_const::type + >::type argument_type; + + static bool convertible(); + PyObject* operator()(argument_type) const; + + private: + // Note that this is a pointer to a function pointer + static converter::to_python_value_function const* fconvert; +}; + + +template +converter::to_python_value_function const* +to_python_value::fconvert + = &converter::registry::to_python_function(converter::undecorated_type_id()); + + +template +bool to_python_value::convertible() +{ + // if this assert fires, our static variable hasn't been set up yet. + assert(fconvert != 0); + return *fconvert != 0; +} + +template +PyObject* to_python_value::operator()(argument_type x) const +{ + // This might be further optimized on platforms which dynamically + // link without specific imports/exports + converter::to_python_value_function f = *fconvert; + return f(&x); +} + +}} // namespace boost::python + +#endif // TO_PYTHON_VALUE_DWA200221_HPP