7 #ifndef __eigenpy_optional_hpp__
8 #define __eigenpy_optional_hpp__
14 #include <boost/optional.hpp>
15 #ifdef EIGENPY_WITH_CXX17_SUPPORT
19 #ifndef EIGENPY_DEFAULT_OPTIONAL
20 #define EIGENPY_DEFAULT_OPTIONAL boost::optional
28 struct expected_pytype_for_arg<
boost::optional<T> >
29 : expected_pytype_for_arg<T> {};
31 #ifdef EIGENPY_WITH_CXX17_SUPPORT
33 struct expected_pytype_for_arg<std::optional<T> > : expected_pytype_for_arg<T> {
47 template <
template <
typename>
class OptionalTpl>
52 typedef boost::none_t
type;
56 #ifdef EIGENPY_WITH_CXX17_SUPPORT
58 struct nullopt_helper<std::optional> {
59 typedef std::nullopt_t type;
60 static type
value() {
return std::nullopt; }
64 template <
typename NoneType>
66 static PyObject *
convert(
const NoneType &) { Py_RETURN_NONE; }
69 if (!check_registration<NoneType>()) {
70 bp::to_python_converter<NoneType, NoneToPython, false>();
78 static PyObject *
convert(
const OptionalTpl<T> &obj) {
80 return bp::incref(bp::object(*obj).ptr());
82 return bp::incref(bp::object().ptr());
87 return bp::converter::registered_pytype<T>::get_pytype();
103 bp::converter::rvalue_from_python_stage1_data *memory);
108 template <
typename T,
template <
typename>
class OptionalTpl>
110 if (obj_ptr == Py_None) {
113 bp::extract<T> bp_obj(obj_ptr);
120 template <
typename T,
template <
typename>
class OptionalTpl>
122 PyObject *obj_ptr, bp::converter::rvalue_from_python_stage1_data *memory) {
124 using rvalue_storage_t =
125 bp::converter::rvalue_from_python_storage<OptionalTpl<T> >;
127 reinterpret_cast<rvalue_storage_t *
>(
reinterpret_cast<void *
>(memory))
130 if (obj_ptr == Py_None) {
133 const T
value = bp::extract<T>(obj_ptr);
134 new (storage) OptionalTpl<T>(
value);
137 memory->convertible = storage;
140 template <
typename T,
template <
typename>
class OptionalTpl>
142 bp::converter::registry::push_back(
143 &convertible, &construct, bp::type_id<OptionalTpl<T> >(),
144 bp::converter::expected_pytype_for_arg<OptionalTpl<T> >::get_pytype);
151 template <
typename T,
162 #endif // __eigenpy_optional_hpp__