From ec8d47ea2fb34941ed18c5f92a31f29708002357 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Fri, 31 Jan 2020 12:03:29 +0100 Subject: [PATCH] Bind vector of Values from C++ to Python At the moment, it is not possible to bind from Python to C++. See TODO --- src/dynamic_graph/convert-dg-to-py.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/dynamic_graph/convert-dg-to-py.cc b/src/dynamic_graph/convert-dg-to-py.cc index d274fe1..7ad8f4c 100644 --- a/src/dynamic_graph/convert-dg-to-py.cc +++ b/src/dynamic_graph/convert-dg-to-py.cc @@ -215,6 +215,12 @@ command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& val } return Value(m4); break; + case (Value::VALUES): + // TODO the vector of values cannot be built since + // - the value type inside the vector are not know + // - inferring the value type from the Python type is not implemented. + throw ExceptionPython(ExceptionPython::VALUE_PARSING, "not implemented: cannot create a vector of values"); + break; default: std::cerr << "Only int, double and string are supported." << std::endl; } @@ -256,6 +262,15 @@ PyObject* matrix4dToPython(const Eigen::Matrix4d& matrix) { return tuple; } +PyObject* valuesToPython(const dynamicgraph::command::Values& vector) { + PyObject* tuple = PyTuple_New(vector.size()); + for (std::size_t index = 0; index < vector.size(); index++) { + PyObject* item = valueToPython(vector[index]); + PyTuple_SET_ITEM(tuple, index, item); + } + return tuple; +} + PyObject* valueToPython(const command::Value& value) { using command::Value; bool boolValue; @@ -298,6 +313,8 @@ PyObject* valueToPython(const command::Value& value) { case (Value::MATRIX4D): matrix4dValue = value.value(); return matrix4dToPython(matrix4dValue); + case (Value::VALUES): + return valuesToPython(value.constValuesValue()); default: return Py_BuildValue(""); } -- GitLab