00001
00002
00003
00004
00005 #ifndef OPTIONAL_070108_HPP
00006 # define OPTIONAL_070108_HPP
00007
00008 # include <boost/python.hpp>
00009 # include <boost/optional.hpp>
00010
00011 template <class T>
00012 struct optional_to_python
00013 {
00014 optional_to_python()
00015 {
00016 boost::python::to_python_converter<
00017 boost::optional<T>, optional_to_python<T>
00018 >();
00019 }
00020
00021 static PyObject* convert(boost::optional<T> const& x)
00022 {
00023 if (!x)
00024 return boost::python::incref(Py_None);
00025
00026 return boost::python::incref(boost::python::object(*x).ptr());
00027 }
00028 };
00029
00030 #endif // OPTIONAL_070108_HPP
00031