6 #ifndef KNOWROB_PY_CONVERTER_OPTIONAL_H
7 #define KNOWROB_PY_CONVERTER_OPTIONAL_H
9 #include <boost/python.hpp>
15 struct python_optional :
private boost::noncopyable {
16 struct conversion :
public boost::python::converter::expected_from_python_type<T> {
17 static PyObject *
convert(std::optional<T>
const &value) {
19 return incref((value ?
object(*value) :
object()).ptr());
25 return obj == Py_None || extract<T>(obj).check() ? obj : NULL;
30 boost::python::converter::rvalue_from_python_stage1_data *data
35 converter::rvalue_from_python_storage<std::optional<T>
> *
36 >(data)->storage.bytes;
38 new(storage) std::optional<T>();
40 new(storage) std::optional<T>(extract<T>(obj));
42 data->convertible = storage;
47 if (!extract<std::optional<T> >(
object()).check()) {
48 to_python_converter<std::optional<T>,
conversion,
true>();
49 converter::registry::push_back(
52 type_id<std::optional<T> >(),
53 &conversion::get_pytype
static PyObject * convert(std::optional< T > const &value)
static void * convertible(PyObject *obj)
static void constructor(PyObject *obj, boost::python::converter::rvalue_from_python_stage1_data *data)