From 14917c9791997288a11bcc3b309ca78efe8f89fd Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 2 Feb 2002 14:31:07 +0000 Subject: [PATCH] initial checkin [SVN r12633] --- include/boost/python/to_python_converter.hpp | 39 +++++++++++++ include/boost/python/to_python_value.hpp | 58 ++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 include/boost/python/to_python_converter.hpp create mode 100644 include/boost/python/to_python_value.hpp 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