1 // Copyright David Abrahams 2001.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef CLASS_WRAPPER_DWA20011221_HPP
6 # define CLASS_WRAPPER_DWA20011221_HPP
8 # include <boost/python/to_python_converter.hpp>
9 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
10 # include <boost/python/converter/pytype_function.hpp>
12 # include <boost/ref.hpp>
14 namespace boost { namespace python { namespace objects {
17 // These two classes adapt the static execute function of a class
18 // MakeInstance execute() function returning a new PyObject*
19 // reference. The first one is used for class copy constructors, and
20 // the second one is used to handle smart pointers.
23 template <class Src, class MakeInstance>
24 struct class_cref_wrapper
25 : to_python_converter<Src,class_cref_wrapper<Src,MakeInstance> ,true>
27 static PyObject* convert(Src const& x)
29 return MakeInstance::execute(boost::ref(x));
31 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
32 static PyTypeObject const *get_pytype() { return converter::registered_pytype_direct<Src>::get_pytype(); }
36 template <class Src, class MakeInstance>
37 struct class_value_wrapper
38 : to_python_converter<Src,class_value_wrapper<Src,MakeInstance> ,true>
40 static PyObject* convert(Src x)
42 return MakeInstance::execute(x);
44 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
45 static PyTypeObject const *get_pytype() { return MakeInstance::get_pytype(); }
49 }}} // namespace boost::python::objects
51 #endif // CLASS_WRAPPER_DWA20011221_HPP