6 #ifndef KNOWROB_PY_CONVERTER_STRING_VIEW_H
7 #define KNOWROB_PY_CONVERTER_STRING_VIEW_H
11 struct string_view_to_python_str {
12 static PyObject *
convert(std::string_view s) {
13 return PyUnicode_FromStringAndSize(s.data(), s.size());
18 struct python_str_to_string_view {
20 if (!PyUnicode_Check(obj_ptr))
return 0;
24 static void construct(PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data) {
25 const char *value = PyUnicode_AsUTF8(obj_ptr);
26 if (value ==
nullptr) boost::python::throw_error_already_set();
27 void *storage = ((boost::python::converter::rvalue_from_python_storage<std::string_view> *) data)->storage.bytes;
28 new(storage) std::string_view(value);
29 data->convertible = storage;
34 boost::python::to_python_converter<std::string_view, string_view_to_python_str>();
35 boost::python::converter::registry::push_back(
38 boost::python::type_id<std::string_view>()
void register_string_view_converter()
static void * convertible(PyObject *obj_ptr)
static void construct(PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data)
static PyObject * convert(std::string_view s)