diff --git a/include/boost/python/lvalue_from_python.hpp b/include/boost/python/lvalue_from_python.hpp new file mode 100644 index 00000000..c5d09ff5 --- /dev/null +++ b/include/boost/python/lvalue_from_python.hpp @@ -0,0 +1,96 @@ +// 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 LVALUE_FROM_PYTHON_DWA2002130_HPP +# define LVALUE_FROM_PYTHON_DWA2002130_HPP + +# include +# include + +namespace boost { namespace python { + +// Utility which produces a member extractor function on platforms +// other than VC6. +template +struct get_member +{ + static Member& execute(Class& c) + { + return c.*mp; + } +}; + +namespace detail +{ + template + struct extract_identity + { + static Class& execute(Class& c) + { + return c; + } + }; +} + +template < + PyTypeObject const* python_type + , class Value + , class PythonObject = Value + , class Extract = detail::extract_identity + > +class lvalue_from_python +{ + typedef type_from_python convertible_t; + public: + + lvalue_from_python() + : m_mutable_converter( + &convertible_t::convertible, convert_mutable) + + , m_const_converter( + &convertible_t::convertible, convert_const) + + , m_mutable_pointer_converter( + &convertible_t::convertible, convert_mutable_pointer) + + , m_const_pointer_converter( + &convertible_t::convertible, convert_const_pointer) + {} + + private: + static Value& convert_mutable(PyObject* op, converter::from_python_data&) + { + return Extract::execute(*(PythonObject*)op); + } + + static Value const& convert_const(PyObject* op, converter::from_python_data&) + { + return Extract::execute(*(PythonObject*)op); + } + + static Value* convert_mutable_pointer(PyObject* op, converter::from_python_data&) + { + return &Extract::execute(*(PythonObject*)op); + } + + static Value const* convert_const_pointer(PyObject* op, converter::from_python_data&) + { + return &Extract::execute(*(PythonObject*)op); + } + + typedef converter::from_python_converter mutable_converter; + typedef converter::from_python_converter const_converter; + typedef converter::from_python_converter mutable_pointer_converter; + typedef converter::from_python_converter const_pointer_converter; + + mutable_converter m_mutable_converter; + const_converter m_const_converter; + mutable_pointer_converter m_mutable_pointer_converter; + const_pointer_converter m_const_pointer_converter; +}; + +}} // namespace boost::python + +#endif // LVALUE_FROM_PYTHON_DWA2002130_HPP