Skip to content
Snippets Groups Projects
Commit ec8d47ea authored by Joseph Mirabel's avatar Joseph Mirabel Committed by olivier stasse
Browse files

Bind vector of Values from C++ to Python

At the moment, it is not possible to bind from Python to C++. See TODO
parent d48a3221
No related branches found
No related tags found
No related merge requests found
...@@ -215,6 +215,12 @@ command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& val ...@@ -215,6 +215,12 @@ command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& val
} }
return Value(m4); return Value(m4);
break; 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: default:
std::cerr << "Only int, double and string are supported." << std::endl; std::cerr << "Only int, double and string are supported." << std::endl;
} }
...@@ -256,6 +262,15 @@ PyObject* matrix4dToPython(const Eigen::Matrix4d& matrix) { ...@@ -256,6 +262,15 @@ PyObject* matrix4dToPython(const Eigen::Matrix4d& matrix) {
return tuple; 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) { PyObject* valueToPython(const command::Value& value) {
using command::Value; using command::Value;
bool boolValue; bool boolValue;
...@@ -298,6 +313,8 @@ PyObject* valueToPython(const command::Value& value) { ...@@ -298,6 +313,8 @@ PyObject* valueToPython(const command::Value& value) {
case (Value::MATRIX4D): case (Value::MATRIX4D):
matrix4dValue = value.value(); matrix4dValue = value.value();
return matrix4dToPython(matrix4dValue); return matrix4dToPython(matrix4dValue);
case (Value::VALUES):
return valuesToPython(value.constValuesValue());
default: default:
return Py_BuildValue(""); return Py_BuildValue("");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment