| 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 |
|---|
| 7 | |
|---|
| 8 | # include <boost/python/to_python_converter.hpp> |
|---|
| 9 | # include <boost/ref.hpp> |
|---|
| 10 | |
|---|
| 11 | namespace boost { namespace python { namespace objects { |
|---|
| 12 | |
|---|
| 13 | // |
|---|
| 14 | // These two classes adapt the static execute function of a class |
|---|
| 15 | // MakeInstance execute() function returning a new PyObject* |
|---|
| 16 | // reference. The first one is used for class copy constructors, and |
|---|
| 17 | // the second one is used to handle smart pointers. |
|---|
| 18 | // |
|---|
| 19 | |
|---|
| 20 | template <class Src, class MakeInstance> |
|---|
| 21 | struct class_cref_wrapper |
|---|
| 22 | : to_python_converter<Src,class_cref_wrapper<Src,MakeInstance> > |
|---|
| 23 | { |
|---|
| 24 | static PyObject* convert(Src const& x) |
|---|
| 25 | { |
|---|
| 26 | return MakeInstance::execute(boost::ref(x)); |
|---|
| 27 | } |
|---|
| 28 | }; |
|---|
| 29 | |
|---|
| 30 | template <class Src, class MakeInstance> |
|---|
| 31 | struct class_value_wrapper |
|---|
| 32 | : to_python_converter<Src,class_value_wrapper<Src,MakeInstance> > |
|---|
| 33 | { |
|---|
| 34 | static PyObject* convert(Src x) |
|---|
| 35 | { |
|---|
| 36 | return MakeInstance::execute(x); |
|---|
| 37 | } |
|---|
| 38 | }; |
|---|
| 39 | |
|---|
| 40 | }}} // namespace boost::python::objects |
|---|
| 41 | |
|---|
| 42 | #endif // CLASS_WRAPPER_DWA20011221_HPP |
|---|